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