hammant 2002/10/13 06:40:01 Modified: altrmi build.xml altrmi/src/java/org/apache/excalibur/altrmi/client/impl AbstractAltrmiFactory.java AbstractSameVmBindableHostContext.java altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket SocketCustomStreamHostContext.java SocketObjectStreamHostContext.java altrmi/src/java/org/apache/excalibur/altrmi/registry Registry.java altrmi/src/java/org/apache/excalibur/altrmi/server/impl/socket CompleteSocketCustomStreamServer.java PartialSocketCustomStreamServer.java PartialSocketObjectStreamServer.java Log: Client no longer directly references Registry. Can be in different classloader or absent. Revision Changes Path 1.41 +1 -0 jakarta-avalon-excalibur/altrmi/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/build.xml,v retrieving revision 1.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- build.xml 13 Oct 2002 11:54:24 -0000 1.40 +++ build.xml 13 Oct 2002 13:40:00 -0000 1.41 @@ -321,6 +321,7 @@ <include name="org/apache/excalibur/altrmi/common/*.java"/> <include name="org/apache/excalibur/altrmi/generator/*.java"/> <include name="org/apache/excalibur/altrmi/server/*.java"/> + <include name="org/apache/excalibur/altrmi/registry/**.java"/> <include name="org/apache/excalibur/altrmi/server/impl/*.java"/> <include name="org/apache/excalibur/altrmi/server/impl/adapters/*.java"/> <include name="org/apache/excalibur/altrmi/server/impl/callback/*.java"/> 1.10 +21 -13 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/AbstractAltrmiFactory.java Index: AbstractAltrmiFactory.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/AbstractAltrmiFactory.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- AbstractAltrmiFactory.java 13 Oct 2002 11:54:25 -0000 1.9 +++ AbstractAltrmiFactory.java 13 Oct 2002 13:40:00 -0000 1.10 @@ -120,15 +120,23 @@ AbstractSameVmBindableHostContext sameVmBindableHostContext = (AbstractSameVmBindableHostContext) m_hostContext; m_hostContext = sameVmBindableHostContext.makeSameVmHostContext(); - m_clientInvocationHandler = m_hostContext.getClientInvocationHandler(); - reply = m_clientInvocationHandler.handleInvocation(new OpenConnectionRequest() ); - + if (m_hostContext == null) + { + // Registry not found, or a different instance to the one + // the server placed its piped instance in. + // revert to non optimized. + m_clientInvocationHandler.handleInvocation(new OpenConnectionRequest( null ) ); + } + else + { + m_clientInvocationHandler = m_hostContext.getClientInvocationHandler(); + reply = m_clientInvocationHandler.handleInvocation(new OpenConnectionRequest() ); + } } else { throw new IOException("SameVM instruction for non rebindable host context."); } - } if( reply instanceof OpenConnectionReply ) @@ -352,8 +360,8 @@ }; } } - - + + /** * Wraps the reference to the remote obj within the FacadeRefHolder obj. * @param obj @@ -367,10 +375,10 @@ return new FacadeRefHolder( refID, objectName ); } - - - + + + public void marshallCorrection( String methodSignature, Object[] args, Class[] argClasses ) { @@ -383,13 +391,13 @@ if(args[i] instanceof AltrmiProxy) { AltrmiProxy proxy = (AltrmiProxy)args[i]; - + if( getReferenceID( proxy ) != null ) { //The stripping "AltrmiGenerated2" from the proxy names generated by //ProxyGenerator's:- "AltrmiGenerated2".length()=16 String objName = args[i].getClass().getName().substring( 16 ); - + args[i]= makeFacadeRefHolder( proxy, objName ); } } @@ -399,5 +407,5 @@ } } } - + } 1.2 +18 -0 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/AbstractSameVmBindableHostContext.java Index: AbstractSameVmBindableHostContext.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/AbstractSameVmBindableHostContext.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractSameVmBindableHostContext.java 13 Oct 2002 11:54:25 -0000 1.1 +++ AbstractSameVmBindableHostContext.java 13 Oct 2002 13:40:00 -0000 1.2 @@ -11,6 +11,7 @@ import org.apache.excalibur.altrmi.client.AltrmiClientInvocationHandler; import java.io.IOException; +import java.lang.reflect.Method; public abstract class AbstractSameVmBindableHostContext extends AbstractHostContext{ @@ -26,5 +27,22 @@ * @throws IOException if a problem */ public abstract AbstractHostContext makeSameVmHostContext() throws IOException; + + + protected Object getOptmization(String uniqueID) + { + try + { + Object registry = this.getClass().getClassLoader() + .loadClass("org.apache.excalibur.altrmi.registry.Registry").newInstance(); + //Binder binder = registry.get("/.altrmi/optimizations/" + uniqueID); + Method method = registry.getClass().getMethod("get", new Class[] {String.class}); + return method.invoke(registry, new Object[] {"/.altrmi/optimizations/" + uniqueID}); + } + catch (Exception e) + { + return null; + } + } } 1.4 +29 -11 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketCustomStreamHostContext.java Index: SocketCustomStreamHostContext.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketCustomStreamHostContext.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SocketCustomStreamHostContext.java 13 Oct 2002 11:54:26 -0000 1.3 +++ SocketCustomStreamHostContext.java 13 Oct 2002 13:40:00 -0000 1.4 @@ -11,14 +11,11 @@ import org.apache.excalibur.altrmi.client.impl.AbstractSameVmBindableHostContext; import org.apache.excalibur.altrmi.client.impl.AbstractHostContext; import org.apache.excalibur.altrmi.common.AltrmiConnectionException; -import org.apache.excalibur.altrmi.registry.Registry; -import org.apache.excalibur.altrmi.registry.Bound; -import org.apache.excalibur.altrmi.registry.Binder; -import org.apache.excalibur.altrmi.registry.BindException; import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.io.IOException; +import java.lang.reflect.Method; /** * Class SocketCustomStreamHostContext @@ -80,21 +77,42 @@ PipedOutputStream out = new PipedOutputStream(); try { - Registry registry = Registry.getInstance(); - Binder binder = registry.get("/.altrmi/optimizations/port=" + m_port); - Bound bound = binder.bind(new Object[] {in, out}); + Object binder = getOptmization("port=" + m_port); + if (binder == null) + { + return null; + } + Object bound = bind(binder, in, out); + if (bound == null) + { + return null; + } PipedCustomStreamHostContext pipedCustomStreamHostContext = new PipedCustomStreamHostContext(in, out); pipedCustomStreamHostContext.initialize(); return pipedCustomStreamHostContext; } - catch (BindException e) + catch (Exception e) { throw new IOException("Naming exception during bind :" + e.getMessage()); } - catch (AltrmiConnectionException e) + } + + private Object bind(Object object, PipedInputStream inputStream, + PipedOutputStream outputStream) + { + + try { - throw new IOException("Connection exception during bind :" + e.getMessage()); + Object[] parms = new Object[]{ inputStream, outputStream }; + Method method = object.getClass().getMethod("bind", new Class[] { parms.getClass() }); + return method.invoke(object, new Object[] { parms }); + } + catch (Exception e) + { + return null; } } + + } 1.4 +33 -15 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketObjectStreamHostContext.java Index: SocketObjectStreamHostContext.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketObjectStreamHostContext.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SocketObjectStreamHostContext.java 13 Oct 2002 11:54:26 -0000 1.3 +++ SocketObjectStreamHostContext.java 13 Oct 2002 13:40:00 -0000 1.4 @@ -8,16 +8,14 @@ package org.apache.excalibur.altrmi.client.impl.socket; import org.apache.excalibur.altrmi.client.impl.AbstractHostContext; +import org.apache.excalibur.altrmi.client.impl.AbstractSameVmBindableHostContext; import org.apache.excalibur.altrmi.client.impl.piped.PipedObjectStreamHostContext; import org.apache.excalibur.altrmi.common.AltrmiConnectionException; -import org.apache.excalibur.altrmi.registry.Registry; -import org.apache.excalibur.altrmi.registry.Binder; -import org.apache.excalibur.altrmi.registry.Bound; -import org.apache.excalibur.altrmi.registry.BindException; import java.io.PipedInputStream; import java.io.IOException; import java.io.PipedOutputStream; +import java.lang.reflect.Method; /** * Class SocketObjectStreamHostContext @@ -26,7 +24,7 @@ * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * @version $Revision$ */ -public class SocketObjectStreamHostContext extends AbstractHostContext +public class SocketObjectStreamHostContext extends AbstractSameVmBindableHostContext { private String mObjectOutputStreamClassName; @@ -127,22 +125,42 @@ PipedOutputStream out = new PipedOutputStream(); try { - Registry registry = Registry.getInstance(); - Binder binder = registry.get("/.altrmi/optimizations/port=" + m_port); - Bound bound = binder.bind(new Object[] {in, out}); - PipedObjectStreamHostContext pipedObjectStreamHostContext + Object binder = getOptmization("port=" + m_port); + if (binder == null) + { + return null; + } + Object bound = bind(binder, in, out); + if (bound == null) + { + return null; + } + PipedObjectStreamHostContext pipedCustomStreamHostContext = new PipedObjectStreamHostContext(in, out); - pipedObjectStreamHostContext.initialize(); - return pipedObjectStreamHostContext; + pipedCustomStreamHostContext.initialize(); + return pipedCustomStreamHostContext; } - catch (BindException e) + catch (Exception e) { throw new IOException("Naming exception during bind :" + e.getMessage()); } - catch (AltrmiConnectionException e) + } + + private Object bind(Object object, PipedInputStream inputStream, + PipedOutputStream outputStream) + { + + try + { + Object[] parms = new Object[]{ inputStream, outputStream }; + Method method = object.getClass().getMethod("bind", new Class[] { parms.getClass() }); + return method.invoke(object, new Object[] { parms }); + } + catch (Exception e) { - throw new IOException("Connection exception during bind :" + e.getMessage()); + return null; } } + } 1.2 +7 -25 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/registry/Registry.java Index: Registry.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/registry/Registry.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Registry.java 13 Oct 2002 12:03:39 -0000 1.1 +++ Registry.java 13 Oct 2002 13:40:00 -0000 1.2 @@ -16,29 +16,7 @@ public class Registry { - private static Registry INSTANCE; - - private HashMap m_map = new HashMap(); - - /** - * Get the singleton instance - * @return the instance - */ - public static synchronized Registry getInstance() - { - if (INSTANCE == null) - { - INSTANCE = new Registry(); - } - return INSTANCE; - } - - /** - * Prevent public construction - */ - private Registry() - { - } + private static HashMap m_map = new HashMap(); /** * Get a Bound object. @@ -47,7 +25,9 @@ */ public Binder get(String key) { - return (Binder) m_map.get(key); + synchronized (m_map) { + return (Binder) m_map.get(key); + } } /** @@ -57,7 +37,9 @@ */ public void put (String key, Object object) { - m_map.put(key, object); + synchronized (m_map) { + m_map.put(key, object); + } } } 1.5 +3 -3 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/socket/CompleteSocketCustomStreamServer.java Index: CompleteSocketCustomStreamServer.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/socket/CompleteSocketCustomStreamServer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CompleteSocketCustomStreamServer.java 13 Oct 2002 11:54:27 -0000 1.4 +++ CompleteSocketCustomStreamServer.java 13 Oct 2002 13:40:00 -0000 1.5 @@ -36,7 +36,7 @@ public CompleteSocketCustomStreamServer( int port ) throws AltrmiServerException { super( port ); - Registry.getInstance().put("/.altrmi/optimizations/port=" + port, + new Registry().put("/.altrmi/optimizations/port=" + port, new CompleteSocketCustomStreamPipedBinder(super.getInovcationHandlerAdapter())); } @@ -54,7 +54,7 @@ throws AltrmiServerException { super( invocationHandlerAdapter, port ); - Registry.getInstance().put("/.altrmi/optimizations/port=" + port, + new Registry().put("/.altrmi/optimizations/port=" + port, new CompleteSocketCustomStreamPipedBinder(invocationHandlerAdapter)); } 1.6 +2 -2 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/socket/PartialSocketCustomStreamServer.java Index: PartialSocketCustomStreamServer.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/socket/PartialSocketCustomStreamServer.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- PartialSocketCustomStreamServer.java 13 Oct 2002 11:54:27 -0000 1.5 +++ PartialSocketCustomStreamServer.java 13 Oct 2002 13:40:00 -0000 1.6 @@ -36,7 +36,7 @@ m_completeSocketCustomStreamPipedBinder = new CompleteSocketCustomStreamPipedBinder(super.getInovcationHandlerAdapter()); - Registry.getInstance().put("/.altrmi/optimizations/port=" + new Registry().put("/.altrmi/optimizations/port=" + port, m_completeSocketCustomStreamPipedBinder); } 1.6 +2 -2 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/socket/PartialSocketObjectStreamServer.java Index: PartialSocketObjectStreamServer.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/socket/PartialSocketObjectStreamServer.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- PartialSocketObjectStreamServer.java 13 Oct 2002 11:54:27 -0000 1.5 +++ PartialSocketObjectStreamServer.java 13 Oct 2002 13:40:00 -0000 1.6 @@ -37,7 +37,7 @@ { m_completeSocketObjectStreamPipedBinder = new CompleteSocketObjectStreamPipedBinder(super.getInovcationHandlerAdapter()); - Registry.getInstance().put("/.altrmi/optimizations/port=" + new Registry().put("/.altrmi/optimizations/port=" + port, m_completeSocketObjectStreamPipedBinder); }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>