ohmLogger funktioniert, aber drei gleich nicht...
This commit is contained in:
parent
1ddb300546
commit
5e3b1b7f20
@ -5,12 +5,10 @@
|
||||
|
||||
package bandit.Model;
|
||||
|
||||
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;
|
||||
|
||||
@ -21,21 +19,15 @@ import bandit.util.OhmLogger;
|
||||
public class Wuerfel implements Runnable // 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 WuerfelData data;
|
||||
private volatile boolean laufend;
|
||||
private ExecutorService eService;
|
||||
|
||||
private final Object LOCK;
|
||||
|
||||
private SubmissionPublisher<WuerfelData> wertPublisher;
|
||||
|
||||
public Wuerfel(int id)
|
||||
{
|
||||
data = new WuerfelData(id, 0);
|
||||
|
||||
|
||||
laufend = false;
|
||||
eService = null;
|
||||
wertPublisher = new SubmissionPublisher<>();
|
||||
@ -74,7 +66,7 @@ public class Wuerfel implements Runnable // Callable
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
lg.info("Generator1 run");
|
||||
lg.fine("Run "+ data.getId());
|
||||
while (true)
|
||||
{
|
||||
while (!laufend)
|
||||
@ -83,7 +75,7 @@ public class Wuerfel implements Runnable // Callable
|
||||
{
|
||||
try
|
||||
{
|
||||
lg.info("WAIT_Gen1");
|
||||
lg.fine("Stop " + data.getId());
|
||||
LOCK.wait();
|
||||
}
|
||||
catch (InterruptedException ex)
|
||||
@ -102,7 +94,6 @@ public class Wuerfel implements Runnable // Callable
|
||||
System.err.println(ex);
|
||||
}
|
||||
this.berechneWert();
|
||||
// lg.info("submit " + data.getValue());
|
||||
wertPublisher.submit(data);
|
||||
}
|
||||
}
|
||||
@ -112,6 +103,9 @@ public class Wuerfel implements Runnable // Callable
|
||||
data.setValue((int) (1 + 6*Math.random()));
|
||||
}
|
||||
|
||||
public synchronized int getValue(){
|
||||
return data.getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -33,19 +33,13 @@ public class Zahlengenerator implements Subscriber<WuerfelData> // Callable
|
||||
private Wuerfel wuerfel_2;
|
||||
private Wuerfel wuerfel_3;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Zahlengenerator()
|
||||
{
|
||||
subscriptions = new ArrayList<>();
|
||||
wertPublisher = new SubmissionPublisher<>();
|
||||
|
||||
wuerfel_1 = new Wuerfel(1);
|
||||
|
||||
wuerfel_2 = new Wuerfel(2);
|
||||
|
||||
wuerfel_3 = new Wuerfel(3);
|
||||
|
||||
synchronized(this){
|
||||
@ -53,9 +47,6 @@ public class Zahlengenerator implements Subscriber<WuerfelData> // Callable
|
||||
wuerfel_2.addWertSubscription(this);
|
||||
wuerfel_3.addWertSubscription(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void addWertSubscription(Subscriber<WuerfelData> subscriber)
|
||||
@ -70,9 +61,6 @@ public class Zahlengenerator implements Subscriber<WuerfelData> // Callable
|
||||
wuerfel_1.start();
|
||||
wuerfel_2.start();
|
||||
wuerfel_3.start();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void stop()
|
||||
@ -82,22 +70,24 @@ public class Zahlengenerator implements Subscriber<WuerfelData> // Callable
|
||||
wuerfel_1.stop();
|
||||
wuerfel_2.stop();
|
||||
wuerfel_3.stop();
|
||||
|
||||
if (wuerfel_1.getValue() == wuerfel_2.getValue() && wuerfel_2.getValue() == wuerfel_3.getValue()){
|
||||
lg.warning("This user has to much luck, he/she should go to a casino");
|
||||
}
|
||||
else
|
||||
lg.warning("unlucky" + wuerfel_1.getValue() + wuerfel_2.getValue() + wuerfel_3.getValue());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Flow.Subscription subscription) {
|
||||
lg.info("on subscribe");
|
||||
lg.config("on subscribe");
|
||||
this.subscriptions.add(subscription);
|
||||
subscription.request(1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onNext(WuerfelData item) {
|
||||
lg.info("on Next");
|
||||
lg.config("on Next");
|
||||
this.wertPublisher.submit(item);
|
||||
this.subscriptions.get(item.getId() - 1).request(1);
|
||||
}
|
||||
|
@ -39,12 +39,12 @@ public class StartStopController implements ActionListener
|
||||
{
|
||||
if (evt.getSource() == view.getBtnStart())
|
||||
{
|
||||
lg.info("Start");
|
||||
lg.info("Start gedruekt");
|
||||
model.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
lg.info("Stop");
|
||||
lg.info("Stop gedrueckt");
|
||||
model.stop();
|
||||
}
|
||||
}
|
||||
|
@ -8,9 +8,11 @@ package bandit.Schnittstelle;
|
||||
import bandit.Model.WuerfelData;
|
||||
import bandit.Model.Zahlengenerator;
|
||||
import bandit.View.ZahlenView;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Flow;
|
||||
import java.util.concurrent.Flow.Subscriber;
|
||||
import java.util.concurrent.Flow.Subscription;
|
||||
import javax.swing.Icon;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -70,7 +70,8 @@ public class ZahlenView extends javax.swing.JFrame
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
private void initComponents()
|
||||
{
|
||||
|
||||
jPanel1 = new javax.swing.JPanel();
|
||||
btnStart = new javax.swing.JButton();
|
||||
|
@ -8,6 +8,9 @@ package bandit.util;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
//import java.util.Properties;
|
||||
import java.util.logging.*;
|
||||
|
||||
@ -57,12 +60,12 @@ public class OhmLogger
|
||||
lg.getHandlers();
|
||||
lg.addHandler(ch);
|
||||
|
||||
lg.setLevel(Level.parse(System.getProperty("log.level", "WARNING")));
|
||||
Properties properties = new Properties();
|
||||
properties.load(configFile);
|
||||
java.util.logging.Level classLogLevel = java.util.logging.Level.parse(properties.getProperty("log.level"));
|
||||
lg.setLevel(classLogLevel);
|
||||
|
||||
// Lese spezifische Level für einzelne Klassen aus der Properties-Datei
|
||||
// Properties properties = new Properties();
|
||||
// properties.load(configFile);
|
||||
//
|
||||
//// Lese spezifische Level für einzelne Klassen aus der Properties-Datei
|
||||
// for (String key : properties.stringPropertyNames()) {
|
||||
// if (key.startsWith("log.level.")) {
|
||||
// String className = key.substring("log.level.".length());
|
||||
@ -72,6 +75,7 @@ public class OhmLogger
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
} else {
|
||||
System.err.println("Unable to find config.properties file. OhmLogger will use default settings.");
|
||||
}
|
||||
|
4
src/config.properties
Normal file
4
src/config.properties
Normal file
@ -0,0 +1,4 @@
|
||||
log.level=INFO
|
||||
# Beispiel f\u00fcr verschiedene Level f\u00fcr unterschiedliche Pakete
|
||||
# log.level.bandit.Zahlengenerator=FINE
|
||||
# log.level.bandit.Model.Wuerfel=WARNING
|
Loading…
x
Reference in New Issue
Block a user