You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ch...@apache.org on 2003/11/19 12:15:03 UTC
cvs commit: incubator-geronimo/modules/remoting/src/test/org/apache/geronimo/remoting JMXRemotingTestMain.java RemotingInterceptorsTest.java
chirino 2003/11/19 03:15:03
Modified: modules/remoting/src/java/org/apache/geronimo/remoting
DeMarshalingInterceptor.java
IntraVMRoutingInterceptor.java
MarshalingInterceptor.java
modules/remoting/src/java/org/apache/geronimo/remoting/jmx
NotificationRemoterInterceptor.java
RemoteMBeanServerFactory.java
modules/remoting/src/java/org/apache/geronimo/remoting/router
AbstractInterceptorRouter.java
AbstractRouterRouter.java JMXRouter.java
modules/remoting/src/java/org/apache/geronimo/remoting/transport
BytesMarshalledObject.java
RemoteTransportInterceptor.java
TransportFactory.java
modules/remoting/src/java/org/apache/geronimo/remoting/transport/async
AsyncClient.java Registry.java
TransportFactory.java
modules/remoting/src/test/org/apache/geronimo/remoting
JMXRemotingTestMain.java
RemotingInterceptorsTest.java
Added: modules/remoting/src/java/org/apache/geronimo/remoting
TransportContext.java
Removed: modules/remoting/src/java/org/apache/geronimo/remoting/router
SimpleInterceptorRegistryRouter.java
Log:
The remoting layer now supports remoting any object the implements the Remote interface. So now you can create listners that can receive remote jmx notifications.
Revision Changes Path
1.2 +14 -7 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/DeMarshalingInterceptor.java
Index: DeMarshalingInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/DeMarshalingInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DeMarshalingInterceptor.java 16 Nov 2003 05:27:27 -0000 1.1
+++ DeMarshalingInterceptor.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -98,18 +98,25 @@
Thread currentThread = Thread.currentThread();
ClassLoader orig = currentThread.getContextClassLoader();
try {
- currentThread.setContextClassLoader(classloader);
-
- MarshalledObject mo = InvocationSupport.getMarshaledValue(invocation);
- Invocation marshalledInvocation = (Invocation) mo.get();
+ Invocation marshalledInvocation;
+
+ MarshalledObject mo = InvocationSupport.getMarshaledValue(invocation);;
+ try {
+ currentThread.setContextClassLoader(classloader);
+ marshalledInvocation = (Invocation) mo.get();
+ } catch (Throwable e) {
+ // Could not deserialize the invocation...
+ mo.set(new ThrowableWrapper(e));
+ return new SimpleInvocationResult(false, mo);
+ }
try {
InvocationResult rc = getNext().invoke(marshalledInvocation);
mo.set(rc.getResult());
- return new SimpleInvocationResult(mo);
+ return new SimpleInvocationResult(true, mo);
} catch (Throwable e) {
mo.set(new ThrowableWrapper(e));
- return new SimpleInvocationResult(mo);
+ return new SimpleInvocationResult(true, mo);
}
} finally {
1.2 +6 -1 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/IntraVMRoutingInterceptor.java
Index: IntraVMRoutingInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/IntraVMRoutingInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- IntraVMRoutingInterceptor.java 16 Nov 2003 05:27:27 -0000 1.1
+++ IntraVMRoutingInterceptor.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -97,6 +97,11 @@
// app is in.
DeMarshalingInterceptor deMarshalingInterceptor =
(DeMarshalingInterceptor) InterceptorRegistry.instance.lookup(deMarshalingInterceptorID);
+
+ if( deMarshalingInterceptor==null ) {
+ // Forget it.. we will not be able to route locally.
+ return;
+ }
ClassLoader parent = deMarshalingInterceptor.getClassloader();
ClassLoader child = Thread.currentThread().getContextClassLoader();
1.2 +33 -18 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/MarshalingInterceptor.java
Index: MarshalingInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/MarshalingInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MarshalingInterceptor.java 16 Nov 2003 05:27:27 -0000 1.1
+++ MarshalingInterceptor.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -72,24 +72,39 @@
* @see org.apache.geronimo.core.service.AbstractInterceptor#invoke(org.apache.geronimo.core.service.Invocation)
*/
public InvocationResult invoke(Invocation invocation) throws Throwable {
- // Marshall the invocation and store it.
- MarshalledObject mo = next.createMarshalledObject();
- mo.set(invocation);
- InvocationSupport.putMarshaledValue(invocation, mo);
- InvocationResult rc = next.invoke(invocation);
+ ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
+ try {
+
+ // Marshall the invocation and store it.
+ MarshalledObject mo = next.createMarshalledObject();
+ mo.set(invocation);
+ InvocationSupport.putMarshaledValue(invocation, mo);
- // Demarshal the result.
- mo = (MarshalledObject) rc.getResult();
- Object result = mo.get();
+ InvocationResult rc = next.invoke(invocation);
- // Are we demarshalling a thrown exception.
- if (result instanceof DeMarshalingInterceptor.ThrowableWrapper) {
- throw ((DeMarshalingInterceptor.ThrowableWrapper) result).exception;
- }
+ // Demarshal the result.
+ mo = (MarshalledObject) rc.getResult();
+ Object result;
+ try {
+
+ result = mo.get();
- return new SimpleInvocationResult(result);
+ } catch ( ClassNotFoundException e ) {
+ // Weird.
+ Thread.currentThread().setContextClassLoader(MarshalingInterceptor.class.getClassLoader());
+ result = mo.get();
+ }
+ // Are we demarshalling a thrown exception.
+ if (result instanceof DeMarshalingInterceptor.ThrowableWrapper) {
+ throw ((DeMarshalingInterceptor.ThrowableWrapper) result).exception;
+ }
+ return new SimpleInvocationResult(true, result);
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalLoader);
+ }
}
/**
1.1 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/TransportContext.java
Index: TransportContext.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.remoting;
import java.io.IOException;
/**
* @version $Revision: 1.1 $ $Date: 2003/11/19 11:15:03 $
*/
abstract public class TransportContext {
private static final ThreadLocal context = new ThreadLocal();
public static final TransportContext getTransportContext() {
return (TransportContext) context.get();
}
public static final void setTransportContext(TransportContext c) {
context.set(c);
}
public abstract Object writeReplace(Object proxy) throws IOException;
}
1.2 +17 -36 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/jmx/NotificationRemoterInterceptor.java
Index: NotificationRemoterInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/jmx/NotificationRemoterInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NotificationRemoterInterceptor.java 16 Nov 2003 05:27:27 -0000 1.1
+++ NotificationRemoterInterceptor.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -56,7 +56,6 @@
package org.apache.geronimo.remoting.jmx;
import java.lang.reflect.Method;
-import java.util.HashMap;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
@@ -66,66 +65,48 @@
import org.apache.geronimo.core.service.Invocation;
import org.apache.geronimo.core.service.InvocationResult;
import org.apache.geronimo.proxy.ProxyInvocation;
+import org.apache.geronimo.remoting.transport.TransportFactory;
/**
* @version $Revision$ $Date$
*/
public class NotificationRemoterInterceptor extends AbstractInterceptor {
-
- HashMap exportedListners = new HashMap();
-
/**
* @see org.apache.geronimo.core.service.AbstractInterceptor#invoke(org.apache.geronimo.core.service.Invocation)
*/
public InvocationResult invoke(Invocation invocation) throws Throwable {
Method method = ProxyInvocation.getMethod(invocation);
Object[] args = ProxyInvocation.getArguments(invocation);
-
- if ( method.getName().equals("addNotificationListener") && isEquals(method.getParameterTypes(), new Class[]{ObjectName.class, NotificationListener.class, NotificationFilter.class, Object.class}) ) {
- //public void addNotificationListener(ObjectName arg0, NotificationListener arg1, NotificationFilter arg2, Object arg3)
- NotificationListener local = (NotificationListener) args[1];
- NotificationListener proxy = getRemoteProxyOf( local );
-
- // Switch the object for a remotabable version.
- args[1] = proxy;
- try {
- return getNext().invoke(invocation);
- } finally {
- // Undo the switch..
- args[1] = local;
- }
-
-
- } else if ( method.getName().equals("removeNotificationListener") && isEquals(method.getParameterTypes(), new Class[]{ObjectName.class, NotificationListener.class}) ) {
+
+ if (
+ method.getName().equals("removeNotificationListener")
+ && isEquals(method.getParameterTypes(), new Class[] { ObjectName.class, NotificationListener.class })) {
//public void removeNotificationListener(ObjectName arg0, NotificationListener arg1)
-
- } else if (method.equals("removeNotificationListener") && isEquals(method.getParameterTypes(), new Class[]{ObjectName.class, NotificationListener.class, NotificationFilter.class, Object.class})) {
+ NotificationListener nl = (NotificationListener) args[1];
+ TransportFactory.unexport(nl);
+ } else if (
+ method.equals("removeNotificationListener")
+ && isEquals(
+ method.getParameterTypes(),
+ new Class[] { ObjectName.class, NotificationListener.class, NotificationFilter.class, Object.class })) {
//public void removeNotificationListener(ObjectName arg0, NotificationListener arg1, NotificationFilter arg2, Object arg3)
-
+ NotificationListener nl = (NotificationListener) args[1];
+ TransportFactory.unexport(nl);
}
return getNext().invoke(invocation);
}
/**
- * @param local
- * @return
- */
- private NotificationListener getRemoteProxyOf(NotificationListener local) {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
* @param classes
* @param classes2
* @return
*/
private boolean isEquals(Class[] classes, Class[] classes2) {
- if( classes.length != classes2.length)
+ if (classes.length != classes2.length)
return false;
for (int i = 0; i < classes.length; i++) {
- if( !classes[i].equals(classes2[i]) )
+ if (!classes[i].equals(classes2[i]))
return false;
}
return true;
1.2 +3 -1 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/jmx/RemoteMBeanServerFactory.java
Index: RemoteMBeanServerFactory.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/jmx/RemoteMBeanServerFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RemoteMBeanServerFactory.java 16 Nov 2003 05:27:27 -0000 1.1
+++ RemoteMBeanServerFactory.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -93,4 +93,6 @@
protected MBeanServer factoryCreate(String hostname) {
return RemoteMBeanServerFactory.create(hostname);
}
+
+
}
1.2 +3 -2 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/router/AbstractInterceptorRouter.java
Index: AbstractInterceptorRouter.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/router/AbstractInterceptorRouter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractInterceptorRouter.java 16 Nov 2003 05:27:27 -0000 1.1
+++ AbstractInterceptorRouter.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -131,7 +131,8 @@
InvocationResult result = interceptor.invoke(invocation);
msg = msg.createMsg();
- msg.pushMarshaledObject((MarshalledObject) result.getResult());
+ Object rc = result.getResult();
+ msg.pushMarshaledObject((MarshalledObject)rc);
return msg;
} catch (Throwable e) {
1.2 +1 -6 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/router/AbstractRouterRouter.java
Index: AbstractRouterRouter.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/router/AbstractRouterRouter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractRouterRouter.java 16 Nov 2003 05:27:27 -0000 1.1
+++ AbstractRouterRouter.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -81,8 +81,6 @@
*/
private Sync routerLock = createNewRouterLock();
- public GeronimoMBeanContext geronimoMBeanContext;
-
/**
*
* @jmx:managed-attribute
@@ -119,8 +117,6 @@
public Msg sendRequest(URI to, Msg msg) throws TransportException {
try {
routerLock.acquire();
-
- routerLock.acquire();
Router next = lookupRouterFrom(to);
if( next == null )
throw new TransportException("No route is available to: "+to);
@@ -157,7 +153,6 @@
* @see org.apache.geronimo.kernel.service.GeronimoMBeanTarget#setMBeanContext(org.apache.geronimo.kernel.service.GeronimoMBeanContext)
*/
public void setMBeanContext(GeronimoMBeanContext context) {
- this.geronimoMBeanContext = context;
}
/**
1.3 +6 -1 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/router/JMXRouter.java
Index: JMXRouter.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/router/JMXRouter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JMXRouter.java 16 Nov 2003 06:36:03 -0000 1.2
+++ JMXRouter.java 19 Nov 2003 11:15:03 -0000 1.3
@@ -66,6 +66,11 @@
/**
* Uses JMX Object names to route the request to a JMX object that implements the
* JMXTargetMBean interface.
+ *
+ * This allows you to route invocations to MBeans using URIs like:
+ * async://localhost:3434/JMX#geronimo.jmx:target=MBeanServerStub
+ *
+ * The MBean that will receive invocations must implement the JMXTarget interface.
*
* @version $Revision$ $Date$
*/
1.2 +34 -4 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/BytesMarshalledObject.java
Index: BytesMarshalledObject.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/BytesMarshalledObject.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BytesMarshalledObject.java 16 Nov 2003 05:27:27 -0000 1.1
+++ BytesMarshalledObject.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -70,6 +70,7 @@
import org.apache.geronimo.common.Classes;
import org.apache.geronimo.remoting.MarshalledObject;
+import org.apache.geronimo.remoting.TransportContext;
/**
* @version $Revision$ $Date$
@@ -112,18 +113,35 @@
static class ObjectOutputStreamExt extends ObjectOutputStream {
+ private TransportContext transportContext;
+
/**
* @param out
* @throws IOException
*/
- public ObjectOutputStreamExt(OutputStream out) throws IOException {
+ public ObjectOutputStreamExt(OutputStream out, TransportContext transportContext) throws IOException {
super(out);
- // TODO Auto-generated constructor stub
+ this.transportContext = transportContext;
+ enableReplaceObject(transportContext!=null);
}
+ /**
+ * @see java.io.ObjectOutputStream#replaceObject(java.lang.Object)
+ */
+ protected Object replaceObject(Object obj) throws IOException {
+ return transportContext.writeReplace(obj);
+ }
+
+ }
+
+ static class NullTransportContext extends TransportContext {
+ public Object writeReplace(Object proxy) throws IOException {
+ return proxy;
+ }
}
private byte data[];
+ private TransportContext transportContext;
public BytesMarshalledObject() {
}
@@ -132,15 +150,27 @@
set(value);
}
+ public BytesMarshalledObject(TransportContext transportContext) {
+ this.transportContext = transportContext;
+ }
+
+ public BytesMarshalledObject(TransportContext transportContext, Object value) throws IOException {
+ this.transportContext = transportContext;
+ set(value);
+ }
+
/**
* @see org.apache.geronimo.remoting.MarshalledObject#set(java.lang.Object)
*/
public void set(Object value) throws IOException {
+ // Set the transport context so that objects can write replace them selfs by
+ // delegating to the TranportContext to create remote proxies.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStreamExt os = new ObjectOutputStreamExt(baos);
+ ObjectOutputStreamExt os = new ObjectOutputStreamExt(baos, transportContext);
os.writeObject(value);
os.close();
data = baos.toByteArray();
+
}
public byte[] getBytes() {
1.2 +3 -3 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/RemoteTransportInterceptor.java
Index: RemoteTransportInterceptor.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/RemoteTransportInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RemoteTransportInterceptor.java 16 Nov 2003 05:27:27 -0000 1.1
+++ RemoteTransportInterceptor.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -102,12 +102,12 @@
msg.pushMarshaledObject(mo);
if (type == InvocationType.REQUEST) {
msg = transportClient.sendRequest(remoteURI, msg);
- return new SimpleInvocationResult(msg.popMarshaledObject());
+ return new SimpleInvocationResult(true, msg.popMarshaledObject());
} else {
transportClient.sendDatagram(remoteURI, msg);
MarshalledObject rcmo = transportClient.createMarshalledObject();
rcmo.set(null);
- return new SimpleInvocationResult(rcmo);
+ return new SimpleInvocationResult(true, rcmo);
}
}
1.2 +13 -1 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/TransportFactory.java
Index: TransportFactory.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/TransportFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TransportFactory.java 16 Nov 2003 05:27:27 -0000 1.1
+++ TransportFactory.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -100,6 +100,17 @@
}
+ public static boolean unexport(Object object) {
+ boolean wasExported = false;
+ Iterator iterator = factories.iterator();
+ while (iterator.hasNext()) {
+ TransportFactory i = (TransportFactory) iterator.next();
+ if( i.doUnexport(object) )
+ wasExported = true;
+ }
+ return wasExported;
+ }
+
static public void addFactory(TransportFactory tf) {
factories.add(tf);
}
@@ -111,5 +122,6 @@
abstract protected boolean handles(URI uri);
abstract public TransportClient createClient();
abstract public TransportServer createSever();
+ abstract public boolean doUnexport(Object object);
}
1.2 +12 -2 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/async/AsyncClient.java
Index: AsyncClient.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/async/AsyncClient.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AsyncClient.java 16 Nov 2003 05:27:27 -0000 1.1
+++ AsyncClient.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -56,11 +56,14 @@
*/
package org.apache.geronimo.remoting.transport.async;
+import java.io.IOException;
import java.net.URI;
+import java.rmi.Remote;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.remoting.MarshalledObject;
+import org.apache.geronimo.remoting.TransportContext;
import org.apache.geronimo.remoting.transport.BytesMarshalledObject;
import org.apache.geronimo.remoting.transport.Msg;
import org.apache.geronimo.remoting.transport.TransportClient;
@@ -113,7 +116,14 @@
* @see org.apache.geronimo.remoting.transport.TransportClient#createMarshalledObject()
*/
public MarshalledObject createMarshalledObject() {
- return new BytesMarshalledObject();
+ return new BytesMarshalledObject(new TransportContext() {
+ public Object writeReplace(Object proxy) throws IOException {
+ if (proxy instanceof Remote) {
+ return Registry.instance.exportObject(proxy);
+ }
+ return proxy;
+ }
+ });
}
}
1.2 +107 -5 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/async/Registry.java
Index: Registry.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/async/Registry.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Registry.java 16 Nov 2003 05:27:33 -0000 1.1
+++ Registry.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -56,10 +56,23 @@
*/
package org.apache.geronimo.remoting.transport.async;
+import java.io.IOException;
import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.proxy.ProxyContainer;
+import org.apache.geronimo.proxy.ReflexiveInterceptor;
+import org.apache.geronimo.remoting.DeMarshalingInterceptor;
+import org.apache.geronimo.remoting.InterVMRoutingInterceptor;
+import org.apache.geronimo.remoting.InterceptorRegistry;
+import org.apache.geronimo.remoting.IntraVMRoutingInterceptor;
+import org.apache.geronimo.remoting.router.InterceptorRegistryRouter;
+import org.apache.geronimo.remoting.router.SubsystemRouter;
+import org.apache.geronimo.remoting.transport.RemoteTransportInterceptor;
+import org.apache.geronimo.remoting.transport.URISupport;
import EDU.oswego.cs.dl.util.concurrent.ClockDaemon;
import EDU.oswego.cs.dl.util.concurrent.Executor;
@@ -76,7 +89,8 @@
/** The amount of time that must pass before a request is considered timedout. */
static public final long REQUEST_TIMEOUT =
- Long.parseLong(System.getProperty("org.apache.geronimo.remoting.transport.async.request_timeout", "60000")); // 1 min.
+ Long.parseLong(System.getProperty("org.apache.geronimo.remoting.transport.async.request_timeout", "60000"));
+ // 1 min.
/** The maximum number of open connections that are allowed per pool. A new pool is allocated to each sever this vm connects to. */
static public final int MAX_CONNECTION_POOL_SIZE =
Integer.parseInt(System.getProperty("org.apache.geronimo.remoting.transport.async.max_connection_per_pool", "25"));
@@ -95,7 +109,6 @@
protected ClockDaemon clockDaemon;
public boolean MOCK_APPLET_SECURITY = false;
-
private int nextWorkerID = 0;
private int getNextWorkerID() {
return nextWorkerID++;
@@ -162,9 +175,17 @@
dynamicServer = (AbstractServer) TransportFactory.instance.createSever();
- // TODO: find a way to get a dispatcher to pass to the bind call.
- dynamicServer.bind(new URI("async://0.0.0.0:0"), null);
+ // Build a routing path so this transport can deliver messages back to
+ // clients.
+ SubsystemRouter subsystemRouter = new SubsystemRouter();
+ subsystemRouter.doStart();
+ InterceptorRegistryRouter registryRouter = new InterceptorRegistryRouter();
+ registryRouter.setSubsystemRouter(subsystemRouter);
+ registryRouter.doStart();
+
+ dynamicServer.bind(new URI("async://0.0.0.0:0"), subsystemRouter);
dynamicServer.start();
+
return dynamicServer;
} catch (Throwable e) {
@@ -206,5 +227,86 @@
*/
synchronized public AbstractServer getDefaultServer() {
return defaultServer;
+ }
+
+ // Use for the keys in our map..
+ // since we want to do identity lookups on objects.
+ static class ObjectKey {
+ private Object key;
+ ObjectKey(Object key) {
+ this.key = key;
+ }
+ public boolean equals(Object obj) {
+ return ((ObjectKey) obj).key == key;
+ }
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ // Keeps track of the exported objects.
+ HashMap exportedObjects = new HashMap();
+ static class ExportedObjec {
+
+ }
+
+ /**
+ * @param proxy
+ * @return
+ */
+ public Object exportObject(Object object) throws IOException {
+
+ ObjectKey key = new ObjectKey(object);
+
+ // Have we allready exported that object??
+ Object proxy = exportedObjects.get(key);
+ if (proxy == null) {
+
+ // we need to export it.
+ AbstractServer server = getServerForClientRequest();
+ // TODO Auto-generated method stub
+
+ // Setup the server side contianer..
+ DeMarshalingInterceptor demarshaller = new DeMarshalingInterceptor();
+ demarshaller.setClassloader(object.getClass().getClassLoader());
+ Long dmiid = InterceptorRegistry.instance.register(demarshaller);
+
+ ProxyContainer serverContainer = new ProxyContainer();
+ serverContainer.addInterceptor(demarshaller);
+ serverContainer.addInterceptor(new ReflexiveInterceptor(object));
+
+ // Setup client container...
+ RemoteTransportInterceptor transport;
+ try {
+ // Setup the client side container..
+ transport = new RemoteTransportInterceptor();
+ URI uri = server.getClientConnectURI();
+ uri = URISupport.setPath(uri, "/Remoting");
+ uri = URISupport.setFragment(uri, "" + dmiid);
+ transport.setRemoteURI(uri);
+ } catch (URISyntaxException e) {
+ throw new IOException("Remote URI could not be constructed.");
+ }
+ InterVMRoutingInterceptor remoteRouter = new InterVMRoutingInterceptor();
+ IntraVMRoutingInterceptor localRouter = new IntraVMRoutingInterceptor();
+ localRouter.setDeMarshalingInterceptorID(dmiid);
+ localRouter.setNext(demarshaller.getNext());
+ remoteRouter.setLocalInterceptor(localRouter);
+ remoteRouter.setTransportInterceptor(transport);
+
+ ProxyContainer clientContainer = new ProxyContainer();
+ clientContainer.addInterceptor(remoteRouter);
+ clientContainer.addInterceptor(localRouter);
+ //clientContainer.addInterceptor(demarshaller.getNext());
+ proxy = clientContainer.createProxy(object.getClass().getClassLoader(), object.getClass().getInterfaces());
+
+ exportedObjects.put(key, proxy);
+ }
+ return proxy;
+ }
+
+ public boolean unexportObject(Object object) {
+ ObjectKey key = new ObjectKey(object);
+ return exportedObjects.remove(key)!=null;
}
}
1.2 +8 -1 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/async/TransportFactory.java
Index: TransportFactory.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/async/TransportFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TransportFactory.java 16 Nov 2003 05:27:33 -0000 1.1
+++ TransportFactory.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -114,4 +114,11 @@
return new NonBlockingChannel();
}
+ /**
+ * @see org.apache.geronimo.remoting.transport.TransportFactory#doUnexport(java.lang.Object)
+ */
+ public boolean doUnexport(Object object) {
+ return Registry.instance.unexportObject(object);
+ }
+
}
1.2 +27 -2 incubator-geronimo/modules/remoting/src/test/org/apache/geronimo/remoting/JMXRemotingTestMain.java
Index: JMXRemotingTestMain.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/test/org/apache/geronimo/remoting/JMXRemotingTestMain.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JMXRemotingTestMain.java 16 Nov 2003 05:27:34 -0000 1.1
+++ JMXRemotingTestMain.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -56,8 +56,13 @@
package org.apache.geronimo.remoting;
+import java.rmi.Remote;
+
import javax.management.MBeanServer;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.apache.geronimo.remoting.jmx.RemoteMBeanServerFactory;
/**
@@ -67,15 +72,35 @@
*/
public class JMXRemotingTestMain {
- public void testCheckClassLoaders() throws Exception {
+ public void XtestCheckClassLoaders() throws Exception {
MBeanServer server = RemoteMBeanServerFactory.create("localhost");
String[] strings = server.getDomains();
for(int i=0; i < strings.length; i++){
System.out.println("domain: "+strings[i]);
}
}
+
+ class MyListner implements NotificationListener, Remote {
+
+ /**
+ * @see javax.management.NotificationListener#handleNotification(javax.management.Notification, java.lang.Object)
+ */
+ public void handleNotification(Notification arg0, Object arg1) {
+ System.out.println("Got notification: "+arg0);
+ System.out.println(" : "+arg1);
+ }
+
+ }
+
+ public void testNotificationListner() throws Exception {
+ System.out.println("adding listner..");
+ MBeanServer server = RemoteMBeanServerFactory.create("localhost");
+ server.addNotificationListener(JMXUtil.getObjectName("geronimo.deployment:role=DeploymentController"),new MyListner(),null,null);
+ Thread.sleep(1000*60*5);
+ System.out.println("done..");
+ }
public static void main(String[] args) throws Exception {
- new JMXRemotingTestMain().testCheckClassLoaders();
+ new JMXRemotingTestMain().testNotificationListner();
}
}
1.2 +5 -3 incubator-geronimo/modules/remoting/src/test/org/apache/geronimo/remoting/RemotingInterceptorsTest.java
Index: RemotingInterceptorsTest.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/test/org/apache/geronimo/remoting/RemotingInterceptorsTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RemotingInterceptorsTest.java 16 Nov 2003 05:27:34 -0000 1.1
+++ RemotingInterceptorsTest.java 19 Nov 2003 11:15:03 -0000 1.2
@@ -67,7 +67,7 @@
import org.apache.geronimo.proxy.ProxyContainer;
import org.apache.geronimo.proxy.ReflexiveInterceptor;
-import org.apache.geronimo.remoting.router.SimpleInterceptorRegistryRouter;
+import org.apache.geronimo.remoting.router.InterceptorRegistryRouter;
import org.apache.geronimo.remoting.transport.BytesMarshalledObject;
import org.apache.geronimo.remoting.transport.RemoteTransportInterceptor;
import org.apache.geronimo.remoting.transport.TransportFactory;
@@ -106,7 +106,9 @@
URI bindURI = new URI("async://0.0.0.0:0");
TransportFactory tf = TransportFactory.getTransportFactory(bindURI);
server = tf.createSever();
- server.bind(bindURI,new SimpleInterceptorRegistryRouter());
+ InterceptorRegistryRouter irr = new InterceptorRegistryRouter();
+ irr.doStart();
+ server.bind(bindURI,irr);
connectURI = server.getClientConnectURI();
server.start();