Wuerfel wuerfelt
This commit is contained in:
1 parent
50deb6c1c9
commit
13483d909c
4 files changed
+127
-62
No files matched your search
@@ -14,73 +14,74 @@ import java.util.concurrent.SubmissionPublisher;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Logger;
|
||||
import bandit.util.OhmLogger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Flow;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author le
|
||||
*/
|
||||
public class Zahlengenerator implements Subscriber<Integer> // Callable
|
||||
public class Zahlengenerator implements Subscriber<WuerfelData> // Callable
|
||||
{
|
||||
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 SubmissionPublisher<Integer> wertPublisher;
|
||||
private ArrayList<Flow.Subscription> subscriptions;
|
||||
//private Flow.Subscription subscription;
|
||||
private SubmissionPublisher<WuerfelData> wertPublisher;
|
||||
|
||||
private Wuerfel wuerfel_1;
|
||||
private Wuerfel wuerfel_2;
|
||||
private Wuerfel wuerfel_3;
|
||||
|
||||
|
||||
private Wuerfel generator1;
|
||||
private Thread thd1;
|
||||
|
||||
// private Generator2 generator2;
|
||||
// private Thread thd2;
|
||||
//
|
||||
// private Generator3 generator3;
|
||||
// private Thread thd3;
|
||||
//
|
||||
|
||||
|
||||
public Zahlengenerator()
|
||||
{
|
||||
subscriptions = new ArrayList<>();
|
||||
wertPublisher = new SubmissionPublisher<>();
|
||||
generator1 = new Wuerfel(this);
|
||||
// generator2 = new Generator2(this);
|
||||
// generator3 = new Generator3(this);
|
||||
|
||||
wuerfel_1 = new Wuerfel(1);
|
||||
|
||||
wuerfel_2 = new Wuerfel(2);
|
||||
|
||||
wuerfel_3 = new Wuerfel(3);
|
||||
|
||||
synchronized(this){
|
||||
wuerfel_1.addWertSubscription(this);
|
||||
wuerfel_2.addWertSubscription(this);
|
||||
wuerfel_3.addWertSubscription(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void addWertSubscription(Subscriber<Integer> subscriber)
|
||||
public void addWertSubscription(Subscriber<WuerfelData> subscriber)
|
||||
{
|
||||
wertPublisher.subscribe(subscriber);
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
if(thd1==null){
|
||||
thd1 = new Thread(generator1);
|
||||
lg.info("thd1.start");
|
||||
thd1.start();
|
||||
}
|
||||
// if(thd2==null){
|
||||
// thd2 = new Thread(generator2);
|
||||
// thd2.start();
|
||||
// }
|
||||
// if(thd3==null){
|
||||
// thd3 = new Thread(generator3);
|
||||
// thd3.start();
|
||||
// }
|
||||
|
||||
lg.info("generator1.start");
|
||||
generator1.start();
|
||||
//generator2.start();
|
||||
//generator3.start();
|
||||
lg.info("Generator gestartet");
|
||||
|
||||
wuerfel_1.start();
|
||||
wuerfel_2.start();
|
||||
wuerfel_3.start();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
generator1.stop();
|
||||
//generator2.stop();
|
||||
//generator3.stop();
|
||||
lg.info("Generator gestopt");
|
||||
|
||||
wuerfel_1.stop();
|
||||
wuerfel_2.stop();
|
||||
wuerfel_3.stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -88,15 +89,17 @@ public class Zahlengenerator implements Subscriber<Integer> // Callable
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Flow.Subscription subscription) {
|
||||
this.subscription = subscription;
|
||||
this.subscription.request(1);
|
||||
lg.info("on subscribe");
|
||||
this.subscriptions.add(subscription);
|
||||
subscription.request(1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onNext(Integer item) {
|
||||
public void onNext(WuerfelData item) {
|
||||
lg.info("on Next");
|
||||
this.wertPublisher.submit(item);
|
||||
this.subscription.request(1);
|
||||
this.subscriptions.get(item.getId() - 1).request(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user