Generators implementiert
This commit is contained in:
1 parent
d8454b90de
commit
6ae236facd
10 files changed
+402
-114
No files matched your search
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import bandit.Model.Generator.Generator1;
|
||||
import bandit.Model.Generator.Generator2;
|
||||
import bandit.Model.Generator.Generator3;
|
||||
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;
|
||||
import java.util.concurrent.Flow;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author le
|
||||
*/
|
||||
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 int wert;
|
||||
private Flow.Subscription subscription;
|
||||
private SubmissionPublisher<Integer[]> wertPublisher;
|
||||
|
||||
private Generator1 generator1;
|
||||
private Thread thd1;
|
||||
|
||||
private Generator2 generator2;
|
||||
private Thread thd2;
|
||||
|
||||
private Generator3 generator3;
|
||||
private Thread thd3;
|
||||
|
||||
|
||||
public Zahlengenerator()
|
||||
{
|
||||
wertPublisher = new SubmissionPublisher<>();
|
||||
generator1 = new Generator1(this);
|
||||
generator2 = new Generator2(this);
|
||||
generator3 = new Generator3(this);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void addWertSubscription(Subscriber<Integer[]> subscriber)
|
||||
{
|
||||
wertPublisher.subscribe(subscriber);
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
if(thd1==null){
|
||||
thd1 = new Thread(generator1);
|
||||
thd1.start();
|
||||
}
|
||||
if(thd2==null){
|
||||
thd2 = new Thread(generator2);
|
||||
thd2.start();
|
||||
}
|
||||
if(thd3==null){
|
||||
thd3 = new Thread(generator3);
|
||||
thd3.start();
|
||||
}
|
||||
|
||||
generator1.start();
|
||||
generator2.start();
|
||||
generator3.start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
generator1.stop();
|
||||
generator2.stop();
|
||||
generator3.stop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Flow.Subscription subscription) {
|
||||
this.subscription = subscription;
|
||||
this.subscription.request(1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onNext(Integer[] item) {
|
||||
this.wertPublisher.submit(item);
|
||||
this.subscription.request(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user