12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-
- package bandit.model;
-
- import java.util.logging.Logger;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- import java.util.concurrent.Flow.Subscriber;
- import java.util.concurrent.SubmissionPublisher;
-
- /**
- *
- * @author chris
- */
- public class WuerfelModel implements Runnable
- {
- private int wert;
- private volatile boolean laufend;
- private SubmissionPublisher<Integer> iPublisher;
- private SubmissionPublisher<Boolean> bPublisher;
- private ExecutorService eService;
- private static Logger lg = Logger.getLogger("Wuerfelthreads");
-
- public WuerfelModel()
- {
- wert = 1;
- laufend = false;
- iPublisher = new SubmissionPublisher<>();
- bPublisher = new SubmissionPublisher<>();
- eService = Executors.newSingleThreadExecutor();
- }
- public void start()
- {
- laufend = true;
- eService.submit(this);
- lg.info("start");
- }
-
- public void stop()
- {
- laufend = false;
- lg.info("stop");
- }
-
- public void addWertSubscription(Subscriber<Integer> subscriber)
- {
- iPublisher.subscribe(subscriber);
- }
-
- public void addZustandSubscription(Subscriber<Boolean> subscriber)
- {
- bPublisher.subscribe(subscriber);
- }
-
- @Override
- public void run()
- {
- //wert++;
- //if(wert >= 7){
- // wert = 1;
- //}
- while (laufend)
- {
-
- /*
- try
- {
- Thread.sleep(10);
- }
- catch (Exception e)
- {
- System.err.println(e);
- }
- wert++;
- if(wert >= 7){
- wert = 1;
- }
-
- iPublisher.submit(wert);
- */
- }
- }
- }
|