ohmLogger funktioniert, aber drei gleich nicht...
This commit is contained in:
parent
1ddb300546
commit
5e3b1b7f20
@ -5,12 +5,10 @@
|
|||||||
|
|
||||||
package bandit.Model;
|
package bandit.Model;
|
||||||
|
|
||||||
import bandit.Model.Zahlengenerator;
|
|
||||||
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;
|
||||||
import java.util.concurrent.SubmissionPublisher;
|
import java.util.concurrent.SubmissionPublisher;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import bandit.util.OhmLogger;
|
import bandit.util.OhmLogger;
|
||||||
|
|
||||||
@ -21,21 +19,15 @@ import bandit.util.OhmLogger;
|
|||||||
public class Wuerfel implements Runnable // Callable
|
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 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 WuerfelData data;
|
||||||
private volatile boolean laufend;
|
private volatile boolean laufend;
|
||||||
private ExecutorService eService;
|
private ExecutorService eService;
|
||||||
|
|
||||||
private final Object LOCK;
|
private final Object LOCK;
|
||||||
|
|
||||||
private SubmissionPublisher<WuerfelData> wertPublisher;
|
private SubmissionPublisher<WuerfelData> wertPublisher;
|
||||||
|
|
||||||
public Wuerfel(int id)
|
public Wuerfel(int id)
|
||||||
{
|
{
|
||||||
data = new WuerfelData(id, 0);
|
data = new WuerfelData(id, 0);
|
||||||
|
|
||||||
|
|
||||||
laufend = false;
|
laufend = false;
|
||||||
eService = null;
|
eService = null;
|
||||||
wertPublisher = new SubmissionPublisher<>();
|
wertPublisher = new SubmissionPublisher<>();
|
||||||
@ -74,7 +66,7 @@ public class Wuerfel implements Runnable // Callable
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
lg.info("Generator1 run");
|
lg.fine("Run "+ data.getId());
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
while (!laufend)
|
while (!laufend)
|
||||||
@ -83,7 +75,7 @@ public class Wuerfel implements Runnable // Callable
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
lg.info("WAIT_Gen1");
|
lg.fine("Stop " + data.getId());
|
||||||
LOCK.wait();
|
LOCK.wait();
|
||||||
}
|
}
|
||||||
catch (InterruptedException ex)
|
catch (InterruptedException ex)
|
||||||
@ -102,7 +94,6 @@ public class Wuerfel implements Runnable // Callable
|
|||||||
System.err.println(ex);
|
System.err.println(ex);
|
||||||
}
|
}
|
||||||
this.berechneWert();
|
this.berechneWert();
|
||||||
// lg.info("submit " + data.getValue());
|
|
||||||
wertPublisher.submit(data);
|
wertPublisher.submit(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,6 +103,9 @@ public class Wuerfel implements Runnable // Callable
|
|||||||
data.setValue((int) (1 + 6*Math.random()));
|
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_2;
|
||||||
private Wuerfel wuerfel_3;
|
private Wuerfel wuerfel_3;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Zahlengenerator()
|
public Zahlengenerator()
|
||||||
{
|
{
|
||||||
subscriptions = new ArrayList<>();
|
subscriptions = new ArrayList<>();
|
||||||
wertPublisher = new SubmissionPublisher<>();
|
wertPublisher = new SubmissionPublisher<>();
|
||||||
|
|
||||||
wuerfel_1 = new Wuerfel(1);
|
wuerfel_1 = new Wuerfel(1);
|
||||||
|
|
||||||
wuerfel_2 = new Wuerfel(2);
|
wuerfel_2 = new Wuerfel(2);
|
||||||
|
|
||||||
wuerfel_3 = new Wuerfel(3);
|
wuerfel_3 = new Wuerfel(3);
|
||||||
|
|
||||||
synchronized(this){
|
synchronized(this){
|
||||||
@ -53,9 +47,6 @@ public class Zahlengenerator implements Subscriber<WuerfelData> // Callable
|
|||||||
wuerfel_2.addWertSubscription(this);
|
wuerfel_2.addWertSubscription(this);
|
||||||
wuerfel_3.addWertSubscription(this);
|
wuerfel_3.addWertSubscription(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWertSubscription(Subscriber<WuerfelData> subscriber)
|
public void addWertSubscription(Subscriber<WuerfelData> subscriber)
|
||||||
@ -70,9 +61,6 @@ public class Zahlengenerator implements Subscriber<WuerfelData> // Callable
|
|||||||
wuerfel_1.start();
|
wuerfel_1.start();
|
||||||
wuerfel_2.start();
|
wuerfel_2.start();
|
||||||
wuerfel_3.start();
|
wuerfel_3.start();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop()
|
public void stop()
|
||||||
@ -82,22 +70,24 @@ public class Zahlengenerator implements Subscriber<WuerfelData> // Callable
|
|||||||
wuerfel_1.stop();
|
wuerfel_1.stop();
|
||||||
wuerfel_2.stop();
|
wuerfel_2.stop();
|
||||||
wuerfel_3.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
|
@Override
|
||||||
public void onSubscribe(Flow.Subscription subscription) {
|
public void onSubscribe(Flow.Subscription subscription) {
|
||||||
lg.info("on subscribe");
|
lg.config("on subscribe");
|
||||||
this.subscriptions.add(subscription);
|
this.subscriptions.add(subscription);
|
||||||
subscription.request(1);
|
subscription.request(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(WuerfelData item) {
|
public void onNext(WuerfelData item) {
|
||||||
lg.info("on Next");
|
lg.config("on Next");
|
||||||
this.wertPublisher.submit(item);
|
this.wertPublisher.submit(item);
|
||||||
this.subscriptions.get(item.getId() - 1).request(1);
|
this.subscriptions.get(item.getId() - 1).request(1);
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,12 @@ public class StartStopController implements ActionListener
|
|||||||
{
|
{
|
||||||
if (evt.getSource() == view.getBtnStart())
|
if (evt.getSource() == view.getBtnStart())
|
||||||
{
|
{
|
||||||
lg.info("Start");
|
lg.info("Start gedruekt");
|
||||||
model.start();
|
model.start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lg.info("Stop");
|
lg.info("Stop gedrueckt");
|
||||||
model.stop();
|
model.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,11 @@ package bandit.Schnittstelle;
|
|||||||
import bandit.Model.WuerfelData;
|
import bandit.Model.WuerfelData;
|
||||||
import bandit.Model.Zahlengenerator;
|
import bandit.Model.Zahlengenerator;
|
||||||
import bandit.View.ZahlenView;
|
import bandit.View.ZahlenView;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.Flow;
|
import java.util.concurrent.Flow;
|
||||||
import java.util.concurrent.Flow.Subscriber;
|
import java.util.concurrent.Flow.Subscriber;
|
||||||
import java.util.concurrent.Flow.Subscription;
|
import java.util.concurrent.Flow.Subscription;
|
||||||
|
import javax.swing.Icon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -69,49 +69,50 @@ public class ZahlenView extends javax.swing.JFrame
|
|||||||
* regenerated by the Form Editor.
|
* regenerated by the Form Editor.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
private void initComponents() {
|
private void initComponents()
|
||||||
|
{
|
||||||
|
|
||||||
jPanel1 = new javax.swing.JPanel();
|
jPanel1 = new javax.swing.JPanel();
|
||||||
btnStart = new javax.swing.JButton();
|
btnStart = new javax.swing.JButton();
|
||||||
btnStop = new javax.swing.JButton();
|
btnStop = new javax.swing.JButton();
|
||||||
jPanel2 = new javax.swing.JPanel();
|
jPanel2 = new javax.swing.JPanel();
|
||||||
lblZahl1 = new javax.swing.JLabel();
|
lblZahl1 = new javax.swing.JLabel();
|
||||||
lblZahl2 = new javax.swing.JLabel();
|
lblZahl2 = new javax.swing.JLabel();
|
||||||
lblZahl3 = new javax.swing.JLabel();
|
lblZahl3 = new javax.swing.JLabel();
|
||||||
|
|
||||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
btnStart.setText("Start");
|
btnStart.setText("Start");
|
||||||
jPanel1.add(btnStart);
|
jPanel1.add(btnStart);
|
||||||
|
|
||||||
btnStop.setText("Stop");
|
btnStop.setText("Stop");
|
||||||
jPanel1.add(btnStop);
|
jPanel1.add(btnStop);
|
||||||
|
|
||||||
getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);
|
getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);
|
||||||
|
|
||||||
lblZahl1.setFont(new java.awt.Font("Liberation Sans", 0, 100)); // NOI18N
|
lblZahl1.setFont(new java.awt.Font("Liberation Sans", 0, 100)); // NOI18N
|
||||||
lblZahl1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
lblZahl1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
||||||
lblZahl1.setText("?");
|
lblZahl1.setText("?");
|
||||||
lblZahl1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
|
lblZahl1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
|
||||||
jPanel2.add(lblZahl1);
|
jPanel2.add(lblZahl1);
|
||||||
|
|
||||||
lblZahl2.setFont(new java.awt.Font("Liberation Sans", 0, 100)); // NOI18N
|
lblZahl2.setFont(new java.awt.Font("Liberation Sans", 0, 100)); // NOI18N
|
||||||
lblZahl2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
lblZahl2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
||||||
lblZahl2.setText("?");
|
lblZahl2.setText("?");
|
||||||
lblZahl2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
|
lblZahl2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
|
||||||
jPanel2.add(lblZahl2);
|
jPanel2.add(lblZahl2);
|
||||||
|
|
||||||
lblZahl3.setFont(new java.awt.Font("Liberation Sans", 0, 100)); // NOI18N
|
lblZahl3.setFont(new java.awt.Font("Liberation Sans", 0, 100)); // NOI18N
|
||||||
lblZahl3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
lblZahl3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
||||||
lblZahl3.setText("?");
|
lblZahl3.setText("?");
|
||||||
lblZahl3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
|
lblZahl3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
|
||||||
jPanel2.add(lblZahl3);
|
jPanel2.add(lblZahl3);
|
||||||
|
|
||||||
getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
|
getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
}// </editor-fold>//GEN-END:initComponents
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
@ -162,13 +163,13 @@ public class ZahlenView extends javax.swing.JFrame
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
private javax.swing.JButton btnStart;
|
private javax.swing.JButton btnStart;
|
||||||
private javax.swing.JButton btnStop;
|
private javax.swing.JButton btnStop;
|
||||||
private javax.swing.JPanel jPanel1;
|
private javax.swing.JPanel jPanel1;
|
||||||
private javax.swing.JPanel jPanel2;
|
private javax.swing.JPanel jPanel2;
|
||||||
private javax.swing.JLabel lblZahl1;
|
private javax.swing.JLabel lblZahl1;
|
||||||
private javax.swing.JLabel lblZahl2;
|
private javax.swing.JLabel lblZahl2;
|
||||||
private javax.swing.JLabel lblZahl3;
|
private javax.swing.JLabel lblZahl3;
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,9 @@ package bandit.util;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
//import java.util.Properties;
|
//import java.util.Properties;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
@ -57,20 +60,21 @@ public class OhmLogger
|
|||||||
lg.getHandlers();
|
lg.getHandlers();
|
||||||
lg.addHandler(ch);
|
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
|
//// Lese spezifische Level für einzelne Klassen aus der Properties-Datei
|
||||||
// Properties properties = new Properties();
|
// for (String key : properties.stringPropertyNames()) {
|
||||||
// properties.load(configFile);
|
// if (key.startsWith("log.level.")) {
|
||||||
//
|
// String className = key.substring("log.level.".length());
|
||||||
// for (String key : properties.stringPropertyNames()) {
|
// Logger classLogger = Logger.getLogger(className);
|
||||||
// if (key.startsWith("log.level.")) {
|
// java.util.logging.Level classLogLevel = java.util.logging.Level.parse(properties.getProperty(key));
|
||||||
// String className = key.substring("log.level.".length());
|
// classLogger.setLevel(classLogLevel);
|
||||||
// Logger classLogger = Logger.getLogger(className);
|
// }
|
||||||
// java.util.logging.Level classLogLevel = java.util.logging.Level.parse(properties.getProperty(key));
|
// }
|
||||||
// classLogger.setLevel(classLogLevel);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Unable to find config.properties file. OhmLogger will use default settings.");
|
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