Test
This commit is contained in:
parent
1e899d7e62
commit
5be14364fd
@ -22,19 +22,18 @@ public class Generator1 implements Runnable // Callable
|
|||||||
{
|
{
|
||||||
private static Logger lg = OhmLogger.getLogger(); //Logger sollten immer static sein da sie für alle instanzen loggs ausführen
|
private static Logger lg = OhmLogger.getLogger(); //Logger sollten immer static sein da sie für alle instanzen loggs ausführen
|
||||||
|
|
||||||
private Integer[] wert;
|
private int wert;
|
||||||
private volatile boolean laufend;
|
private volatile boolean laufend;
|
||||||
private ExecutorService eService;
|
private ExecutorService eService;
|
||||||
|
|
||||||
private final Object LOCK;
|
private final Object LOCK;
|
||||||
|
|
||||||
private SubmissionPublisher<Integer[]> wertPublisher;
|
private SubmissionPublisher<Integer> wertPublisher;
|
||||||
|
|
||||||
public Generator1(Zahlengenerator hauptgenerator)
|
public Generator1(Zahlengenerator hauptgenerator)
|
||||||
{
|
{
|
||||||
wert = new Integer[2];
|
wert = 0;
|
||||||
wert[0] = -1;
|
|
||||||
wert[1] = 1;
|
|
||||||
|
|
||||||
laufend = false;
|
laufend = false;
|
||||||
eService = Executors.newSingleThreadExecutor();
|
eService = Executors.newSingleThreadExecutor();
|
||||||
@ -43,7 +42,7 @@ public class Generator1 implements Runnable // Callable
|
|||||||
LOCK = new Object();
|
LOCK = new Object();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWertSubscription(Subscriber<Integer[]> subscriber)
|
public void addWertSubscription(Subscriber<Integer> subscriber)
|
||||||
{
|
{
|
||||||
wertPublisher.subscribe(subscriber);
|
wertPublisher.subscribe(subscriber);
|
||||||
}
|
}
|
||||||
@ -74,6 +73,7 @@ public class Generator1 implements Runnable // Callable
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
lg.info("Generator1 run");
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
while (!laufend)
|
while (!laufend)
|
||||||
@ -107,7 +107,7 @@ public class Generator1 implements Runnable // Callable
|
|||||||
|
|
||||||
private synchronized void berechneWert()
|
private synchronized void berechneWert()
|
||||||
{
|
{
|
||||||
wert[0] = (int) (1 + 6*Math.random());
|
wert = (int) (1 + 6*Math.random());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
||||||
*/
|
|
||||||
|
|
||||||
package bandit.Model.Generator;
|
|
||||||
|
|
||||||
import bandit.Model.Zahlengenerator;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.Flow.Subscriber;
|
|
||||||
import java.util.concurrent.SubmissionPublisher;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import bandit.util.OhmLogger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author le
|
|
||||||
*/
|
|
||||||
public class Generator2 implements Runnable // Callable
|
|
||||||
{
|
|
||||||
private static Logger lg = OhmLogger.getLogger(); //Logger sollten immer static sein da sie für alle instanzen loggs ausführen
|
|
||||||
|
|
||||||
private Integer[] wert;
|
|
||||||
private volatile boolean laufend;
|
|
||||||
private ExecutorService eService;
|
|
||||||
|
|
||||||
private final Object LOCK;
|
|
||||||
|
|
||||||
private SubmissionPublisher<Integer[]> wertPublisher;
|
|
||||||
|
|
||||||
public Generator2(Zahlengenerator hauptgenerator)
|
|
||||||
{
|
|
||||||
wert = new Integer[2];
|
|
||||||
wert[0] = -1;
|
|
||||||
wert[1] = 2;
|
|
||||||
|
|
||||||
laufend = false;
|
|
||||||
eService = Executors.newSingleThreadExecutor();
|
|
||||||
wertPublisher = new SubmissionPublisher<>();
|
|
||||||
this.addWertSubscription(hauptgenerator);
|
|
||||||
LOCK = new Object();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addWertSubscription(Subscriber<Integer[]> subscriber)
|
|
||||||
{
|
|
||||||
wertPublisher.subscribe(subscriber);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start()
|
|
||||||
{
|
|
||||||
laufend = true;
|
|
||||||
synchronized (LOCK)
|
|
||||||
{
|
|
||||||
LOCK.notifyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (eService.isShutdown())
|
|
||||||
{
|
|
||||||
eService = Executors.newSingleThreadExecutor();
|
|
||||||
}
|
|
||||||
eService.execute(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop()
|
|
||||||
{
|
|
||||||
synchronized(LOCK){
|
|
||||||
laufend = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
while (!laufend)
|
|
||||||
{
|
|
||||||
synchronized (LOCK)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
lg.info("WAIT_Gen2");
|
|
||||||
LOCK.wait();
|
|
||||||
}
|
|
||||||
catch (InterruptedException ex)
|
|
||||||
{
|
|
||||||
lg.warning(ex.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Thread.sleep(100);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
System.err.println(ex);
|
|
||||||
}
|
|
||||||
this.berechneWert();
|
|
||||||
wertPublisher.submit(wert);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void berechneWert()
|
|
||||||
{
|
|
||||||
wert[0] = (int) (1 + 6*Math.random());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
||||||
*/
|
|
||||||
|
|
||||||
package bandit.Model.Generator;
|
|
||||||
|
|
||||||
import bandit.Model.Zahlengenerator;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.Flow.Subscriber;
|
|
||||||
import java.util.concurrent.SubmissionPublisher;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import bandit.util.OhmLogger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author le
|
|
||||||
*/
|
|
||||||
public class Generator3 implements Runnable // Callable
|
|
||||||
{
|
|
||||||
private static Logger lg = OhmLogger.getLogger(); //Logger sollten immer static sein da sie für alle instanzen loggs ausführen
|
|
||||||
|
|
||||||
private Integer[] wert;
|
|
||||||
private volatile boolean laufend;
|
|
||||||
private ExecutorService eService;
|
|
||||||
|
|
||||||
private final Object LOCK;
|
|
||||||
|
|
||||||
private SubmissionPublisher<Integer[]> wertPublisher;
|
|
||||||
|
|
||||||
public Generator3(Zahlengenerator hauptgenerator)
|
|
||||||
{
|
|
||||||
wert = new Integer[2];
|
|
||||||
wert[0] = -1;
|
|
||||||
wert[1] = 3;
|
|
||||||
|
|
||||||
laufend = false;
|
|
||||||
eService = Executors.newSingleThreadExecutor();
|
|
||||||
wertPublisher = new SubmissionPublisher<>();
|
|
||||||
this.addWertSubscription(hauptgenerator);
|
|
||||||
LOCK = new Object();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addWertSubscription(Subscriber<Integer[]> subscriber)
|
|
||||||
{
|
|
||||||
wertPublisher.subscribe(subscriber);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start()
|
|
||||||
{
|
|
||||||
laufend = true;
|
|
||||||
synchronized (LOCK)
|
|
||||||
{
|
|
||||||
LOCK.notifyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (eService.isShutdown())
|
|
||||||
{
|
|
||||||
eService = Executors.newSingleThreadExecutor();
|
|
||||||
}
|
|
||||||
eService.execute(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop()
|
|
||||||
{
|
|
||||||
synchronized(LOCK){
|
|
||||||
laufend = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
while (!laufend)
|
|
||||||
{
|
|
||||||
synchronized (LOCK)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
lg.info("WAIT_Gen3");
|
|
||||||
LOCK.wait();
|
|
||||||
}
|
|
||||||
catch (InterruptedException ex)
|
|
||||||
{
|
|
||||||
lg.warning(ex.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Thread.sleep(100);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
System.err.println(ex);
|
|
||||||
}
|
|
||||||
this.berechneWert();
|
|
||||||
wertPublisher.submit(wert);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void berechneWert()
|
|
||||||
{
|
|
||||||
wert[0] = (int) (1 + 6*Math.random());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -6,8 +6,8 @@
|
|||||||
package bandit.Model;
|
package bandit.Model;
|
||||||
|
|
||||||
import bandit.Model.Generator.Generator1;
|
import bandit.Model.Generator.Generator1;
|
||||||
import bandit.Model.Generator.Generator2;
|
//import bandit.Model.Generator.Generator2;
|
||||||
import bandit.Model.Generator.Generator3;
|
//import bandit.Model.Generator.Generator3;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Flow.Subscriber;
|
import java.util.concurrent.Flow.Subscriber;
|
||||||
@ -21,34 +21,34 @@ import java.util.concurrent.Flow;
|
|||||||
*
|
*
|
||||||
* @author le
|
* @author le
|
||||||
*/
|
*/
|
||||||
public class Zahlengenerator implements Subscriber<Integer[]> // Callable
|
public class Zahlengenerator implements Subscriber<Integer> // Callable
|
||||||
{
|
{
|
||||||
private static Logger lg = OhmLogger.getLogger(); //Logger sollten immer static sein da sie für alle instanzen loggs ausführen
|
private static Logger lg = OhmLogger.getLogger(); //Logger sollten immer static sein da sie für alle instanzen loggs ausführen
|
||||||
|
|
||||||
private Flow.Subscription subscription;
|
private Flow.Subscription subscription;
|
||||||
private SubmissionPublisher<Integer[]> wertPublisher;
|
private SubmissionPublisher<Integer> wertPublisher;
|
||||||
|
|
||||||
private Generator1 generator1;
|
private Generator1 generator1;
|
||||||
private Thread thd1;
|
private Thread thd1;
|
||||||
|
|
||||||
private Generator2 generator2;
|
// private Generator2 generator2;
|
||||||
private Thread thd2;
|
// private Thread thd2;
|
||||||
|
//
|
||||||
private Generator3 generator3;
|
// private Generator3 generator3;
|
||||||
private Thread thd3;
|
// private Thread thd3;
|
||||||
|
//
|
||||||
|
|
||||||
public Zahlengenerator()
|
public Zahlengenerator()
|
||||||
{
|
{
|
||||||
wertPublisher = new SubmissionPublisher<>();
|
wertPublisher = new SubmissionPublisher<>();
|
||||||
generator1 = new Generator1(this);
|
generator1 = new Generator1(this);
|
||||||
generator2 = new Generator2(this);
|
// generator2 = new Generator2(this);
|
||||||
generator3 = new Generator3(this);
|
// generator3 = new Generator3(this);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWertSubscription(Subscriber<Integer[]> subscriber)
|
public void addWertSubscription(Subscriber<Integer> subscriber)
|
||||||
{
|
{
|
||||||
wertPublisher.subscribe(subscriber);
|
wertPublisher.subscribe(subscriber);
|
||||||
}
|
}
|
||||||
@ -57,20 +57,22 @@ public class Zahlengenerator implements Subscriber<Integer[]> // Callable
|
|||||||
{
|
{
|
||||||
if(thd1==null){
|
if(thd1==null){
|
||||||
thd1 = new Thread(generator1);
|
thd1 = new Thread(generator1);
|
||||||
|
lg.info("thd1.start");
|
||||||
thd1.start();
|
thd1.start();
|
||||||
}
|
}
|
||||||
if(thd2==null){
|
// if(thd2==null){
|
||||||
thd2 = new Thread(generator2);
|
// thd2 = new Thread(generator2);
|
||||||
thd2.start();
|
// thd2.start();
|
||||||
}
|
// }
|
||||||
if(thd3==null){
|
// if(thd3==null){
|
||||||
thd3 = new Thread(generator3);
|
// thd3 = new Thread(generator3);
|
||||||
thd3.start();
|
// thd3.start();
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
lg.info("generator1.start");
|
||||||
generator1.start();
|
generator1.start();
|
||||||
generator2.start();
|
//generator2.start();
|
||||||
generator3.start();
|
//generator3.start();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -78,8 +80,8 @@ public class Zahlengenerator implements Subscriber<Integer[]> // Callable
|
|||||||
public void stop()
|
public void stop()
|
||||||
{
|
{
|
||||||
generator1.stop();
|
generator1.stop();
|
||||||
generator2.stop();
|
//generator2.stop();
|
||||||
generator3.stop();
|
//generator3.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -93,7 +95,7 @@ public void onSubscribe(Flow.Subscription subscription) {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(Integer[] item) {
|
public void onNext(Integer item) {
|
||||||
this.wertPublisher.submit(item);
|
this.wertPublisher.submit(item);
|
||||||
this.subscription.request(1);
|
this.subscription.request(1);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import java.util.concurrent.Flow.Subscription;
|
|||||||
*
|
*
|
||||||
* @author le
|
* @author le
|
||||||
*/
|
*/
|
||||||
public class WertAdapter implements Subscriber<Integer[]>
|
public class WertAdapter implements Subscriber<Integer>
|
||||||
{
|
{
|
||||||
private ZahlenView view;
|
private ZahlenView view;
|
||||||
private Zahlengenerator model;
|
private Zahlengenerator model;
|
||||||
@ -35,23 +35,12 @@ public class WertAdapter implements Subscriber<Integer[]>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(Integer item[])
|
public void onNext(Integer item)
|
||||||
{
|
{
|
||||||
String strWert = String.valueOf(item[0]);
|
String strWert = String.valueOf(item);
|
||||||
|
|
||||||
switch(item[1]){
|
|
||||||
case 1:
|
|
||||||
view.getLblZahl1().setText(strWert);
|
view.getLblZahl1().setText(strWert);
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
view.getLblZahl2().setText(strWert);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
view.getLblZahl3().setText(strWert);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.subscription.request(1);
|
this.subscription.request(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user