omg les tests fonctionnent tous Poogers

Co-authored-by: gdamms <gdamms@users.noreply.github.com>
This commit is contained in:
Laureηt 2022-01-12 11:10:10 +01:00
parent 89735ebea9
commit efec8ad0a1
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
7 changed files with 49 additions and 32 deletions

View file

@ -95,11 +95,15 @@ 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) {
try { new Thread() {
lindaServer.eventRegister(mode, timing, template, callback); public void run() {
} catch (RemoteException e) { try {
e.printStackTrace(); callback.call(lindaServer.waitForTuple(mode, timing, template));
} } catch (RemoteException e) {
e.printStackTrace();
}
}
}.start();
} }
public void debug(String prefix) { public void debug(String prefix) {

View file

@ -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;
} }

View file

@ -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 {

View file

@ -233,23 +233,27 @@ public class CentralizedLinda implements Linda {
return results; return results;
} }
public Tuple waitForTuple(eventMode mode, eventTiming timing, Tuple template) {
switch (timing) {
case IMMEDIATE:
return mode == eventMode.READ ? read(template) : take(template);
case FUTURE:
Collection<Tuple> knownTuples = new ArrayList<Tuple>();
synchronized (tuples) {
for (Tuple t : tuples) {
knownTuples.add((Tuple) t.clone());
}
}
return future_search(template, knownTuples, mode);
default:
return null; // n'arrive jamais
}
}
public void eventRegister(eventMode mode, eventTiming timing, Tuple template, Callback callback) { public void eventRegister(eventMode mode, eventTiming timing, Tuple template, Callback callback) {
new Thread() { new Thread() {
public void run() { public void run() {
switch (timing) { callback.call(waitForTuple(mode, timing, template));
case IMMEDIATE:
callback.call(mode == eventMode.READ ? read(template) : take(template));
return;
case FUTURE:
Collection<Tuple> knownTuples = new ArrayList<Tuple>();
synchronized (tuples) {
for (Tuple t : tuples) {
knownTuples.add((Tuple) t.clone());
}
}
callback.call(future_search(template, knownTuples, mode));
return;
}
} }
}.start(); }.start();
} }

View file

@ -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);

View file

@ -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;

View file

@ -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");
} }