2021-11-27 16:50:33 +00:00
|
|
|
package linda.server;
|
|
|
|
|
|
|
|
import linda.Callback;
|
|
|
|
import linda.Linda;
|
|
|
|
import linda.Tuple;
|
2021-11-30 16:39:17 +00:00
|
|
|
import linda.shm.CentralizedLinda;
|
2021-11-27 16:50:33 +00:00
|
|
|
|
2021-11-30 16:39:17 +00:00
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.rmi.*;
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client part of a client/server implementation of Linda.
|
|
|
|
* It implements the Linda interface and propagates everything to the server it
|
|
|
|
* is connected to.
|
|
|
|
*/
|
2021-11-27 16:50:33 +00:00
|
|
|
public class LindaClient implements Linda {
|
2021-11-30 16:39:17 +00:00
|
|
|
|
2021-12-02 20:57:01 +00:00
|
|
|
LindaRemote lindaServer;
|
2021-11-30 16:39:17 +00:00
|
|
|
|
|
|
|
public static void main(String[] args) {
|
2021-12-02 20:57:01 +00:00
|
|
|
|
|
|
|
LindaClient lc = new LindaClient(args[0]);
|
2021-11-30 16:39:17 +00:00
|
|
|
|
2021-12-02 20:57:01 +00:00
|
|
|
Tuple t1 = new Tuple(1, "a");
|
|
|
|
System.out.print("Tuple " + t1 + " envoyé");
|
|
|
|
lc.write(t1);
|
|
|
|
System.out.print("Tuple " + t1 + " écrit");
|
2021-11-30 16:39:17 +00:00
|
|
|
|
2021-12-02 20:57:01 +00:00
|
|
|
try {
|
|
|
|
Thread.sleep(3000);
|
|
|
|
} catch (InterruptedException e) {
|
2021-11-30 16:39:17 +00:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2021-12-02 20:57:01 +00:00
|
|
|
|
|
|
|
Tuple template = new Tuple(Integer.class, String.class);
|
|
|
|
System.out.print("Lecture " + template + " envoyé");
|
|
|
|
Tuple t2 = lc.read(template);
|
|
|
|
System.out.print("Tuple " + t2 + " lu");
|
|
|
|
|
2021-11-30 16:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the Linda implementation.
|
|
|
|
*
|
|
|
|
* @param serverURI the URI of the server, e.g.
|
|
|
|
* "rmi://localhost:4000/LindaServer" or
|
|
|
|
* "//localhost:4000/LindaServer".
|
2021-11-27 16:50:33 +00:00
|
|
|
*/
|
|
|
|
public LindaClient(String serverURI) {
|
2021-11-30 16:39:17 +00:00
|
|
|
try {
|
2021-12-02 20:57:01 +00:00
|
|
|
this.lindaServer = (LindaRemote) Naming.lookup(serverURI);
|
2021-11-30 16:39:17 +00:00
|
|
|
} catch (MalformedURLException | RemoteException | NotBoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void write(Tuple t) {
|
2021-12-02 20:57:01 +00:00
|
|
|
try {
|
|
|
|
lindaServer.write(t);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2021-11-30 16:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Tuple take(Tuple template) {
|
2021-12-02 20:57:01 +00:00
|
|
|
try {
|
|
|
|
return lindaServer.take(template);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
2021-11-27 16:50:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 16:39:17 +00:00
|
|
|
public Tuple read(Tuple template) {
|
2021-12-02 20:57:01 +00:00
|
|
|
try {
|
|
|
|
return lindaServer.read(template);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
2021-11-30 16:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Tuple tryTake(Tuple template) {
|
2021-12-02 20:57:01 +00:00
|
|
|
try {
|
|
|
|
return lindaServer.tryTake(template);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
2021-11-30 16:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Tuple tryRead(Tuple template) {
|
2021-12-02 20:57:01 +00:00
|
|
|
try {
|
|
|
|
return lindaServer.tryRead(template);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
2021-11-30 16:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Collection<Tuple> takeAll(Tuple template) {
|
2021-12-02 20:57:01 +00:00
|
|
|
try {
|
|
|
|
return lindaServer.takeAll(template);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
2021-11-30 16:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Collection<Tuple> readAll(Tuple template) {
|
2021-12-02 20:57:01 +00:00
|
|
|
try {
|
|
|
|
return lindaServer.readAll(template);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
2021-11-30 16:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void eventRegister(eventMode mode, eventTiming timing, Tuple template, Callback callback) {
|
2021-12-02 20:57:01 +00:00
|
|
|
try {
|
|
|
|
lindaServer.eventRegister(mode, timing, template, callback);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2021-11-30 16:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void debug(String prefix) {
|
2021-12-02 20:57:01 +00:00
|
|
|
try {
|
|
|
|
lindaServer.debug(prefix);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2021-11-30 16:39:17 +00:00
|
|
|
}
|
2021-11-27 16:50:33 +00:00
|
|
|
}
|