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 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
|
|
|
|
|
|
|
Linda lindaServer;
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
2021-11-30 17:01:10 +00:00
|
|
|
LindaClient lc = new LindaClient(args[0]);
|
2021-11-30 16:39:17 +00:00
|
|
|
|
2021-11-30 17:01:10 +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-11-30 17:01:10 +00:00
|
|
|
try {
|
|
|
|
Thread.sleep(3000);
|
|
|
|
} catch (InterruptedException e) {
|
2021-11-30 16:39:17 +00:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2021-11-30 17:01:10 +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 {
|
|
|
|
this.lindaServer = (Linda) Naming.lookup(serverURI);
|
|
|
|
} catch (MalformedURLException | RemoteException | NotBoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void write(Tuple t) {
|
|
|
|
lindaServer.write(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Tuple take(Tuple template) {
|
|
|
|
return lindaServer.take(template);
|
2021-11-27 16:50:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 16:39:17 +00:00
|
|
|
public Tuple read(Tuple template) {
|
|
|
|
return lindaServer.read(template);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Tuple tryTake(Tuple template) {
|
|
|
|
return lindaServer.tryTake(template);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Tuple tryRead(Tuple template) {
|
|
|
|
return lindaServer.tryRead(template);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Collection<Tuple> takeAll(Tuple template) {
|
|
|
|
return lindaServer.takeAll(template);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Collection<Tuple> readAll(Tuple template) {
|
|
|
|
return lindaServer.readAll(template);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void eventRegister(eventMode mode, eventTiming timing, Tuple template, Callback callback) {
|
|
|
|
lindaServer.eventRegister(mode, timing, template, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void debug(String prefix) {
|
|
|
|
lindaServer.debug(prefix);
|
|
|
|
}
|
2021-11-27 16:50:33 +00:00
|
|
|
}
|