diff --git a/VERSION.txt b/VERSION.txt index be3729fe857..1154b5f6fe9 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -10,6 +10,7 @@ jetty-7.4.3-SNAPSHOT + 349870 proxy servlet protect continuation against fast failing exchanges + 349896 SCEP supports zero maxIdleTime + 349897 draft -09 websockets + + 349997 MBeanContainer uses weak references + JETTY-1342 Recreate selector in change task jetty-7.4.2.v20110526 diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java index 1792350b03a..5371c8b60dc 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -32,6 +33,7 @@ import org.eclipse.jetty.util.component.Container; import org.eclipse.jetty.util.component.Container.Relationship; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.thread.ShutdownThread; /** @@ -39,10 +41,12 @@ import org.eclipse.jetty.util.thread.ShutdownThread; */ public class MBeanContainer extends AbstractLifeCycle implements Container.Listener, Dumpable { + private final static Logger __log = Log.getLogger(MBeanContainer.class.getName()); + private final MBeanServer _server; private final WeakHashMap _beans = new WeakHashMap(); private final HashMap _unique = new HashMap(); - private final MultiMap _relations = new MultiMap(); + private final WeakHashMap> _relations = new WeakHashMap>(); private String _domain = null; /** @@ -89,7 +93,7 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste } catch (Exception e) { - Log.ignore(e); + __log.ignore(e); } } @@ -130,6 +134,7 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste */ public synchronized void add(Relationship relationship) { + __log.debug("add {}",relationship); ObjectName parent = _beans.get(relationship.getParent()); if (parent == null) { @@ -145,7 +150,15 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste } if (parent != null && child != null) - _relations.add(parent, relationship); + { + List rels = _relations.get(parent); + if (rels==null) + { + rels=new ArrayList(); + _relations.put(parent,rels); + } + rels.add(relationship); + } } /** @@ -155,11 +168,23 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste */ public synchronized void remove(Relationship relationship) { + __log.debug("remove {}",relationship); ObjectName parent = _beans.get(relationship.getParent()); ObjectName child = _beans.get(relationship.getChild()); if (parent != null && child != null) - _relations.removeValue(parent, relationship); + { + List rels = _relations.get(parent); + if (rels!=null) + { + for (Iterator i=rels.iterator();i.hasNext();) + { + Container.Relationship r = i.next(); + if (relationship.equals(r) || r.getChild()==null) + i.remove(); + } + } + } } /** @@ -169,14 +194,15 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste */ public synchronized void removeBean(Object obj) { + __log.debug("removeBean {}",obj); ObjectName bean = _beans.remove(obj); if (bean != null) { - List beanRelations = _relations.getValues(bean); - if (beanRelations != null && beanRelations.size() > 0) + List beanRelations= _relations.remove(bean); + if (beanRelations != null) { - Log.debug("Unregister {}", beanRelations); + __log.debug("Unregister {}", beanRelations); List removeList = new ArrayList(beanRelations); for (Object r : removeList) { @@ -188,15 +214,15 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste try { _server.unregisterMBean(bean); - Log.debug("Unregistered {}", bean); + __log.debug("Unregistered {}", bean); } catch (javax.management.InstanceNotFoundException e) { - Log.ignore(e); + __log.ignore(e); } catch (Exception e) { - Log.warn(e); + __log.warn(e); } } } @@ -208,6 +234,7 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste */ public synchronized void addBean(Object obj) { + __log.debug("addBean {}",obj); try { if (obj == null || _beans.containsKey(obj)) @@ -271,13 +298,13 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste } ObjectInstance oinstance = _server.registerMBean(mbean, oname); - Log.debug("Registered {}", oinstance.getObjectName()); + __log.debug("Registered {}", oinstance.getObjectName()); _beans.put(obj, oinstance.getObjectName()); } catch (Exception e) { - Log.warn("bean: " + obj, e); + __log.warn("bean: " + obj, e); } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/Container.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/Container.java index 4622c6662aa..0cec73d2463 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/component/Container.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/Container.java @@ -12,6 +12,7 @@ // ======================================================================== package org.eclipse.jetty.util.component; +import java.lang.ref.WeakReference; import java.util.EventListener; import java.util.concurrent.CopyOnWriteArrayList; @@ -225,20 +226,19 @@ public class Container /* ------------------------------------------------------------ */ /** A Container event. * @see Listener - * */ public static class Relationship { - private Object _parent; - private Object _child; + private final WeakReference _parent; + private final WeakReference _child; private String _relationship; private Container _container; private Relationship(Container container, Object parent,Object child, String relationship) { _container=container; - _parent=parent; - _child=child; + _parent=new WeakReference(parent); + _child=new WeakReference(child); _relationship=relationship; } @@ -249,12 +249,12 @@ public class Container public Object getChild() { - return _child; + return _child.get(); } public Object getParent() { - return _parent; + return _parent.get(); } public String getRelationship() @@ -280,7 +280,7 @@ public class Container if (o==null || !(o instanceof Relationship)) return false; Relationship r = (Relationship)o; - return r._parent==_parent && r._child==_child && r._relationship.equals(_relationship); + return r._parent.get()==_parent.get() && r._child.get()==_child.get() && r._relationship.equals(_relationship); } }