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