1 package org.sapia.ubik.rmi.server; 2 3 import org.sapia.taskman.TaskManager; 4 import org.sapia.ubik.rmi.Consts; 5 import org.sapia.ubik.rmi.interceptor.Event; 6 import org.sapia.ubik.rmi.interceptor.Interceptor; 7 import org.sapia.ubik.rmi.interceptor.InvalidInterceptorException; 8 import org.sapia.ubik.rmi.interceptor.MultiDispatcher; 9 import org.sapia.ubik.rmi.server.gc.ServerGC; 10 import org.sapia.ubik.rmi.server.invocation.RMICommandProcessor; 11 12 13 23 public class ServerRuntime { 24 static final int DEFAULT_MAX_CALLBACK_THREADS = 1; 25 26 31 public final ObjectTable objectTable = new ObjectTable(); 32 33 34 39 public final MultiDispatcher dispatcher = new MultiDispatcher(); 40 41 44 public final ServerGC gc; 45 46 51 public final RMICommandProcessor processor; 52 53 56 public final ServerTable server = new ServerTable(); 57 58 ServerRuntime(TaskManager taskman) { 59 int maxThreads = DEFAULT_MAX_CALLBACK_THREADS; 60 61 if (System.getProperty(Consts.SERVER_CALLBACK_MAX_THREADS) != null) { 62 try { 63 if ((System.getProperty(Consts.CALLBACK_ENABLED) != null) && 64 System.getProperty(Consts.CALLBACK_ENABLED).equalsIgnoreCase("true")) { 65 maxThreads = Integer.parseInt(System.getProperty( 66 Consts.SERVER_CALLBACK_MAX_THREADS)); 67 } else { 68 maxThreads = 1; 69 } 70 } catch (NumberFormatException e) { 71 Log.warning(ServerRuntime.class, 72 "invalid value for system property: " + 73 Consts.SERVER_CALLBACK_MAX_THREADS + "; using default: " + 74 maxThreads); 75 } 76 } 77 78 processor = new RMICommandProcessor(maxThreads); 79 gc = new ServerGC(taskman); 80 } 81 82 88 public synchronized void addInterceptor(Class eventClass, Interceptor it) 89 throws InvalidInterceptorException { 90 dispatcher.addInterceptor(eventClass, it); 91 } 92 93 98 public void dispatchEvent(Event event) { 99 dispatcher.dispatch(event); 100 } 101 102 105 void shutdown(long timeout) throws InterruptedException { 106 Log.warning(ServerRuntime.class, "Shutting down command processor"); 107 processor.shutdown(timeout); 108 Log.warning(ServerRuntime.class, "Shutting down server"); 109 server.close(); 110 } 111 } 112 | Popular Tags |