dain 2004/01/14 21:36:53
Modified: modules/kernel/src/java/org/apache/geronimo/gbean/jmx
CollectionProxy.java GBeanMBeanEndpoint.java
Proxy.java SingleProxy.java
Added: modules/kernel/src/java/org/apache/geronimo/gbean
EndpointCollection.java
EndpointCollectionEvent.java
EndpointCollectionListener.java
Log:
Added notifications to the endpoint collection
Changed synchronization in endpoint collections
Revision Changes Path
1.1
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/EndpointCollection.java
Index: EndpointCollection.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 [EMAIL PROTECTED]
*
* 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.gbean;
import java.util.Collection;
/**
* An extension of collection that allows a client to register for
notifications when
* members are added to and removed from the collection.
*
* @version $Revision: 1.1 $ $Date: 2004/01/15 05:36:53 $
*/
public interface EndpointCollection extends Collection {
void addEndpointCollectionListener(EndpointCollectionListener listener);
void removeEndpointCollectionListener(EndpointCollectionListener
listener);
}
1.1
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/EndpointCollectionEvent.java
Index: EndpointCollectionEvent.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 [EMAIL PROTECTED]
*
* 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.gbean;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/01/15 05:36:53 $
*/
public class EndpointCollectionEvent {
private final String endpointName;
private final Object member;
public EndpointCollectionEvent(String endpointName, Object member) {
this.endpointName = endpointName;
this.member = member;
}
public String getEndpointName() {
return endpointName;
}
public Object getMember() {
return member;
}
}
1.1
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/EndpointCollectionListener.java
Index: EndpointCollectionListener.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 [EMAIL PROTECTED]
*
* 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.gbean;
import java.util.EventListener;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/01/15 05:36:53 $
*/
public interface EndpointCollectionListener extends EventListener {
void memberAdded(EndpointCollectionEvent event);
void memberRemoved(EndpointCollectionEvent event);
}
1.4 +155 -65
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/CollectionProxy.java
Index: CollectionProxy.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/CollectionProxy.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CollectionProxy.java 15 Jan 2004 00:45:54 -0000 1.3
+++ CollectionProxy.java 15 Jan 2004 05:36:53 -0000 1.4
@@ -62,10 +62,17 @@
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
+import java.util.HashSet;
+import java.util.ArrayList;
import javax.management.ObjectName;
import org.apache.geronimo.gbean.WaitingException;
+import org.apache.geronimo.gbean.EndpointCollection;
+import org.apache.geronimo.gbean.EndpointCollectionListener;
+import org.apache.geronimo.gbean.EndpointCollectionEvent;
import org.apache.geronimo.kernel.jmx.InterfaceCallbackFilter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.Factory;
@@ -77,33 +84,46 @@
* @version $Revision$ $Date$
*/
public class CollectionProxy implements Proxy {
+ private static final Log log = LogFactory.getLog(CollectionProxy.class);
+
/**
* The GBeanMBean to which this proxy belongs.
*/
- private final GBeanMBean gmbean;
+ private GBeanMBean gmbean;
+
+ /**
+ * Name of the endpoint
+ */
+ public String name;
/**
* A map from object names to the proxy
*/
- private final Map proxies = new HashMap();
+ private Map proxies = new HashMap();
/**
* A map from object names to the proxy interceptor
*/
- private final Map interceptors = new HashMap();
+ private Map interceptors = new HashMap();
/**
* Proxy collection implementation held by the component
*/
- private final ClientCollection proxy = new
ClientCollection(proxies.values());
+ private ClientCollection proxy = new ClientCollection();
/**
* Facotry for proxy instances.
*/
- private final Factory factory;
+ private Factory factory;
+
+ /**
+ * Is this proxy currently stopped?
+ */
+ private boolean stopped;
- public CollectionProxy(GBeanMBean gmbean, Class type) {
+ public CollectionProxy(GBeanMBean gmbean, String name, Class type) {
this.gmbean = gmbean;
+ this.name = name;
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(Object.class);
enhancer.setInterfaces(new Class[]{type});
@@ -113,7 +133,23 @@
factory = enhancer.create();
}
- public Object getProxy() {
+ public synchronized void destroy() {
+ for (Iterator iterator = interceptors.values().iterator();
iterator.hasNext();) {
+ ProxyMethodInterceptor interceptor = (ProxyMethodInterceptor)
iterator.next();
+ interceptor.disconnect();
+ }
+ proxy.listeners = null;
+
+ gmbean = null;
+ name = null;
+ proxies = null;
+ interceptors = null;
+ proxy = null;
+ factory = null;
+ stopped = true;
+ }
+
+ public synchronized Object getProxy() {
return proxy;
}
@@ -128,19 +164,27 @@
interceptor.connect(gmbean.getServer(), target,
proxy.isStopped());
interceptors.put(target, interceptor);
proxies.put(target, factory.newInstance(interceptor));
+ if (!stopped) {
+ proxy.fireMemberAdddedEvent(target);
+ }
}
}
public synchronized void removeTarget(ObjectName target) {
- proxies.remove(target);
- ProxyMethodInterceptor interceptor = (ProxyMethodInterceptor)
interceptors.remove(target);
- if (interceptor != null) {
- interceptor.disconnect();
+ Object targetProxy = proxies.remove(target);
+ if (targetProxy != null) {
+ ProxyMethodInterceptor interceptor = (ProxyMethodInterceptor)
interceptors.remove(target);
+ if (interceptor != null) {
+ interceptor.disconnect();
+ }
+ if (!stopped) {
+ proxy.fireMemberRemovedEvent(target);
+ }
}
}
public synchronized void start() throws WaitingException {
- proxy.start();
+ stopped = false;
for (Iterator iterator = interceptors.values().iterator();
iterator.hasNext();) {
ProxyMethodInterceptor interceptor = (ProxyMethodInterceptor)
iterator.next();
interceptor.start();
@@ -148,64 +192,120 @@
}
public synchronized void stop() {
- proxy.stop();
+ stopped = true;
for (Iterator iterator = interceptors.values().iterator();
iterator.hasNext();) {
ProxyMethodInterceptor interceptor = (ProxyMethodInterceptor)
iterator.next();
interceptor.stop();
}
}
- private static class ClientCollection implements Collection {
- private Collection proxies;
- private boolean stopped;
+ private class ClientCollection implements EndpointCollection {
+ private Set listeners = new HashSet();
- public ClientCollection(Collection proxies) {
- this.proxies = proxies;
- stopped = true;
+ public boolean isStopped() {
+ synchronized (CollectionProxy.this) {
+ return stopped;
+ }
}
- private void start() {
- stopped = false;
+ public void addEndpointCollectionListener(EndpointCollectionListener
listener) {
+ synchronized (CollectionProxy.this) {
+ listeners.add(listener);
+ }
}
- private void stop() {
- stopped = true;
+ public void
removeEndpointCollectionListener(EndpointCollectionListener listener) {
+ synchronized (CollectionProxy.this) {
+ listeners.remove(listener);
+ }
}
- public boolean isStopped() {
- return stopped;
+ private void fireMemberAdddedEvent(Object member) {
+ ArrayList listenerCopy;
+ synchronized (CollectionProxy.this) {
+ listenerCopy = new ArrayList(listeners);
+ }
+ for (Iterator iterator = listenerCopy.iterator();
iterator.hasNext();) {
+ EndpointCollectionListener listener =
(EndpointCollectionListener) iterator.next();
+ try {
+ listener.memberAdded(new EndpointCollectionEvent(name,
member));
+ } catch (Throwable t) {
+ log.error("Listener threw exception", t);
+ }
+ }
+ }
+
+ private void fireMemberRemovedEvent(Object member) {
+ ArrayList listenerCopy;
+ synchronized (CollectionProxy.this) {
+ listenerCopy = new ArrayList(listeners);
+ }
+ for (Iterator iterator = listenerCopy.iterator();
iterator.hasNext();) {
+ EndpointCollectionListener listener =
(EndpointCollectionListener) iterator.next();
+ try {
+ listener.memberRemoved(new EndpointCollectionEvent(name,
member));
+ } catch (Throwable t) {
+ log.error("Listener threw exception", t);
+ }
+ }
}
public int size() {
- if (stopped) {
- return 0;
+ synchronized (CollectionProxy.this) {
+ if (stopped) {
+ return 0;
+ }
+ return proxies.size();
}
- return proxies.size();
}
public boolean isEmpty() {
- if (stopped) {
- return true;
+ synchronized (CollectionProxy.this) {
+ if (stopped) {
+ return true;
+ }
+ return proxies.isEmpty();
}
- return proxies.isEmpty();
}
public boolean contains(Object o) {
- if (stopped) {
- return false;
+ synchronized (CollectionProxy.this) {
+ if (stopped) {
+ return false;
+ }
+ return proxies.containsValue(o);
}
- return proxies.contains(o);
}
public Iterator iterator() {
- if (stopped) {
+ synchronized (CollectionProxy.this) {
+ if (stopped) {
+ return new Iterator() {
+ public boolean hasNext() {
+ return false;
+ }
+
+ public Object next() {
+ throw new NoSuchElementException();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
return new Iterator() {
+ // copy the proxies, so the client can iterate without
concurrent modification
+ // this is necssary since the client has nothing to
synchronize on
+ private final Iterator iterator = new
ArrayList(proxies.values()).iterator();
+
public boolean hasNext() {
- return false;
+ return iterator.hasNext();
}
public Object next() {
- throw new NoSuchElementException();
+ return iterator.next();
}
public void remove() {
@@ -213,46 +313,36 @@
}
};
}
-
- return new Iterator() {
- private final Iterator iterator = proxies.iterator();
-
- public boolean hasNext() {
- return iterator.hasNext();
- }
-
- public Object next() {
- return iterator.next();
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
- };
}
public Object[] toArray() {
- if (stopped) {
- return new Object[0];
+ synchronized (CollectionProxy.this) {
+ if (stopped) {
+ return new Object[0];
+ }
+ return proxies.values().toArray();
}
- return proxies.toArray();
}
public Object[] toArray(Object a[]) {
- if (stopped) {
- if (a.length > 0) {
- a[0] = null;
+ synchronized (CollectionProxy.this) {
+ if (stopped) {
+ if (a.length > 0) {
+ a[0] = null;
+ }
+ return a;
}
- return a;
+ return proxies.values().toArray(a);
}
- return proxies.toArray(a);
}
public boolean containsAll(Collection c) {
- if (stopped) {
- return c.isEmpty();
+ synchronized (CollectionProxy.this) {
+ if (stopped) {
+ return c.isEmpty();
+ }
+ return proxies.values().containsAll(c);
}
- return proxies.containsAll(c);
}
public boolean add(Object o) {
1.3 +3 -2
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanEndpoint.java
Index: GBeanMBeanEndpoint.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanEndpoint.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- GBeanMBeanEndpoint.java 15 Jan 2004 00:45:54 -0000 1.2
+++ GBeanMBeanEndpoint.java 15 Jan 2004 05:36:53 -0000 1.3
@@ -196,7 +196,7 @@
if (singleValued) {
proxy = new SingleProxy(gmbean, name, type, patterns);
} else {
- proxy = new CollectionProxy(gmbean, type);
+ proxy = new CollectionProxy(gmbean, name, type);
}
@@ -266,6 +266,7 @@
Set registeredTargets = proxy.getTargets();
// destroy the proxy
+ proxy.destroy();
proxy = null;
// unregister for all notifications
1.2 +3 -1
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/Proxy.java
Index: Proxy.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/Proxy.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Proxy.java 12 Jan 2004 01:38:55 -0000 1.1
+++ Proxy.java 15 Jan 2004 05:36:53 -0000 1.2
@@ -66,6 +66,8 @@
* @version $Revision$ $Date$
*/
public interface Proxy {
+ void destroy();
+
Object getProxy();
Set getTargets();
1.4 +20 -8
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/SingleProxy.java
Index: SingleProxy.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/SingleProxy.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SingleProxy.java 15 Jan 2004 00:45:54 -0000 1.3
+++ SingleProxy.java 15 Jan 2004 05:36:53 -0000 1.4
@@ -81,29 +81,29 @@
/**
* The GBeanMBean to which this proxy belongs.
*/
- private final GBeanMBean gmbean;
+ private GBeanMBean gmbean;
/**
* Name of this proxy.
*/
- private final String name;
+ private String name;
/**
* The ObjectName patterns to which this proxy could be connected.
* This is used to block mbeans from starting that would match a
* pattern while we are running.
*/
- private final Set patterns;
+ private Set patterns;
/**
* A set of all targets matching the
*/
- private final Set targets = new HashSet();
+ private Set targets = new HashSet();
/**
* Proxy implementation held by the component
*/
- private final Object proxy;
+ private Object proxy;
/**
* Is the GBeanMBean waitng for me to start?
@@ -134,11 +134,23 @@
proxy = factory.newInstance(methodInterceptor);
}
- public Object getProxy() {
+ public synchronized void destroy() {
+ methodInterceptor.disconnect();
+
+ gmbean = null;
+ name = null;
+ patterns = null;
+ targets = null;
+ proxy = null;
+ waitingForMe = false;
+ methodInterceptor = null;
+ }
+
+ public synchronized Object getProxy() {
return proxy;
}
- public Set getTargets() {
+ public synchronized Set getTargets() {
return targets;
}