This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.testing.osgi-mock-1.5.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git
commit 64dc2d084b4c0ab45fb206fe3d0aceafc7bd3afc Author: Julian Sedding <[email protected]> AuthorDate: Mon Jun 29 18:11:57 2015 +0000 SLING-4845 - MockBundleContext is not thread-safe git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1688279 13f79535-47bb-0310-9956-ffa450edef68 --- .../sling/testing/mock/osgi/MockBundleContext.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java index 540babb..e37f8e9 100644 --- a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java +++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java @@ -23,12 +23,12 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Dictionary; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.lang3.StringUtils; import org.apache.felix.framework.FilterImpl; @@ -47,19 +47,26 @@ import org.osgi.framework.ServiceFactory; import org.osgi.framework.ServiceListener; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.common.collect.ImmutableList; +import static java.util.Collections.synchronizedList; +import static java.util.Collections.synchronizedSortedSet; + /** * Mock {@link BundleContext} implementation. */ class MockBundleContext implements BundleContext { + private static final Logger LOG = LoggerFactory.getLogger(MockBundleContext.class); + private final MockBundle bundle; - private final SortedSet<MockServiceRegistration> registeredServices = new TreeSet<MockServiceRegistration>(); - private final Map<ServiceListener, Filter> serviceListeners = new HashMap<ServiceListener, Filter>(); - private final List<BundleListener> bundleListeners = new ArrayList<BundleListener>(); - + private final SortedSet<MockServiceRegistration> registeredServices = synchronizedSortedSet(new TreeSet<MockServiceRegistration>()); + private final Map<ServiceListener, Filter> serviceListeners = new ConcurrentHashMap<ServiceListener, Filter>(); + private final List<BundleListener> bundleListeners = synchronizedList(new ArrayList<BundleListener>()); + public MockBundleContext() { this.bundle = new MockBundle(this); } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
