1 4 package com.tc.aspectwerkz.connectivity; 5 6 7 import com.tc.aspectwerkz.exception.WrappedRuntimeException; 8 import com.tc.aspectwerkz.util.ContextClassLoader; 9 10 import java.io.FileInputStream ; 11 import java.lang.reflect.Method ; 12 import java.util.Properties ; 13 14 19 public class RemoteProxyServerManager { 20 21 24 private static final boolean START_REMOTE_PROXY_SERVER = "true".equals( 25 java.lang.System.getProperty( 26 "aspectwerkz.remote.server.run", 27 "false" 28 ) 29 ); 30 31 34 private static final RemoteProxyServerManager INSTANCE = new RemoteProxyServerManager(); 35 36 39 private RemoteProxyServer m_remoteProxyServer = null; 40 41 46 public static RemoteProxyServerManager getInstance() { 47 return INSTANCE; 48 } 49 50 53 public void start() { 54 if (START_REMOTE_PROXY_SERVER) { 55 m_remoteProxyServer = new RemoteProxyServer(ContextClassLoader.getLoader(), getInvoker()); 56 m_remoteProxyServer.start(); 57 } 58 } 59 60 65 private Invoker getInvoker() { 66 Invoker invoker; 67 try { 68 Properties properties = new Properties (); 69 properties.load(new FileInputStream (java.lang.System.getProperty("aspectwerkz.resource.bundle"))); 70 String className = properties.getProperty("remote.server.invoker.classname"); 71 invoker = (Invoker) ContextClassLoader.forName(className).newInstance(); 72 } catch (Exception e) { 73 invoker = getDefaultInvoker(); 74 } 75 return invoker; 76 } 77 78 83 private Invoker getDefaultInvoker() { 84 return new Invoker() { 85 public Object invoke(final String handle, 86 final String methodName, 87 final Class [] paramTypes, 88 final Object [] args, 89 final Object context) { 90 Object result; 91 try { 92 final Object instance = RemoteProxy.getWrappedInstance(handle); 93 final Method method = instance.getClass().getMethod(methodName, paramTypes); 94 result = method.invoke(instance, args); 95 } catch (Exception e) { 96 throw new WrappedRuntimeException(e); 97 } 98 return result; 99 } 100 }; 101 } 102 103 106 private RemoteProxyServerManager() { 107 108 } 109 } 110 | Popular Tags |