beehive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dolan...@apache.org
Subject svn commit: r379610 - in /beehive/trunk/netui/src: pageflow/org/apache/beehive/netui/pageflow/requeststate/NameService.java tags-html/org/apache/beehive/netui/tags/divpanel/DivPanelCRI.java
Date Tue, 21 Feb 2006 22:44:50 GMT
Author: dolander
Date: Tue Feb 21 14:44:46 2006
New Revision: 379610

URL: http://svn.apache.org/viewcvs?rev=379610&view=rev
Log:
A bit agreesive in my use of a WeakReference so I was losing the named
object in the NameService.  This was causing the BVTs to fail.  I
changed the place where the WeakReference was being used.



Modified:
    beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/requeststate/NameService.java
    beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/divpanel/DivPanelCRI.java

Modified: beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/requeststate/NameService.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/requeststate/NameService.java?rev=379610&r1=379609&r2=379610&view=diff
==============================================================================
--- beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/requeststate/NameService.java
(original)
+++ beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/requeststate/NameService.java
Tue Feb 21 14:44:46 2006
@@ -30,6 +30,8 @@
  */
 final public class NameService
 {
+    // @todo: at some point we should walk the HashMap and reclaim all of the WeakReferences
+
     private static final String NAME_SERVICE = "netui.nameService";
 
     // static value for situation where this is not stored in the session.
@@ -149,13 +151,15 @@
     public void put(INameable object) {
         if (object == null)
             throw new IllegalStateException("object must not be null");
+
         String name = object.getObjectName();
         if (name == null)
             throw new IllegalStateException("object has not been named");
+
         TrackingObject to = new TrackingObject();
-        to.setINameable(object);
+        to.setINameable(new WeakReference(object));
 
-        _nameMap.put(name,new WeakReference(to));
+        _nameMap.put(name,to);
 
         // fire the fact that we just added a nameable to be tracked
         if (_listeners != null)
@@ -174,19 +178,20 @@
         if (name == null)
             throw new IllegalStateException("name must not be null");
 
-        WeakReference wr = (WeakReference) _nameMap.get(name);
+        TrackingObject to = (TrackingObject) _nameMap.get(name);
 
         // The object wasn't found
-        if (wr == null)
+        if (to == null)
             return null;
 
         // If the object has been reclaimed, then we remove the named object from the map.
-        TrackingObject to = (TrackingObject) wr.get();
-        if (to == null) {
+        WeakReference wr = to.getWeakINameable();
+        INameable o = (INameable) wr.get();
+        if (o == null) {
             _nameMap.remove(name);
             return null;
         }
-        return to.getINameable();
+        return o;
     }
 
     /**
@@ -236,9 +241,10 @@
         // create a copy of the listeners so that there isn't any modifications while we
         // fire the events.
         synchronized (_listeners) { copy = _listeners.toArray(); }
+        INameable o = (INameable) to.getWeakINameable().get();
 
         for (int i = 0; i < copy.length; i++) {
-            ((NamingObjectListener)copy[i]).namingObject(to.getINameable(), to);
+            ((NamingObjectListener)copy[i]).namingObject(o, to);
         }
     }
 
@@ -261,18 +267,18 @@
 
     final private class TrackingObject extends LazyMap
     {
-        private INameable _nameable;
+        private WeakReference _nameable;
 
         public Map getMap() {
             return (isMapCreated() ? this : null);
         }
 
-        public void setINameable(INameable nameable)
+        public void setINameable(WeakReference nameable)
         {
             _nameable = nameable;
         }
 
-        public INameable getINameable() {
+        public WeakReference getWeakINameable() {
             return _nameable;
         }
     }

Modified: beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/divpanel/DivPanelCRI.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/divpanel/DivPanelCRI.java?rev=379610&r1=379609&r2=379610&view=diff
==============================================================================
--- beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/divpanel/DivPanelCRI.java
(original)
+++ beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/divpanel/DivPanelCRI.java
Tue Feb 21 14:44:46 2006
@@ -57,7 +57,7 @@
         NameService ns = NameService.instance(req.getSession());
         assert(ns != null);
 
-        // get the tree from the name service
+        // get the DivPanel from the name service
         INameable n = ns.get(dp);
         if (n == null) {
             System.err.println("DivPanel '" + dp + "' was not found in the NameService");



Mime
View raw message