1 package org.sapia.ubik.rmi.server; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 import org.sapia.taskman.TaskManager; 7 import org.sapia.ubik.net.ServerAddress; 8 import org.sapia.ubik.rmi.Consts; 9 import org.sapia.ubik.rmi.interceptor.Event; 10 import org.sapia.ubik.rmi.interceptor.Interceptor; 11 import org.sapia.ubik.rmi.interceptor.InvalidInterceptorException; 12 import org.sapia.ubik.rmi.interceptor.MultiDispatcher; 13 import org.sapia.ubik.rmi.server.gc.ClientGC; 14 import org.sapia.ubik.rmi.server.invocation.InvocationDispatcher; 15 16 17 28 public class ClientRuntime { 29 32 static final InvocationDispatcher invoker = new InvocationDispatcher(); 33 34 39 private static Map _serverAddresses = new HashMap (); 40 41 48 public final MultiDispatcher dispatcher = new MultiDispatcher(); 49 50 51 final ClientGC gc; 52 53 ClientRuntime(TaskManager taskman) { 54 gc = new ClientGC(taskman); 55 } 56 57 66 boolean isCallback(String transportType) { 67 if (_serverAddresses.get(transportType) == null) { 68 doInit(transportType); 69 } 70 71 return _serverAddresses.get(transportType) != null; 72 } 73 74 void shutdown(long timeout) throws InterruptedException { 75 } 77 78 87 public ServerAddress getCallbackAddress(String transportType) 88 throws IllegalStateException { 89 if (_serverAddresses.get(transportType) == null) { 90 throw new IllegalStateException ( 91 "no callback server was instantiated; make sure " + 92 "the following system property is set to 'true' upon VM startup: " + 93 Consts.CALLBACK_ENABLED); 94 } 95 96 return (ServerAddress) _serverAddresses.get(transportType); 97 } 98 99 105 public synchronized void addInterceptor(Class eventClass, Interceptor it) 106 throws InvalidInterceptorException { 107 dispatcher.addInterceptor(eventClass, it); 108 } 109 110 116 public void dispatchEvent(Event event) { 117 dispatcher.dispatch(event); 118 } 119 120 123 synchronized void doInit(String transportType) { 124 if ((System.getProperty(Consts.CALLBACK_ENABLED) != null) && 125 System.getProperty(Consts.CALLBACK_ENABLED).equalsIgnoreCase("true")) { 126 if (_serverAddresses.get(transportType) != null) { 127 return; 128 } 129 130 Log.warning(getClass(), 131 "Creating server to receive callbacks on transport: " + transportType); 132 133 ServerAddress serverAddress = null; 134 135 if (Hub.serverRuntime.server.isInit(transportType)) { 136 serverAddress = Hub.serverRuntime.server.getServerAddress(transportType); 137 } else { 138 try { 139 serverAddress = Hub.serverRuntime.server.init(transportType); 140 } catch (java.rmi.RemoteException e) { 141 Log.error(ClientRuntime.class, e); 142 } 143 } 144 145 _serverAddresses.put(transportType, serverAddress); 146 } 147 } 148 } 149 | Popular Tags |