mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-20 19:20:04 +00:00
re-added synchronization where necessary to CachedOsgiTypeBasedServiceFinder
Change-Id: I311676d36849c2a913caac3ae915abc767b4d6c7
This commit is contained in:
1 parent
cf7e6c2154
commit
d215e048bf
1 file changed
+15
-8
@@ -62,21 +62,28 @@ public class CachedOsgiTypeBasedServiceFinder<ServiceT> implements ServiceTracke
|
||||
|
||||
@Override
|
||||
public void applyServiceWhenAvailable(String type, Callback<ServiceT> callback) {
|
||||
ServiceT service = services.get(type);
|
||||
final ServiceT service;
|
||||
synchronized (services) {
|
||||
service = services.get(type);
|
||||
if (service == null) {
|
||||
Util.addToValueSet(callbacks, type, callback);
|
||||
}
|
||||
}
|
||||
// no synchronization needed here anymore if the service was already found
|
||||
if (service != null) {
|
||||
callback.withService(service);
|
||||
} else {
|
||||
Util.addToValueSet(callbacks, type, callback);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceT addingService(ServiceReference<ServiceT> reference) {
|
||||
String type = (String) reference.getProperty(TypeBasedServiceFinder.TYPE);
|
||||
ServiceT service = context.getService(reference);
|
||||
Set<Callback<ServiceT>> callbacksToNotify;
|
||||
services.put(type, service);
|
||||
callbacksToNotify = callbacks.remove(type);
|
||||
final String type = (String) reference.getProperty(TypeBasedServiceFinder.TYPE);
|
||||
final ServiceT service = context.getService(reference);
|
||||
final Set<Callback<ServiceT>> callbacksToNotify;
|
||||
synchronized (services) {
|
||||
services.put(type, service);
|
||||
callbacksToNotify = callbacks.remove(type);
|
||||
}
|
||||
if (callbacksToNotify != null) {
|
||||
callbacksToNotify.forEach(c -> {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user