1 package org.sapia.ubik.rmi.examples; 2 3 import org.sapia.ubik.net.Connection; 4 import org.sapia.ubik.net.TCPAddress; 5 import org.sapia.ubik.rmi.server.RMICommand; 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 public class HelloWorldCommand extends RMICommand { 22 25 public Object execute() throws Throwable { 26 return "Hello World"; 27 } 28 29 public static void main(String [] args) { 30 TCPAddress addr = new TCPAddress("localhost", 7070); 32 33 Connection conn = null; 34 35 try { 36 conn = TransportManager.getConnectionsFor(addr).acquire(); 38 } catch (RemoteException e) { 39 e.printStackTrace(); 40 System.exit(1); 41 } 42 43 try { 44 conn.send(new HelloWorldCommand()); 45 } catch (IOException e) { 46 e.printStackTrace(); 47 System.exit(1); 48 } 49 50 try { 52 Object response = conn.receive(); 53 54 if (response instanceof Throwable ) { 55 Throwable err = (Throwable ) response; 56 err.fillInStackTrace(); 57 err.printStackTrace(); 58 } else { 59 System.out.println(response); 61 } 62 63 TransportManager.getConnectionsFor(addr).release(conn); 67 } catch (RemoteException e) { 68 e.printStackTrace(); 69 System.exit(1); 70 } catch (IOException e) { 71 e.printStackTrace(); 72 System.exit(1); 73 } catch (ClassNotFoundException e) { 74 e.printStackTrace(); 75 System.exit(1); 76 } 77 } 78 } 79 | Popular Tags |