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