obserDeCaoteurAsync dans CapteurImpl
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package impl;
|
||||
|
||||
import interfaces.AlgoDiffusion;
|
||||
import interfaces.Capteur;
|
||||
import interfaces.Observer;
|
||||
import interfaces.ObserverDeCapteurAsync;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.util.ArrayList;
|
||||
@@ -10,14 +11,16 @@ import java.util.List;
|
||||
public class CapteurImpl implements Capteur {
|
||||
public Clock clock = Clock.systemUTC();
|
||||
public int value;
|
||||
public List<Observer<Integer>> observers;
|
||||
public AlgoDiffusion diffusion;
|
||||
public List<ObserverDeCapteurAsync> observers;
|
||||
|
||||
public CapteurImpl() {
|
||||
public CapteurImpl(AlgoDiffusion diffusion) {
|
||||
value = 0;
|
||||
observers = new ArrayList<>();
|
||||
this.diffusion = diffusion;
|
||||
}
|
||||
@Override
|
||||
public void attach(Observer<Integer> o) {
|
||||
public void attach(ObserverDeCapteurAsync o) {
|
||||
try {
|
||||
observers.add(o);
|
||||
}catch(Exception e) {
|
||||
@@ -27,7 +30,7 @@ public class CapteurImpl implements Capteur {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach(Observer<Integer> o) {
|
||||
public void detach(ObserverDeCapteurAsync o) {
|
||||
try {
|
||||
observers.remove(o);
|
||||
}catch(Exception e) {
|
||||
@@ -38,7 +41,10 @@ public class CapteurImpl implements Capteur {
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
|
||||
for (ObserverDeCapteurAsync canal : observers) {
|
||||
canal.update(this);
|
||||
}
|
||||
this.diffusion.execture();
|
||||
}
|
||||
|
||||
//AO2 - Concrete Servant
|
||||
@@ -46,4 +52,5 @@ public class CapteurImpl implements Capteur {
|
||||
public int getValue() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
package impl;
|
||||
|
||||
public class DiffusionAtomique {
|
||||
import interfaces.AlgoDiffusion;
|
||||
|
||||
public class DiffusionAtomique implements AlgoDiffusion {
|
||||
|
||||
@Override
|
||||
public void configure() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'configure'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execture() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'execture'");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user