Author: darran.lofthouse(a)jboss.com
Date: 2009-03-02 06:31:40 -0500 (Mon, 02 Mar 2009)
New Revision: 9467
Modified:
stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/metadata/umdm/EndpointMetaData.java
Log:
[JBPAPP-1743] Correct WeakReference handling in ConfigObservable to remove cleared
WeakReferences.
Modified:
stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/metadata/umdm/EndpointMetaData.java
===================================================================
---
stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/metadata/umdm/EndpointMetaData.java 2009-03-02
10:09:06 UTC (rev 9466)
+++
stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/metadata/umdm/EndpointMetaData.java 2009-03-02
11:31:40 UTC (rev 9467)
@@ -21,8 +21,12 @@
*/
package org.jboss.ws.metadata.umdm;
+
// $Id$
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -640,6 +644,7 @@
if (retParam != null)
createAccessor(retParam, jaxbCtx);
}
+
}
private void eagerInitializeJAXBContextCache()
@@ -843,6 +848,7 @@
class ConfigObservable extends Observable
{
+ private ReferenceQueue<WeakReference<Observer>> queue = new
ReferenceQueue<WeakReference<Observer>>();
private List<WeakReference<Observer>> observer = new
ArrayList<WeakReference<Observer>>();
public void doNotify(Object object)
@@ -853,15 +859,17 @@
public synchronized void addObserver(Observer o)
{
- observer.add(new WeakReference(o));
+ clearCollected();
+ observer.add(new WeakReference(o, queue));
}
public synchronized void deleteObserver(Observer o)
{
+ clearCollected();
for (WeakReference<Observer> w : observer)
{
Observer tmp = w.get();
- if (tmp.equals(o))
+ if (tmp != null && tmp.equals(o))
{
observer.remove(o);
break;
@@ -877,16 +885,29 @@
public void notifyObservers(Object arg)
{
+ clearCollected();
if (hasChanged())
{
for (WeakReference<Observer> w : observer)
{
Observer tmp = w.get();
- tmp.update(this, arg);
-
+ if (tmp != null)
+ {
+ tmp.update(this, arg);
+ }
}
}
}
+
+ private void clearCollected()
+ {
+ Reference ref;
+ while ((ref = queue.poll()) != null)
+ {
+ observer.remove(ref);
+ }
+
+ }
}
public List<UnifiedPortComponentRefMetaData> getServiceRefContrib()