package linda.server; import linda.Callback; import linda.Linda; import linda.Tuple; import linda.shm.CentralizedLinda; 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. */ public class LindaClient implements Linda { Linda lindaServer; public static void main(String[] args) { try { LindaServer ls = (LindaServer) Naming.lookup(args[0]); Tuple t1 = new Tuple(1, "a"); System.out.print("Tuple " + t1 + " envoyé"); ls.write(t1); System.out.print("Tuple " + t1 + " écrit"); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } Tuple template = new Tuple(Integer.class, String.class); System.out.print("Lecture " + template + " envoyé"); Tuple t2 = ls.read(template); System.out.print("Tuple " + t2 + " lu"); } catch (MalformedURLException | RemoteException | NotBoundException e) { e.printStackTrace(); } } /** * Initializes the Linda implementation. * * @param serverURI the URI of the server, e.g. * "rmi://localhost:4000/LindaServer" or * "//localhost:4000/LindaServer". */ public LindaClient(String serverURI) { 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); } 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 takeAll(Tuple template) { return lindaServer.takeAll(template); } public Collection 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); } }