projet-donnees-reparties/linda/test/BasicTestCallback.java
2021-11-28 12:44:46 +01:00

50 lines
1.3 KiB
Java

package linda.test;
import linda.*;
import linda.Linda.eventMode;
import linda.Linda.eventTiming;
public class BasicTestCallback {
private static Linda linda;
private static Tuple cbmotif;
private static class MyCallback implements Callback {
public void call(Tuple t) {
System.out.println("CB got " + t);
linda.eventRegister(eventMode.TAKE, eventTiming.IMMEDIATE, cbmotif, this);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
System.out.println("CB done with " + t);
}
}
public static void main(String[] a) {
linda = new linda.shm.CentralizedLinda();
// linda = new linda.server.LindaClient("//localhost:4000/MonServeur");
cbmotif = new Tuple(Integer.class, String.class);
linda.eventRegister(eventMode.TAKE, eventTiming.IMMEDIATE, cbmotif, new MyCallback());
Tuple t1 = new Tuple(4, 5);
System.out.println("(2) write: " + t1);
linda.write(t1);
Tuple t2 = new Tuple("hello", 15);
System.out.println("(2) write: " + t2);
linda.write(t2);
linda.debug("(2)");
Tuple t3 = new Tuple(4, "foo");
System.out.println("(2) write: " + t3);
linda.write(t3);
linda.debug("(2)");
}
}