test (à clean), essai de diffusion asynchrone qui utilise le scheluder dans CapteurImpl
This commit is contained in:
41
src/impl/DiffusionEpoque.java
Normal file
41
src/impl/DiffusionEpoque.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package impl;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import interfaces.AlgoDiffusion;
|
||||
import interfaces.ObserverDeCapteurAsync;
|
||||
|
||||
public class DiffusionEpoque implements AlgoDiffusion {
|
||||
|
||||
public CapteurImpl capteur;
|
||||
|
||||
@Override
|
||||
public void configure() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'configure'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
this.capteur.lock2();
|
||||
System.out.println("execute");
|
||||
Future<?>[] l = new Future<?>[capteur.observers.size()];
|
||||
int i = 0;
|
||||
for (ObserverDeCapteurAsync canal : capteur.observers) {
|
||||
Future<?> f = canal.update();
|
||||
l[i] = f;
|
||||
i++;
|
||||
}
|
||||
|
||||
for (Future<?> f : l) { //attend que les autres soient résolus //TODO
|
||||
try {
|
||||
f.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
this.capteur.unlock2();
|
||||
//this.capteur.unlock();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user