You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2021/12/07 11:21:09 UTC
[sling-org-apache-sling-testing-osgi-mock] 02/02: ensure generated service IDs are unique accross threads
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch experimental/WTES-69-diagnosis
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git
commit 142b2c7bf0bab8c42d3e1a6218dd5cdf338b5a85
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Tue Dec 7 12:20:35 2021 +0100
ensure generated service IDs are unique accross threads
---
.../org/apache/sling/testing/mock/osgi/MockServiceRegistration.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
index 2294611..96ecc7d 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
@@ -25,6 +25,7 @@ import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.framework.FilterImpl;
@@ -51,10 +52,12 @@ class MockServiceRegistration<T> implements ServiceRegistration<T>, Comparable<M
private final ServiceReference<T> serviceReference;
private final MockBundleContext bundleContext;
+ private static final AtomicLong SERVICE_ID_COUNTER = new AtomicLong();
+
@SuppressWarnings("unchecked")
public MockServiceRegistration(final Bundle bundle, final String[] clazzes, final T service,
final Dictionary<String, Object> properties, MockBundleContext bundleContext) {
- this.serviceId = ++serviceCounter;
+ this.serviceId = SERVICE_ID_COUNTER.incrementAndGet();
this.clazzes = new HashSet<String>(Arrays.asList(clazzes));
if (service instanceof ServiceFactory) {