Skip to content

Commit

Permalink
Do a deep copy on observers
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2305 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Apr 5, 2009
1 parent 85bdd02 commit acae34d
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 1 deletion.
2 changes: 1 addition & 1 deletion impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -188,7 +188,7 @@ public static ManagerImpl newChildManager(ManagerImpl parentManager)
beans.addAll(parentManager.getBeans());

ConcurrentSetMultiMap<Type, EventObserver<?>> registeredObservers = new ConcurrentSetHashMultiMap<Type, EventObserver<?>>();
registeredObservers.putAll(parentManager.getRegisteredObservers());
registeredObservers.deepPutAll(parentManager.getRegisteredObservers());
Namespace rootNamespace = new Namespace(parentManager.getRootNamespace());

return new ManagerImpl(
Expand Down
Expand Up @@ -16,6 +16,7 @@
*/
package org.jboss.webbeans.util.collections;

import java.util.Collection;
import java.util.concurrent.CopyOnWriteArrayList;

/**
Expand All @@ -38,5 +39,22 @@ public static <E> ConcurrentList<E> emptyList()
}

private static final long serialVersionUID = -7489797765014324457L;

public ConcurrentList()
{
super();
}

public ConcurrentList(Collection<? extends E> collection)
{
super(collection);
}

public ConcurrentList(E[] array)
{
super(array);
}



}
Expand Up @@ -16,6 +16,7 @@
*/
package org.jboss.webbeans.util.collections.multi;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

Expand Down Expand Up @@ -49,6 +50,14 @@ protected ConcurrentMap<K, ConcurrentList<V>> delegate()
{
return delegate;
}

public void deepPutAll(Map<? extends K, ? extends ConcurrentList<V>> map)
{
for (Entry<? extends K, ? extends ConcurrentList<V>> entry : map.entrySet())
{
put(entry.getKey(), new ConcurrentList<V>(entry.getValue()));
}
}

/**
* Gets the list of values for a given key
Expand Down
Expand Up @@ -16,6 +16,7 @@
*/
package org.jboss.webbeans.util.collections.multi;

import java.util.Map;
import java.util.concurrent.ConcurrentMap;

import org.jboss.webbeans.util.collections.ConcurrentList;
Expand All @@ -37,4 +38,12 @@ public interface ConcurrentListMultiMap<K, V> extends ConcurrentMap<K, Concurren
*/
public void put(K key, V value);

/**
* Put all the data in the map into this map, copying each multi-value, not
* just attaching the existing multi-value
*
* @param map the map to copy
*/
public void deepPutAll(Map<? extends K, ? extends ConcurrentList<V>> map);

}
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -44,6 +45,14 @@ public ConcurrentSetHashMultiMap()
{
delegate = new ConcurrentHashMap<K, Set<V>>();
}

public void deepPutAll(Map<? extends K, ? extends Set<V>> map)
{
for (Entry<? extends K, ? extends Set<V>> entry : map.entrySet())
{
put(entry.getKey(), new CopyOnWriteArraySet<V>(entry.getValue()));
}
}

@Override
protected ConcurrentMap<K, Set<V>> delegate()
Expand Down
Expand Up @@ -16,6 +16,7 @@
*/
package org.jboss.webbeans.util.collections.multi;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;

Expand All @@ -37,5 +38,13 @@ public interface ConcurrentSetMultiMap<K, V> extends ConcurrentMap<K, Set<V>>
* @param value the value to add
*/
public void put(K key, V value);

/**
* Put all the data in the map into this map, copying each multi-value, not
* just attaching the existing multi-value
*
* @param map the map to copy
*/
public void deepPutAll(Map<? extends K, ? extends Set<V>> map);

}
Expand Up @@ -50,6 +50,14 @@ protected Map<K, List<V>> delegate()
{
return delegate;
}

public void deepPutAll(Map<? extends K, ? extends List<V>> map)
{
for (Entry<? extends K, ? extends List<V>> entry : map.entrySet())
{
put(entry.getKey(), new ArrayList<V>(entry.getValue()));
}
}

/**
* Gets the list of values for a given key
Expand Down
Expand Up @@ -35,4 +35,12 @@ public interface ListMultiMap<K, V> extends Map<K, List<V>>
*/
public void put(K key, V value);

/**
* Put all the data in the map into this map, copying each multi-value, not
* just attaching the existing multi-value
*
* @param map the map to copy
*/
public void deepPutAll(Map<? extends K, ? extends List<V>> map);

}
Expand Up @@ -50,6 +50,14 @@ protected Map<K, Set<V>> delegate()
{
return delegate;
}

public void deepPutAll(Map<? extends K, ? extends Set<V>> map)
{
for (Entry<? extends K, ? extends Set<V>> entry : map.entrySet())
{
put(entry.getKey(), new HashSet<V>(entry.getValue()));
}
}

/**
* Gets the list of values for a given key
Expand Down
Expand Up @@ -37,4 +37,12 @@ public interface SetMultiMap<K, V> extends Map<K, Set<V>>
*/
public void put(K key, V value);

/**
* Put all the data in the map into this map, copying each multi-value, not
* just attaching the existing multi-value
*
* @param map the map to copy
*/
public void deepPutAll(Map<? extends K, ? extends Set<V>> map);

}

0 comments on commit acae34d

Please sign in to comment.