1 8 package org.codehaus.aspectwerkz.connectivity; 9 10 import java.util.Properties ; 11 import java.io.FileInputStream ; 12 import java.lang.reflect.Method ; 13 14 import org.codehaus.aspectwerkz.exception.WrappedRuntimeException; 15 import org.codehaus.aspectwerkz.util.ContextClassLoader; 16 17 22 public class RemoteProxyServerManager { 23 24 27 private static final boolean START_REMOTE_PROXY_SERVER = "true".equals( 28 java.lang.System.getProperty( 29 "aspectwerkz.remote.server.run", 30 "false" 31 ) 32 ); 33 34 37 private static final RemoteProxyServerManager INSTANCE = new RemoteProxyServerManager(); 38 39 42 private RemoteProxyServer m_remoteProxyServer = null; 43 44 49 public static RemoteProxyServerManager getInstance() { 50 return INSTANCE; 51 } 52 53 56 public void start() { 57 if (START_REMOTE_PROXY_SERVER) { 58 m_remoteProxyServer = new RemoteProxyServer(ContextClassLoader.getLoader(), getInvoker()); 59 m_remoteProxyServer.start(); 60 } 61 } 62 63 68 private Invoker getInvoker() { 69 Invoker invoker; 70 try { 71 Properties properties = new Properties (); 72 properties.load(new FileInputStream (java.lang.System.getProperty("aspectwerkz.resource.bundle"))); 73 String className = properties.getProperty("remote.server.invoker.classname"); 74 invoker = (Invoker) ContextClassLoader.forName(className).newInstance(); 75 } catch (Exception e) { 76 invoker = getDefaultInvoker(); 77 } 78 return invoker; 79 } 80 81 86 private Invoker getDefaultInvoker() { 87 return new Invoker() { 88 public Object invoke(final String handle, 89 final String methodName, 90 final Class [] paramTypes, 91 final Object [] args, 92 final Object context) { 93 Object result; 94 try { 95 final Object instance = RemoteProxy.getWrappedInstance(handle); 96 final Method method = instance.getClass().getMethod(methodName, paramTypes); 97 result = method.invoke(instance, args); 98 } catch (Exception e) { 99 throw new WrappedRuntimeException(e); 100 } 101 return result; 102 } 103 }; 104 } 105 106 109 private RemoteProxyServerManager() { 110 111 } 112 } 113 | Popular Tags |