2021-11-28 11:44:46 +00:00
|
|
|
|
|
|
|
package linda.test;
|
|
|
|
|
|
|
|
import linda.*;
|
|
|
|
import linda.Linda.eventMode;
|
|
|
|
import linda.Linda.eventTiming;
|
|
|
|
|
|
|
|
public class BasicTestCB {
|
|
|
|
|
|
|
|
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.debug("(1.1)");
|
|
|
|
Tuple t1 = new Tuple(1, "a");
|
2021-11-30 16:39:17 +00:00
|
|
|
System.out.println("(1) write: " + t1);
|
2021-11-28 11:44:46 +00:00
|
|
|
linda.write(t1);
|
|
|
|
linda.debug("(1.2)");
|
|
|
|
|
2021-11-30 16:39:17 +00:00
|
|
|
linda.eventRegister(eventMode.READ, eventTiming.FUTURE, cbmotif, new MyCallback());
|
2021-11-28 11:44:46 +00:00
|
|
|
try {
|
|
|
|
Thread.sleep(5000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
linda.debug("(2.1)");
|
|
|
|
Tuple t2 = new Tuple(2, "b");
|
|
|
|
System.out.println("(2) write: " + t2);
|
|
|
|
linda.write(t2);
|
|
|
|
linda.debug("(2.2)");
|
|
|
|
|
|
|
|
try {
|
|
|
|
Thread.sleep(5000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
linda.debug("(3.1)");
|
|
|
|
Tuple t3 = new Tuple(3, "c");
|
2021-11-30 16:39:17 +00:00
|
|
|
System.out.println("(3) write: " + t3);
|
2021-11-28 11:44:46 +00:00
|
|
|
linda.write(t3);
|
|
|
|
linda.debug("(3.2)");
|
|
|
|
|
|
|
|
try {
|
|
|
|
Thread.sleep(5000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|