1 package org.sapia.ubik.rmi.examples; 2 3 import org.sapia.ubik.rmi.naming.remote.*; 4 import org.sapia.ubik.rmi.server.Log; 5 6 import java.rmi.Naming ; 7 import java.rmi.RemoteException ; 8 9 import java.util.Properties ; 10 11 import javax.naming.*; 12 13 14 22 public class Bench { 23 public static void main(String [] args) { 24 Log.setWarning(); 26 27 try { 29 Foo f; 30 31 f = getJdkFoo(); 32 System.out.println("==== Producing numbers for Java RMI... ===="); 33 System.out.println(); 34 doGetBar(f); 35 System.out.println(); 36 doGetMsg(f); 37 38 System.out.println(); 39 f = getUbikFoo(); 40 System.out.println("==== Producing numbers for Ubik RMI... ===="); 41 System.out.println(); 42 doGetBar(f); 43 System.out.println(); 44 doGetMsg(f); 45 46 System.out.println("Press CTRL-C to exit"); 47 48 while (true) { 49 Thread.sleep(100000); 50 } 51 } catch (Throwable t) { 52 t.printStackTrace(); 53 } 54 } 55 56 private static Foo getJdkFoo() throws Throwable { 57 return (Foo) Naming.lookup("rmi://localhost:1098/Foo"); 58 } 59 60 private static Foo getUbikFoo() throws Throwable { 61 Properties props = new Properties (); 62 props.setProperty(InitialContext.PROVIDER_URL, "ubik://localhost:1099/"); 63 props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, 64 RemoteInitialContextFactory.class.getName()); 65 66 InitialContext ctx = new InitialContext(props); 67 68 return (Foo) ctx.lookup("Foo"); 69 } 70 71 private static void doGetBar(Foo f) throws RemoteException { 72 System.out.println("Calling getBar() on Foo (returns a remote Object)"); 73 74 for (int i = 0; i < 4; i++) { 75 long start = 0; 76 long total = 0; 77 long maxTime = 1000; 78 int callCount = 0; 79 80 System.out.println(); 81 System.out.println(">>run " + (i + 1)); 82 83 while (true) { 84 start = System.currentTimeMillis(); 85 f.getBar(); 86 total = total + (System.currentTimeMillis() - start); 87 callCount++; 88 89 if (total >= maxTime) { 90 break; 91 } 92 } 93 94 System.out.println("" + callCount + "/" + total + 95 " (number of calls/number of millis)"); 96 } 97 } 98 99 private static void doGetMsg(Foo f) throws RemoteException { 100 System.out.println("Calling getMsg() on Bar (getMsg() returns a string)"); 101 102 Bar b = f.getBar(); 103 104 for (int i = 0; i < 4; i++) { 105 long start = 0; 106 long total = 0; 107 long maxTime = 1000; 108 int callCount = 0; 109 110 System.out.println(); 111 System.out.println(">>run " + (i + 1)); 112 113 while (true) { 114 start = System.currentTimeMillis(); 115 b.getMsg(); 116 total = total + (System.currentTimeMillis() - start); 117 callCount++; 118 119 if (total >= maxTime) { 120 break; 121 } 122 } 123 124 System.out.println("" + callCount + "/" + total + 125 " (number of calls/number of millis)"); 126 } 127 } 128 } 129 | Popular Tags |