1 package org.sapia.ubik.rmi.replication; 2 3 import org.sapia.ubik.net.Connection; 4 import org.sapia.ubik.net.ServerAddress; 5 import org.sapia.ubik.rmi.server.transport.Connections; 6 import org.sapia.ubik.rmi.server.transport.TransportManager; 7 8 import java.io.IOException ; 9 10 import java.rmi.RemoteException ; 11 12 13 21 class SendHelper implements Runnable { 22 private Object _toSend; 23 private ServerAddress _addr; 24 private boolean _sync; 25 26 SendHelper(Object toSend, ServerAddress addr, boolean sync) { 27 _toSend = toSend; 28 _addr = addr; 29 _sync = sync; 30 } 31 32 35 public void run() { 36 try { 37 doSend(); 38 } catch (Throwable t) { 39 t.printStackTrace(); 40 } 41 } 42 43 Object send() throws Throwable { 44 if (_sync) { 45 return doSend(); 46 } 47 48 Thread t = new Thread (this); 49 t.setName("ubik.rmi.SendHelper"); 50 t.setDaemon(true); 51 t.start(); 52 53 return null; 54 } 55 56 private Object doSend() throws Throwable { 57 Connections conns = TransportManager.getConnectionsFor(_addr); 58 Connection conn = conns.acquire(); 59 Object toReturn; 60 61 try { 62 conn.send(_toSend); 63 toReturn = conn.receive(); 64 } catch (RemoteException e) { 65 conn.close(); 66 throw e; 67 } catch (IOException e) { 68 RemoteException re = new RemoteException ("Could not send replicated command", 69 e); 70 conn.close(); 71 throw re; 72 } catch (ClassNotFoundException e) { 73 RemoteException re = new RemoteException ("Could not receive response for replicated command", 74 e); 75 conn.close(); 76 throw re; 77 } 78 79 conns.release(conn); 80 81 return toReturn; 82 } 83 } 84 | Popular Tags |