omg les tests fonctionnent tous Poogers
Co-authored-by: gdamms <gdamms@users.noreply.github.com>
This commit is contained in:
parent
89735ebea9
commit
efec8ad0a1
|
@ -95,12 +95,16 @@ public class LindaClient implements Linda {
|
|||
}
|
||||
|
||||
public void eventRegister(eventMode mode, eventTiming timing, Tuple template, Callback callback) {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
lindaServer.eventRegister(mode, timing, template, callback);
|
||||
callback.call(lindaServer.waitForTuple(mode, timing, template));
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
public void debug(String prefix) {
|
||||
try {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package linda.server;
|
||||
|
||||
import linda.Callback;
|
||||
import linda.Linda;
|
||||
import linda.Tuple;
|
||||
|
||||
|
@ -24,8 +23,7 @@ public interface LindaRemote extends Remote {
|
|||
|
||||
public Collection<Tuple> readAll(Tuple template) throws RemoteException;
|
||||
|
||||
public void eventRegister(Linda.eventMode mode, Linda.eventTiming timing, Tuple template, Callback callback)
|
||||
throws RemoteException;
|
||||
public Tuple waitForTuple(Linda.eventMode mode, Linda.eventTiming timing, Tuple template) throws RemoteException;
|
||||
|
||||
public void debug(String prefix) throws RemoteException;
|
||||
}
|
||||
|
|
|
@ -3,14 +3,13 @@ package linda.server;
|
|||
import java.util.Collection;
|
||||
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
import java.net.MalformedURLException;
|
||||
import java.rmi.*;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
|
||||
import linda.Callback;
|
||||
import linda.Linda;
|
||||
import linda.Tuple;
|
||||
import linda.Linda.eventMode;
|
||||
import linda.Linda.eventTiming;
|
||||
import linda.shm.CentralizedLinda;
|
||||
|
||||
/**
|
||||
|
@ -18,7 +17,7 @@ import linda.shm.CentralizedLinda;
|
|||
*/
|
||||
public class LindaServer extends UnicastRemoteObject implements LindaRemote {
|
||||
|
||||
Linda lindaInstance;
|
||||
CentralizedLinda lindaInstance;
|
||||
Registry registry;
|
||||
LindaServer ls;
|
||||
|
||||
|
@ -86,9 +85,8 @@ public class LindaServer extends UnicastRemoteObject implements LindaRemote {
|
|||
return lindaInstance.readAll(template);
|
||||
}
|
||||
|
||||
public void eventRegister(Linda.eventMode mode, Linda.eventTiming timing, Tuple template, Callback callback)
|
||||
throws RemoteException {
|
||||
lindaInstance.eventRegister(mode, timing, template, callback);
|
||||
public Tuple waitForTuple(eventMode mode, eventTiming timing, Tuple template) throws RemoteException {
|
||||
return lindaInstance.waitForTuple(mode, timing, template);
|
||||
}
|
||||
|
||||
public void debug(String prefix) throws RemoteException {
|
||||
|
|
|
@ -233,13 +233,10 @@ public class CentralizedLinda implements Linda {
|
|||
return results;
|
||||
}
|
||||
|
||||
public void eventRegister(eventMode mode, eventTiming timing, Tuple template, Callback callback) {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
public Tuple waitForTuple(eventMode mode, eventTiming timing, Tuple template) {
|
||||
switch (timing) {
|
||||
case IMMEDIATE:
|
||||
callback.call(mode == eventMode.READ ? read(template) : take(template));
|
||||
return;
|
||||
return mode == eventMode.READ ? read(template) : take(template);
|
||||
case FUTURE:
|
||||
Collection<Tuple> knownTuples = new ArrayList<Tuple>();
|
||||
synchronized (tuples) {
|
||||
|
@ -247,10 +244,17 @@ public class CentralizedLinda implements Linda {
|
|||
knownTuples.add((Tuple) t.clone());
|
||||
}
|
||||
}
|
||||
callback.call(future_search(template, knownTuples, mode));
|
||||
return;
|
||||
return future_search(template, knownTuples, mode);
|
||||
default:
|
||||
return null; // n'arrive jamais
|
||||
}
|
||||
}
|
||||
|
||||
public void eventRegister(eventMode mode, eventTiming timing, Tuple template, Callback callback) {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
callback.call(waitForTuple(mode, timing, template));
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
|
||||
package linda.test;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import linda.*;
|
||||
import linda.Linda.eventMode;
|
||||
import linda.Linda.eventTiming;
|
||||
|
||||
public class BasicTestCB {
|
||||
public class BasicTestCB implements Serializable {
|
||||
|
||||
private static Linda linda;
|
||||
private static Tuple cbmotif;
|
||||
|
||||
private static class MyCallback implements Callback {
|
||||
private static class MyCallback implements Callback, Serializable {
|
||||
public void call(Tuple t) {
|
||||
System.out.println("CB got " + t);
|
||||
linda.eventRegister(eventMode.TAKE, eventTiming.IMMEDIATE, cbmotif, this);
|
||||
|
|
|
@ -3,7 +3,6 @@ package linda.test;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.rmi.AccessException;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
|
|
|
@ -13,6 +13,12 @@ import linda.Tuple;
|
|||
|
||||
public class REPL implements Callback, Serializable {
|
||||
|
||||
public class MyCallback implements Callback {
|
||||
public void call(Tuple t) {
|
||||
System.out.println("Tuple de l'event register : " + t);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
@ -36,6 +42,10 @@ public class REPL implements Callback, Serializable {
|
|||
System.out.println("tt : tryTake tuple");
|
||||
System.out.println("ra : readAll tuple");
|
||||
System.out.println("ta : takeAll tuple");
|
||||
System.out.println("evRI : eventRegister Read Immediate");
|
||||
System.out.println("evRF : eventRegister Read Future");
|
||||
System.out.println("evTI : eventRegister Take Immediate");
|
||||
System.out.println("evTF : eventRegister Take Future");
|
||||
System.out.println("\nPour les templates :");
|
||||
System.out.println("I : int");
|
||||
System.out.println("S : string");
|
||||
|
@ -100,6 +110,8 @@ public class REPL implements Callback, Serializable {
|
|||
System.out.print(ti + " ");
|
||||
}
|
||||
System.out.println(" pris.");
|
||||
} else if (args[0].equals("evRI")) {
|
||||
lc.even
|
||||
} else {
|
||||
System.out.println("Il faut indiquer la commande et un tuple ! Ex : > r 1 S\n");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue