package linda.server; import linda.Callback; import linda.Linda; import linda.Tuple; 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 { LindaRemote lindaServer; public static void main(String[] args) { <<<<<<< HEAD ======= >>>>>>> 4a7bd702d3a89d65aa8cb02471b5d126846a9062 LindaClient lc = new LindaClient(args[0]); Tuple t1 = new Tuple(1, "a"); System.out.print("Tuple " + t1 + " envoyé"); lc.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 = lc.read(template); System.out.print("Tuple " + t2 + " lu"); } /** * 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 = (LindaRemote) Naming.lookup(serverURI); } catch (MalformedURLException | RemoteException | NotBoundException e) { e.printStackTrace(); } } public void write(Tuple t) { try { lindaServer.write(t); } catch (RemoteException e) { e.printStackTrace(); } } public Tuple take(Tuple template) { try { return lindaServer.take(template); } catch (RemoteException e) { e.printStackTrace(); return null; } } public Tuple read(Tuple template) { try { return lindaServer.read(template); } catch (RemoteException e) { e.printStackTrace(); return null; } } public Tuple tryTake(Tuple template) { try { return lindaServer.tryTake(template); } catch (RemoteException e) { e.printStackTrace(); return null; } } public Tuple tryRead(Tuple template) { try { return lindaServer.tryRead(template); } catch (RemoteException e) { e.printStackTrace(); return null; } } public Collection takeAll(Tuple template) { try { return lindaServer.takeAll(template); } catch (RemoteException e) { e.printStackTrace(); return null; } } public Collection readAll(Tuple template) { try { return lindaServer.readAll(template); } catch (RemoteException e) { e.printStackTrace(); return null; } } public void eventRegister(eventMode mode, eventTiming timing, Tuple template, Callback callback) { try { lindaServer.eventRegister(mode, timing, template, callback); } catch (RemoteException e) { e.printStackTrace(); } } public void debug(String prefix) { try { lindaServer.debug(prefix); } catch (RemoteException e) { e.printStackTrace(); } } }