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/23 11:56:35 UTC
cvs commit: incubator-geronimo/modules/remoting/src/test/org/apache/geronimo/remoting JMXRemotingTestMain.java
chirino 2003/11/23 02:56:35
Modified: modules/remoting/src/java/org/apache/geronimo/remoting
InterceptorRegistry.java TransportContext.java
modules/remoting/src/java/org/apache/geronimo/remoting/transport
BytesMarshalledObject.java BytesMsg.java
modules/remoting/src/java/org/apache/geronimo/remoting/transport/async
AsyncClient.java AsyncMsg.java Registry.java
modules/remoting/src/test/org/apache/geronimo/remoting
JMXRemotingTestMain.java
Added: modules/remoting/src/java/org/apache/geronimo/remoting/transport/async
IdentityInterceptor.java RemoteRef.java
Log:
Updated remoting so that remote object identity works as you would expect.
Whne a object X is sent to another machine as remote object A and later
sent again as remote object B.. now the A==B is true. A.equals(B) is also true.
Revision Changes Path
1.2 +2 -2 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/InterceptorRegistry.java
Index: InterceptorRegistry.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/InterceptorRegistry.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InterceptorRegistry.java 16 Nov 2003 05:27:27 -0000 1.1
+++ InterceptorRegistry.java 23 Nov 2003 10:56:35 -0000 1.2
@@ -70,7 +70,7 @@
}
- long nextID = 0;
+ long nextID = System.currentTimeMillis();
private synchronized long getNextID() {
return nextID++;
}
1.2 +7 -1 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/TransportContext.java
Index: TransportContext.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/TransportContext.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TransportContext.java 19 Nov 2003 11:15:03 -0000 1.1
+++ TransportContext.java 23 Nov 2003 10:56:35 -0000 1.2
@@ -73,4 +73,10 @@
}
public abstract Object writeReplace(Object proxy) throws IOException;
+
+ /**
+ * @param obj
+ * @return
+ */
+ public abstract Object readReplace(Object obj) throws IOException;
}
1.3 +13 -9 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BytesMarshalledObject.java 19 Nov 2003 11:15:03 -0000 1.2
+++ BytesMarshalledObject.java 23 Nov 2003 10:56:35 -0000 1.3
@@ -80,10 +80,13 @@
public class ObjectInputStreamExt extends ObjectInputStream {
private ClassLoader classloader;
+ private TransportContext transportContext;
- public ObjectInputStreamExt(InputStream in, ClassLoader loader) throws IOException {
+ public ObjectInputStreamExt(InputStream in, ClassLoader loader, TransportContext transportContext) throws IOException {
super(in);
+ this.transportContext = transportContext;
this.classloader = loader;
+ this.enableResolveObject(transportContext!=null);
}
/**
@@ -109,6 +112,13 @@
}
+
+ /**
+ * @see java.io.ObjectInputStream#resolveObject(java.lang.Object)
+ */
+ protected Object resolveObject(Object obj) throws IOException {
+ return transportContext.readReplace(obj);
+ }
}
static class ObjectOutputStreamExt extends ObjectOutputStream {
@@ -134,12 +144,6 @@
}
- static class NullTransportContext extends TransportContext {
- public Object writeReplace(Object proxy) throws IOException {
- return proxy;
- }
- }
-
private byte data[];
private TransportContext transportContext;
@@ -187,7 +191,7 @@
public Object get(ClassLoader classloader) throws IOException, ClassNotFoundException {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
- ObjectInputStreamExt is = new ObjectInputStreamExt(bais, classloader);
+ ObjectInputStreamExt is = new ObjectInputStreamExt(bais, classloader, transportContext);
Object rc = is.readObject();
is.close();
return rc;
1.2 +13 -3 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/BytesMsg.java
Index: BytesMsg.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/BytesMsg.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BytesMsg.java 16 Nov 2003 05:27:27 -0000 1.1
+++ BytesMsg.java 23 Nov 2003 10:56:35 -0000 1.2
@@ -65,14 +65,24 @@
import java.util.ArrayList;
import org.apache.geronimo.remoting.MarshalledObject;
+import org.apache.geronimo.remoting.TransportContext;
/**
* @version $Revision$ $Date$
*/
public class BytesMsg implements Msg {
+ transient TransportContext transportContext;
ArrayList objectStack = new ArrayList(5);
+
+ /**
+ * @param transportContext
+ */
+ public BytesMsg(TransportContext transportContext) {
+ this.transportContext = transportContext;
+ }
+
/**
* @see org.apache.geronimo.remoting.transport.Msg#pushMarshaledObject(org.apache.geronimo.remoting.MarshalledObject)
*/
@@ -97,7 +107,7 @@
* @see org.apache.geronimo.remoting.transport.Msg#createMsg()
*/
public Msg createMsg() {
- return new BytesMsg();
+ return new BytesMsg(transportContext);
}
public void writeExternal(DataOutput out) throws IOException {
@@ -117,7 +127,7 @@
int l = in.readInt();
byte t[] = new byte[l];
in.readFully(t);
- BytesMarshalledObject mo = new BytesMarshalledObject();
+ BytesMarshalledObject mo = new BytesMarshalledObject(transportContext);
mo.setBytes(t);
objectStack.add(mo);
}
1.3 +2 -12 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AsyncClient.java 19 Nov 2003 11:15:03 -0000 1.2
+++ AsyncClient.java 23 Nov 2003 10:56:35 -0000 1.3
@@ -56,14 +56,11 @@
*/
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;
@@ -116,14 +113,7 @@
* @see org.apache.geronimo.remoting.transport.TransportClient#createMarshalledObject()
*/
public MarshalledObject createMarshalledObject() {
- return new BytesMarshalledObject(new TransportContext() {
- public Object writeReplace(Object proxy) throws IOException {
- if (proxy instanceof Remote) {
- return Registry.instance.exportObject(proxy);
- }
- return proxy;
- }
- });
+ return new BytesMarshalledObject(Registry.transportContext);
}
}
1.2 +10 -1 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/async/AsyncMsg.java
Index: AsyncMsg.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/async/AsyncMsg.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AsyncMsg.java 16 Nov 2003 05:27:27 -0000 1.1
+++ AsyncMsg.java 23 Nov 2003 10:56:35 -0000 1.2
@@ -76,6 +76,15 @@
int requestId;
String to;
+
+ /**
+ * @param transportContext
+ */
+ public AsyncMsg() {
+ super(Registry.transportContext);
+ }
+
+
/**
* @see org.apache.geronimo.remoting.transport.BytesMsg#createMsg()
*/
1.3 +76 -40 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Registry.java 19 Nov 2003 11:15:03 -0000 1.2
+++ Registry.java 23 Nov 2003 10:56:35 -0000 1.3
@@ -58,17 +58,20 @@
import java.io.IOException;
import java.net.URI;
-import java.net.URISyntaxException;
+import java.rmi.Remote;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
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.MarshalingInterceptor;
+import org.apache.geronimo.remoting.TransportContext;
import org.apache.geronimo.remoting.router.InterceptorRegistryRouter;
import org.apache.geronimo.remoting.router.SubsystemRouter;
import org.apache.geronimo.remoting.transport.RemoteTransportInterceptor;
@@ -245,68 +248,101 @@
}
// Keeps track of the exported objects.
- HashMap exportedObjects = new HashMap();
- static class ExportedObjec {
-
+ Map exportedObjects = Collections.synchronizedMap(new HashMap());
+
+ static class ExportedObject {
+ RemoteRef remoteRef;
+ ProxyContainer serverContainer;
}
-
+
/**
* @param proxy
* @return
*/
- public Object exportObject(Object object) throws IOException {
+ public RemoteRef 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
+ ExportedObject eo = (ExportedObject) exportedObjects.get(key);
+ if (eo == null) {
// 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));
+ eo = new ExportedObject();
+ eo.serverContainer = new ProxyContainer();
+ eo.serverContainer.addInterceptor(demarshaller);
+ eo.serverContainer.addInterceptor(new ReflexiveInterceptor(object));
- // Setup client container...
- RemoteTransportInterceptor transport;
+ // Build the RemoteRef for the object.
+ eo.remoteRef = new RemoteRef();
try {
- // Setup the client side container..
- transport = new RemoteTransportInterceptor();
+
+ AbstractServer server = getServerForClientRequest();
URI uri = server.getClientConnectURI();
uri = URISupport.setPath(uri, "/Remoting");
uri = URISupport.setFragment(uri, "" + dmiid);
- transport.setRemoteURI(uri);
- } catch (URISyntaxException e) {
+ eo.remoteRef.remoteURI = uri;
+ } catch (Exception 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());
+ eo.remoteRef.interfaces = object.getClass().getInterfaces();
- exportedObjects.put(key, proxy);
+ exportedObjects.put(key, eo);
+ log.debug("Exported object: "+eo.remoteRef.remoteURI);
}
- return proxy;
+ return eo.remoteRef;
}
-
+
public boolean unexportObject(Object object) {
ObjectKey key = new ObjectKey(object);
- return exportedObjects.remove(key)!=null;
+ return exportedObjects.remove(key) != null;
+ }
+
+ // Keep a weak map of the objects that we have imported.
+ // This allows == comparions to work on previously imported objects.
+ Map importedObjects = new WeakHashMap();
+
+ /**
+ * @param obj
+ * @return
+ */
+ synchronized protected Object importObject(RemoteRef ref) {
+
+ Object object = importedObjects.get(ref);
+ if (object == null) {
+
+ RemoteTransportInterceptor transport = new RemoteTransportInterceptor();
+ transport.setRemoteURI(ref.remoteURI);
+
+ ProxyContainer clientContainer = new ProxyContainer();
+ clientContainer.addInterceptor(new IdentityInterceptor(ref));
+ clientContainer.addInterceptor(new MarshalingInterceptor());
+ clientContainer.addInterceptor(transport);
+
+ object = clientContainer.createProxy(Thread.currentThread().getContextClassLoader(), ref.interfaces);
+ log.trace("Imported object: "+ref.remoteURI);
+ importedObjects.put(ref, object);
+ }
+ return object;
}
+
+ public static final TransportContext transportContext = new TransportContext() {
+ public Object writeReplace(Object proxy) throws IOException {
+ if (proxy instanceof Remote) {
+ return Registry.instance.exportObject(proxy);
+ }
+ return proxy;
+ }
+ public Object readReplace(Object obj) throws IOException {
+ if (obj instanceof RemoteRef) {
+ return Registry.instance.importObject((RemoteRef) obj);
+ }
+ return obj;
+ }
+ };
+
}
1.1 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/async/IdentityInterceptor.java
Index: IdentityInterceptor.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.transport.async;
import java.io.Serializable;
import java.lang.reflect.Method;
import org.apache.geronimo.common.Classes;
import org.apache.geronimo.core.service.Interceptor;
import org.apache.geronimo.core.service.Invocation;
import org.apache.geronimo.core.service.InvocationResult;
import org.apache.geronimo.core.service.SimpleInvocationResult;
import org.apache.geronimo.proxy.ProxyInvocation;
/**
* @version $Revision: 1.1 $ $Date: 2003/11/23 10:56:35 $
*/
public class IdentityInterceptor implements Interceptor, Serializable {
private static final Method EQUALS_METHOD = Classes.getMethod(Object.class, "equals");
private static final Method HASHCODE_METHOD = Classes.getMethod(Object.class, "hashCode");
private RemoteRef ref;
private Interceptor next;
/**
* @param ref
*/
public IdentityInterceptor(RemoteRef ref) {
this.ref = ref;
}
/**
* @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);
if( method.equals(EQUALS_METHOD) ) {
Object proxy = ProxyInvocation.getProxy(invocation);
Object[] args = ProxyInvocation.getArguments(invocation);
return new SimpleInvocationResult( true, proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
} else if( method.equals(HASHCODE_METHOD) ) {
return new SimpleInvocationResult( true, new Integer(ref.hashCode()) );
}
return next.invoke(invocation);
}
/**
* @see org.apache.geronimo.core.service.Interceptor#getNext()
*/
public Interceptor getNext() {
return next;
}
/**
* @see org.apache.geronimo.core.service.Interceptor#setNext(org.apache.geronimo.core.service.Interceptor)
*/
public void setNext(Interceptor interceptor) throws IllegalStateException {
this.next = interceptor;
}
}
1.1 incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/transport/async/RemoteRef.java
Index: RemoteRef.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.transport.async;
import java.io.Serializable;
import java.net.URI;
class RemoteRef implements Serializable {
URI remoteURI;
Class interfaces[];
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
int rc = remoteURI.hashCode();
return rc;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
try {
return remoteURI.equals(((RemoteRef)obj).remoteURI);
} catch (Throwable e) {
return false;
}
}
}
1.3 +15 -4 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JMXRemotingTestMain.java 19 Nov 2003 11:15:03 -0000 1.2
+++ JMXRemotingTestMain.java 23 Nov 2003 10:56:35 -0000 1.3
@@ -61,10 +61,13 @@
import javax.management.MBeanServer;
import javax.management.Notification;
import javax.management.NotificationListener;
+import javax.management.ObjectName;
import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.apache.geronimo.remoting.jmx.RemoteMBeanServerFactory;
+import EDU.oswego.cs.dl.util.concurrent.Latch;
+
/**
* this test needs for a geronimo instance to be running and
* so I guess this is really a IntegrationTest and not a Unit test.
@@ -72,6 +75,8 @@
*/
public class JMXRemotingTestMain {
+ Latch eventLatch = new Latch();
+
public void XtestCheckClassLoaders() throws Exception {
MBeanServer server = RemoteMBeanServerFactory.create("localhost");
String[] strings = server.getDomains();
@@ -87,7 +92,8 @@
*/
public void handleNotification(Notification arg0, Object arg1) {
System.out.println("Got notification: "+arg0);
- System.out.println(" : "+arg1);
+ System.out.println(" : "+arg1);
+ eventLatch.release();
}
}
@@ -95,9 +101,14 @@
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..");
+ ObjectName name = JMXUtil.getObjectName("geronimo.deployment:role=DeploymentController");
+ MyListner listner = new MyListner();
+ server.addNotificationListener(name,listner,null,null);
+ eventLatch.acquire();
+ System.out.println("Event received.");
+ server.removeNotificationListener(name, listner, null, null);
+ System.out.println("Notifications removed.");
+ Thread.sleep(1000*60);
}
public static void main(String[] args) throws Exception {