summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service')
-rw-r--r--sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/AbstractDiscoveryService.java8
-rw-r--r--sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java52
-rw-r--r--sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java4
3 files changed, 20 insertions, 44 deletions
diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/AbstractDiscoveryService.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/AbstractDiscoveryService.java
index 4bbf130c74..886e79197d 100644
--- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/AbstractDiscoveryService.java
+++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/AbstractDiscoveryService.java
@@ -64,7 +64,7 @@ public abstract class AbstractDiscoveryService implements Discovery, LifeCycleLi
private Map<String, List<EndpointListener>> filtersToListeners = new HashMap<String, List<EndpointListener>>();
// this is effectively a set which allows for multiple service descriptions with the
// same interface name but different properties and takes care of itself with respect to concurrency
- protected Map<EndpointDescription, Bundle> servicesInfo = new ConcurrentHashMap<EndpointDescription, Bundle>();
+ protected Map<EndpointDescription, Bundle> endpointDescriptions = new ConcurrentHashMap<EndpointDescription, Bundle>();
private Map<EndpointListener, Collection<String>> listenersToFilters =
new HashMap<EndpointListener, Collection<String>>();
private ServiceTracker trackerTracker;
@@ -176,7 +176,7 @@ public abstract class AbstractDiscoveryService implements Discovery, LifeCycleLi
}
if (logger.isLoggable(Level.FINE)) {
- if (servicesInfo.size() > 0) {
+ if (endpointDescriptions.size() > 0) {
logger.fine("search for matches to trigger callbacks with delta: " + deltaInterest);
} else {
logger.fine("nothing to search for matches to trigger callbacks with delta: " + deltaInterest);
@@ -185,7 +185,7 @@ public abstract class AbstractDiscoveryService implements Discovery, LifeCycleLi
Iterator<String> i = deltaInterest.iterator();
while (i.hasNext()) {
String next = i.next();
- for (EndpointDescription sd : servicesInfo.keySet()) {
+ for (EndpointDescription sd : endpointDescriptions.keySet()) {
triggerCallbacks(listener, next, sd, ADDED);
}
}
@@ -267,7 +267,7 @@ public abstract class AbstractDiscoveryService implements Discovery, LifeCycleLi
return collection;
}
- protected void endpointChanged(EndpointDescription sd, int type) {
+ protected synchronized void endpointChanged(EndpointDescription sd, int type) {
for (Map.Entry<EndpointListener, Collection<String>> entry : listenersToFilters.entrySet()) {
for (String filter : entry.getValue()) {
if (filterMatches(filter, sd)) {
diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java
index a7c6d04ee9..a02be672a2 100644
--- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java
+++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java
@@ -65,7 +65,7 @@ public class DomainDiscoveryService extends AbstractDiscoveryService implements
thread.start();
}
- private void startEndpointRegistry() {
+ private synchronized void startEndpointRegistry() {
// The following code forced the start() of the domain registry in absense of services
String domainRegistry = context.getProperty("org.osgi.sca.domain.registry");
if (domainRegistry == null) {
@@ -80,7 +80,7 @@ public class DomainDiscoveryService extends AbstractDiscoveryService implements
}
}
- public void endpointAdded(Endpoint endpoint) {
+ public synchronized void endpointAdded(Endpoint endpoint) {
Implementation impl = endpoint.getComponent().getImplementation();
if (!(impl instanceof OSGiImplementation)) {
return;
@@ -94,59 +94,35 @@ public class DomainDiscoveryService extends AbstractDiscoveryService implements
bundleContext = bundle != null ? bundle.getBundleContext() : null;
}
- /*
- if (!endpoint.isRemote()) {
- Interface intf = endpoint.getService().getInterfaceContract().getInterface();
- JavaInterface javaInterface = (JavaInterface)intf;
- // String filter = getOSGiFilter(provider.getOSGiProperties(service));
- // FIXME: What is the filter?
- String filter = "(!(sca.reference=*))";
- // "(sca.service=" + component.getURI() + "#service-name\\(" + service.getName() + "\\))";
- ServiceReference ref = null;
- try {
- ref = bundleContext.getServiceReferences(javaInterface.getName(), filter)[0];
- } catch (InvalidSyntaxException e) {
- // Ignore
- }
- if (ref != null) {
-
- }
- } else
- */
- {
// Notify the endpoint listeners
EndpointDescription description = createEndpointDescription(bundleContext, endpoint);
// Set the owning bundle to runtime bundle to avoid NPE
- servicesInfo.put(description, context.getBundle());
+ endpointDescriptions.put(description, context.getBundle());
endpointChanged(description, ADDED);
- }
}
- public void endpointRemoved(Endpoint endpoint) {
- /*
- if (!endpoint.isRemote()) {
- // export services
- } else
- */
- {
+ public synchronized void endpointRemoved(Endpoint endpoint) {
EndpointDescription description = createEndpointDescription(context, endpoint);
- servicesInfo.remove(description);
+ endpointDescriptions.remove(description);
endpointChanged(description, REMOVED);
- }
}
- public void endpointUpdated(Endpoint oldEndpoint, Endpoint newEndpoint) {
+ public synchronized void endpointUpdated(Endpoint oldEndpoint, Endpoint newEndpoint) {
// FIXME: This is a quick and dirty way for the update
endpointRemoved(oldEndpoint);
endpointAdded(newEndpoint);
}
public void stop() {
- domainRegistryFactory.removeListener(this);
- if (endpointRegistry instanceof LifeCycleListener) {
- ((LifeCycleListener)endpointRegistry).stop();
+ if (domainRegistryFactory != null) {
+ domainRegistryFactory.removeListener(this);
+ if (endpointRegistry instanceof LifeCycleListener) {
+ ((LifeCycleListener)endpointRegistry).stop();
+ }
+ domainRegistryFactory = null;
+ endpointRegistry = null;
+ super.stop();
}
- super.stop();
}
@Override
diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java
index a4c9414b92..56a830a1e6 100644
--- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java
+++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java
@@ -105,7 +105,7 @@ public class LocalDiscoveryService extends AbstractDiscoveryService implements B
}
private void removeServicesDeclaredInBundle(Bundle bundle) {
- for (Iterator<Map.Entry<EndpointDescription, Bundle>> i = servicesInfo.entrySet().iterator(); i.hasNext();) {
+ for (Iterator<Map.Entry<EndpointDescription, Bundle>> i = endpointDescriptions.entrySet().iterator(); i.hasNext();) {
Entry<EndpointDescription, Bundle> entry = i.next();
if (entry.getValue().equals(bundle)) {
serviceDescriptionRemoved(entry.getKey());
@@ -163,7 +163,7 @@ public class LocalDiscoveryService extends AbstractDiscoveryService implements B
for (ServiceDescriptions sds : extender.getRemoteServiceDescriptions()) {
for (ServiceDescription sd : sds) {
EndpointDescription sed = createEndpointDescription(sd);
- servicesInfo.put(sed, bundle);
+ endpointDescriptions.put(sed, bundle);
serviceDescriptionAdded(sed);
}
}