projet-donnees-reparties/linda/server/LindaClient.java

113 lines
2.8 KiB
Java
Raw Normal View History

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
LindaRemote lindaServer;
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 = (LindaRemote) Naming.lookup(serverURI);
2021-11-30 16:39:17 +00:00
} catch (MalformedURLException | RemoteException | NotBoundException e) {
e.printStackTrace();
}
}
public void write(Tuple t) {
try {
lindaServer.write(t);
} catch (RemoteException e) {
e.printStackTrace();
}
2021-11-30 16:39:17 +00:00
}
public Tuple take(Tuple template) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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
}