correction init Diffusion dans le main
This commit is contained in:
@@ -11,7 +11,7 @@ public class CapteurImpl implements Capteur {
|
||||
private int value;
|
||||
private AlgoDiffusion diffusion;
|
||||
protected List<ObserverDeCapteurAsync> observers=new ArrayList<ObserverDeCapteurAsync>();
|
||||
private Boolean locker;
|
||||
private Boolean locker = false;
|
||||
|
||||
@Override
|
||||
public void attach(ObserverDeCapteurAsync o) {
|
||||
@@ -31,10 +31,14 @@ public class CapteurImpl implements Capteur {
|
||||
}
|
||||
|
||||
public void lock(){
|
||||
locker = false;
|
||||
locker = true;
|
||||
}
|
||||
public void unlock(){
|
||||
locker = true;
|
||||
locker = false;
|
||||
}
|
||||
|
||||
public void setAlgoDiffusion(AlgoDiffusion diffusion){
|
||||
this.diffusion = diffusion;
|
||||
}
|
||||
|
||||
//AO2 - Concrete Servant
|
||||
|
||||
@@ -19,10 +19,10 @@ public class DiffusionAtomique implements AlgoDiffusion {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
capteur.lock(); //TODO unlock
|
||||
List<ObserverDeCapteurAsync> canaux = capteur.observers;
|
||||
for (ObserverDeCapteurAsync canal : canaux) {
|
||||
capteur.lock();
|
||||
for (ObserverDeCapteurAsync canal : capteur.observers) {
|
||||
canal.update(this.capteur);
|
||||
}
|
||||
capteur.unlock(); //TODO
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ public class Scheduler {
|
||||
private final ScheduledExecutorService scheduler;
|
||||
|
||||
public Scheduler(int nbCanaux) {
|
||||
int nThread = 2+2*nbCanaux;
|
||||
int nThread = 20+2*nbCanaux;
|
||||
scheduler = Executors.newScheduledThreadPool(nThread);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package interfaces;
|
||||
|
||||
public interface AlgoDiffusion {
|
||||
|
||||
public void configure();
|
||||
|
||||
public void execute();
|
||||
|
||||
@@ -6,9 +6,9 @@ import java.util.concurrent.TimeUnit;
|
||||
import impl.Afficheur;
|
||||
import impl.Canal;
|
||||
import impl.CapteurImpl;
|
||||
import impl.DiffusionAtomique;
|
||||
import impl.Scheduler;
|
||||
import interfaces.Capteur;
|
||||
import interfaces.ObserverdeCapteur;
|
||||
import interfaces.AlgoDiffusion;
|
||||
|
||||
public class main {
|
||||
|
||||
@@ -16,7 +16,10 @@ public class main {
|
||||
|
||||
public static void main(String[] argv){
|
||||
Scheduler scheduler = new Scheduler(NB_CANAUX);
|
||||
Capteur c = new CapteurImpl();
|
||||
CapteurImpl c = new CapteurImpl();
|
||||
DiffusionAtomique algo = new DiffusionAtomique();
|
||||
algo.capteur = c;
|
||||
c.setAlgoDiffusion(algo);
|
||||
|
||||
/*
|
||||
Afficheur a=new Afficheur();
|
||||
|
||||
Reference in New Issue
Block a user