1 package org.sapia.ubik.rmi.examples; 2 3 import org.sapia.ubik.rmi.Consts; 4 import org.sapia.ubik.rmi.naming.remote.RemoteInitialContextFactory; 5 import org.sapia.ubik.rmi.server.Hub; 6 7 import java.util.Properties ; 8 9 import javax.naming.InitialContext ; 10 11 12 21 public class PrimitiveClient { 22 public static void main(String [] args) { 23 try { 24 Properties props = new Properties (); 25 26 System.setProperty(Consts.MARSHALLING, "true"); 28 29 props.setProperty(InitialContext.PROVIDER_URL, "ubik://localhost:1099"); 30 props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, 31 RemoteInitialContextFactory.class.getName()); 32 33 InitialContext ctx = new InitialContext (props); 34 Object lookedUp = ctx.lookup("PrimitiveService"); 35 System.out.println(lookedUp.getClass().getName()); 36 37 PrimitiveService svc = (PrimitiveService) lookedUp; 38 39 svc.getBoolean(); 40 svc.getByte(); 41 svc.getChar(); 42 svc.getShort(); 43 svc.getInt(); 44 svc.getLong(); 45 svc.getFloat(); 46 svc.getDouble(); 47 48 svc.setBoolean(true); 49 svc.setByte((byte) 0); 50 svc.setChar('c'); 51 svc.setShort((short) 0); 52 svc.setInt(0); 53 svc.setLong(0); 54 svc.setFloat(0); 55 svc.setDouble(0); 56 57 byte[] b = "Hello World".getBytes(); 58 59 for (int i = 0; i < b.length; i++) { 60 System.out.print(b[i]); 61 } 62 63 svc.setBytes(b); 64 65 Hub.shutdown(30000); 66 } catch (Exception e) { 67 e.printStackTrace(); 68 } 69 } 70 } 71 | Popular Tags |