Author: darran.lofthouse(a)jboss.com
Date: 2009-02-27 13:24:18 -0500 (Fri, 27 Feb 2009)
New Revision: 9447
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/umdm/EndpointMetaData.java
Log:
[JBWS-2559] Correct WeakReference handling in ConfigObservable to remove cleared
WeakReferences.
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/umdm/EndpointMetaData.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/umdm/EndpointMetaData.java 2009-02-27
18:00:26 UTC (rev 9446)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/umdm/EndpointMetaData.java 2009-02-27
18:24:18 UTC (rev 9447)
@@ -21,6 +21,8 @@
*/
package org.jboss.ws.metadata.umdm;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -675,9 +677,9 @@
if (retParam != null)
createAccessor(retParam, jaxbCtx);
}
-
+
}
-
+
private void eagerInitializeJAXBContextCache()
{
//initialize jaxb context cache
@@ -685,7 +687,7 @@
{
log.debug("Initializing JAXBContext cache...");
BindingCustomization bindingCustomization = null;
- if(this instanceof ServerEndpointMetaData)
+ if (this instanceof ServerEndpointMetaData)
{
bindingCustomization =
((ServerEndpointMetaData)this).getEndpoint().getAttachment(BindingCustomization.class);
}
@@ -928,6 +930,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)
@@ -938,15 +941,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;
@@ -962,16 +967,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()