Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/META-INF/MANIFEST.MF1
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/OSGI-INF/eventhookcomponent.xml2
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java14
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerComponent.java8
-rw-r--r--compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerImpl.java8
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractTopologyManager.java246
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java16
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionAdvertiser.java16
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java42
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java80
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdminEvent.java46
11 files changed, 196 insertions, 283 deletions
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/META-INF/MANIFEST.MF b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/META-INF/MANIFEST.MF
index b759db01b..e62512352 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/META-INF/MANIFEST.MF
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/META-INF/MANIFEST.MF
@@ -10,6 +10,7 @@ Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
Import-Package: org.eclipse.ecf.core.util,
org.osgi.framework;version="1.3.0",
org.osgi.framework.hooks.service;version="1.0.0",
+ org.osgi.service.event;version="1.3.0",
org.osgi.service.log;version="1.3.0",
org.osgi.service.remoteserviceadmin;version="1.0",
org.osgi.util.tracker
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/OSGI-INF/eventhookcomponent.xml b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/OSGI-INF/eventhookcomponent.xml
index 348301167..6ff7e5d2c 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/OSGI-INF/eventhookcomponent.xml
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/OSGI-INF/eventhookcomponent.xml
@@ -3,6 +3,8 @@
<implementation class="org.eclipse.ecf.internal.osgi.services.distribution.BasicTopologyManagerComponent"/>
<service>
<provide interface="org.osgi.framework.hooks.service.EventHook"/>
+ <provide interface="org.osgi.service.event.EventHandler"/>
</service>
<reference bind="bindEndpointListener" cardinality="1..n" interface="org.osgi.service.remoteserviceadmin.EndpointListener" name="EndpointListener" policy="static" unbind="unbindEndpointListener"/>
+ <property name="event.topics" type="String" value="org/osgi/service/remoteserviceadmin/*"/>
</scr:component>
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java
index 83535b505..f81a485ab 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java
@@ -20,6 +20,8 @@ import org.osgi.framework.Filter;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.service.EventHook;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
import org.osgi.service.log.LogService;
import org.osgi.service.remoteserviceadmin.EndpointListener;
import org.osgi.util.tracker.ServiceTracker;
@@ -62,6 +64,7 @@ public class Activator implements BundleActivator {
private ServiceRegistration endpointListenerReg;
private BasicTopologyManagerComponent basicTopologyManagerComp;
private ServiceRegistration eventHookRegistration;
+ private ServiceRegistration eventHandlerRegistration;
public static Activator getDefault() {
return plugin;
@@ -179,6 +182,13 @@ public class Activator implements BundleActivator {
basicTopologyManagerComp = new BasicTopologyManagerComponent();
// bind the topology manager to it
basicTopologyManagerComp.bindEndpointListener(basicTopologyManagerImpl);
+ // Register EventHandler for rsa
+ Properties eventHandlerProps = new Properties();
+ String[] rsaTopics = new String[] { "org/osgi/service/remoteserviceadmin/*" }; //$NON-NLS-1$
+ eventHandlerProps.put(EventConstants.EVENT_TOPIC, rsaTopics);
+ eventHandlerRegistration = this.context.registerService(
+ EventHandler.class, basicTopologyManagerComp,
+ (Dictionary) eventHandlerProps);
// register the basic topology manager as EventHook service
eventHookRegistration = this.context.registerService(EventHook.class,
basicTopologyManagerComp, null);
@@ -206,6 +216,10 @@ public class Activator implements BundleActivator {
endpointListenerReg.unregister();
endpointListenerReg = null;
}
+ if (eventHandlerRegistration != null) {
+ eventHandlerRegistration.unregister();
+ eventHandlerRegistration = null;
+ }
if (basicTopologyManagerImpl != null) {
basicTopologyManagerImpl.close();
basicTopologyManagerImpl = null;
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerComponent.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerComponent.java
index 7b4e7e9d7..d2fbe2bd2 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerComponent.java
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerComponent.java
@@ -3,9 +3,11 @@ package org.eclipse.ecf.internal.osgi.services.distribution;
import java.util.Collection;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.hooks.service.EventHook;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventHandler;
import org.osgi.service.remoteserviceadmin.EndpointListener;
-public class BasicTopologyManagerComponent implements EventHook {
+public class BasicTopologyManagerComponent implements EventHook, EventHandler {
private boolean exportRegisteredSvcs = new Boolean(
System.getProperty(
@@ -40,4 +42,8 @@ public class BasicTopologyManagerComponent implements EventHook {
basicTopologyManagerImpl.event(event, contexts);
}
+ public void handleEvent(Event event) {
+ basicTopologyManagerImpl.handleEvent(event);
+ }
+
}
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerImpl.java
index 89c78345d..83aef85d1 100644
--- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerImpl.java
+++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerImpl.java
@@ -6,10 +6,12 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventHandler;
import org.osgi.service.remoteserviceadmin.EndpointListener;
public class BasicTopologyManagerImpl extends AbstractTopologyManager implements
- EndpointListener {
+ EndpointListener, EventHandler {
BasicTopologyManagerImpl(BundleContext context) {
super(context);
@@ -88,4 +90,8 @@ public class BasicTopologyManagerImpl extends AbstractTopologyManager implements
handleEvent(event, contexts);
}
+ public void handleEvent(Event event) {
+ handleRSAEvent(event);
+ }
+
}
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractTopologyManager.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractTopologyManager.java
index 7b84f70ce..9be888c86 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractTopologyManager.java
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractTopologyManager.java
@@ -9,10 +9,7 @@
******************************************************************************/
package org.eclipse.ecf.osgi.services.remoteserviceadmin;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -22,13 +19,15 @@ import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.Activator;
import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.DebugOptions;
import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.LogUtility;
import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.PropertiesUtil;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.remoteserviceadmin.ExportRegistration;
+import org.osgi.service.event.Event;
import org.osgi.service.remoteserviceadmin.ImportRegistration;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
import org.osgi.util.tracker.ServiceTracker;
/**
@@ -53,10 +52,6 @@ public abstract class AbstractTopologyManager {
private ServiceTracker remoteServiceAdminTracker;
private Object remoteServiceAdminTrackerLock = new Object();
- protected Collection<org.osgi.service.remoteserviceadmin.ExportRegistration> exportedRegistrations = new ArrayList<org.osgi.service.remoteserviceadmin.ExportRegistration>();
-
- protected Collection<org.osgi.service.remoteserviceadmin.ImportRegistration> importedRegistrations = new ArrayList<org.osgi.service.remoteserviceadmin.ImportRegistration>();
-
public AbstractTopologyManager(BundleContext context) {
this.context = context;
}
@@ -102,12 +97,6 @@ public abstract class AbstractTopologyManager {
remoteServiceAdminTracker = null;
}
}
- synchronized (exportedRegistrations) {
- exportedRegistrations.clear();
- }
- synchronized (importedRegistrations) {
- importedRegistrations.clear();
- }
context = null;
}
@@ -209,48 +198,20 @@ public abstract class AbstractTopologyManager {
protected void handleEndpointAdded(
org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription,
String matchedFilter) {
-
if (!(endpointDescription instanceof org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription))
- handleOSGiEndpointAdded(endpointDescription, matchedFilter);
+ handleNonECFEndpointAdded(endpointDescription, matchedFilter);
else {
// First, select importing remote service admin
- org.osgi.service.remoteserviceadmin.RemoteServiceAdmin rsa = getRemoteServiceAdmin();
-
- if (rsa == null) {
- logError("handleEndpointAdded", //$NON-NLS-1$
- "RemoteServiceAdmin not found for importing endpointDescription=" //$NON-NLS-1$
- + endpointDescription);
- return;
- }
-
trace("handleEndpointAdded", "endpointDescription=" //$NON-NLS-1$ //$NON-NLS-2$
- + endpointDescription + " rsa=" + rsa); //$NON-NLS-1$
-
- // now call rsa.import
- org.osgi.service.remoteserviceadmin.ImportRegistration importRegistration = rsa
- .importService(endpointDescription);
-
- if (importRegistration == null) {
- logError("handleEndpointAdded", //$NON-NLS-1$
- "Import registration is null for endpointDescription=" //$NON-NLS-1$
- + endpointDescription + " and rsa=" + rsa); //$NON-NLS-1$
- } else {
- Throwable t = importRegistration.getException();
- if (t != null)
- handleInvalidImportRegistration(importRegistration, t);
- else {
- synchronized (importedRegistrations) {
- importedRegistrations.add(importRegistration);
- }
- }
- }
+ + endpointDescription);
+ getRemoteServiceAdmin().importService(endpointDescription);
}
}
/**
* @since 3.0
*/
- protected void handleOSGiEndpointAdded(
+ protected void handleNonECFEndpointAdded(
org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription,
String matchedFilter) {
@@ -301,18 +262,28 @@ public abstract class AbstractTopologyManager {
org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription,
String matchedFilter) {
if (!(endpointDescription instanceof org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription))
- handleOSGiEndpointRemoved(endpointDescription, matchedFilter);
+ handleNonECFEndpointRemoved(endpointDescription, matchedFilter);
else {
trace("handleEndpointRemoved", "endpointDescription=" //$NON-NLS-1$ //$NON-NLS-2$
+ endpointDescription);
- unimportService(endpointDescription);
+ RemoteServiceAdmin rsa = (RemoteServiceAdmin) getRemoteServiceAdmin();
+ List<RemoteServiceAdmin.ImportRegistration> importedRegistrations = rsa
+ .getImportedRegistrations();
+ org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription ed = (org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription) endpointDescription;
+ for (RemoteServiceAdmin.ImportRegistration importedRegistration : importedRegistrations) {
+ if (importedRegistration.match(ed)) {
+ trace("handleEndpointRemoved", "closing importedRegistration=" //$NON-NLS-1$ //$NON-NLS-2$
+ + importedRegistration);
+ importedRegistration.close();
+ }
+ }
}
}
/**
* @since 3.0
*/
- protected void handleOSGiEndpointRemoved(
+ protected void handleNonECFEndpointRemoved(
org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription,
String matchedFilter) {
IEndpointDescriptionAdvertiser advertiser = getEndpointDescriptionAdvertiser(endpointDescription);
@@ -343,18 +314,6 @@ public abstract class AbstractTopologyManager {
if (exportedInterfaces == null)
return;
- // Select remote service admin
- org.osgi.service.remoteserviceadmin.RemoteServiceAdmin rsa = getRemoteServiceAdmin();
-
- // if no remote service admin available, then log error and return
- if (rsa == null) {
- logError("handleServiceRegistered", //$NON-NLS-1$
- "No RemoteServiceAdmin found for serviceReference=" //$NON-NLS-1$
- + serviceReference
- + ". Remote service NOT EXPORTED"); //$NON-NLS-1$
- return;
- }
-
// prepare export properties
Map<String, Object> exportProperties = new TreeMap<String, Object>(
String.CASE_INSENSITIVE_ORDER);
@@ -363,135 +322,62 @@ public abstract class AbstractTopologyManager {
exportedInterfaces);
trace("handleServiceRegistering", "serviceReference=" //$NON-NLS-1$ //$NON-NLS-2$
+ serviceReference + " exportProperties=" + exportProperties); //$NON-NLS-1$
- Collection<org.osgi.service.remoteserviceadmin.ExportRegistration> registrations = rsa
- .exportService(serviceReference, exportProperties);
-
- if (registrations == null || registrations.size() == 0) {
- logError("handleServiceRegistered", //$NON-NLS-1$
- "No export registrations created by RemoteServiceAdmin=" //$NON-NLS-1$
- + rsa + ". ServiceReference=" + serviceReference //$NON-NLS-1$
- + " NOT EXPORTED"); //$NON-NLS-1$
- return;
- }
-
- List<EndpointDescription> endpointDescriptions = new ArrayList<EndpointDescription>();
-
- for (org.osgi.service.remoteserviceadmin.ExportRegistration exportRegistration : registrations) {
- // If they are invalid report as such
- Throwable t = exportRegistration.getException();
- if (t != null)
- handleInvalidExportRegistration(exportRegistration, t);
- else {
- endpointDescriptions
- .add((EndpointDescription) exportRegistration
- .getExportReference().getExportedEndpoint());
- synchronized (exportedRegistrations) {
- exportedRegistrations.add(exportRegistration);
- }
- }
- }
- // advertise valid exported registrations
- advertiseEndpointDescriptions(endpointDescriptions);
- }
-
- protected void advertiseEndpointDescriptions(
- List<EndpointDescription> endpointDescriptions) {
- for (EndpointDescription ed : endpointDescriptions)
- advertiseEndpointDescription(ed);
- }
-
- protected void handleInvalidExportRegistration(
- ExportRegistration exportRegistration, Throwable t) {
- logError("handleInvalidExportRegistration", "exportRegistration=" //$NON-NLS-1$ //$NON-NLS-2$
- + exportRegistration, t);
+ // Do the export with RSA
+ getRemoteServiceAdmin().exportService(serviceReference,
+ exportProperties);
}
protected void handleServiceModifying(ServiceReference serviceReference) {
}
protected void handleServiceUnregistering(ServiceReference serviceReference) {
- Collection<EndpointDescription> endpointDescriptions = unexportService(serviceReference);
- if (endpointDescriptions != null)
- for (EndpointDescription ed : endpointDescriptions)
- unadvertiseEndpointDescription(ed);
- }
-
- protected Collection<EndpointDescription> unexportService(
- ServiceReference serviceReference) {
- Map<org.osgi.service.remoteserviceadmin.ExportRegistration, EndpointDescription> matchingExportRegistrations = null;
- synchronized (exportedRegistrations) {
- for (Iterator<org.osgi.service.remoteserviceadmin.ExportRegistration> i = exportedRegistrations
- .iterator(); i.hasNext();) {
- if (matchingExportRegistrations == null)
- matchingExportRegistrations = new HashMap<org.osgi.service.remoteserviceadmin.ExportRegistration, EndpointDescription>();
- org.osgi.service.remoteserviceadmin.ExportRegistration exportRegistration = i
- .next();
- // Only check valid registrations (no exceptions)
- if (exportRegistration.getException() == null) {
- org.osgi.service.remoteserviceadmin.ExportReference exportRef = exportRegistration
- .getExportReference();
- if (exportRef != null) {
- ServiceReference exportReference = exportRef
- .getExportedService();
- if (exportReference != null
- && serviceReference.equals(exportReference)) {
- matchingExportRegistrations.put(exportRegistration,
- (EndpointDescription) exportRef
- .getExportedEndpoint());
- i.remove();
- }
- }
- }
+ List<RemoteServiceAdmin.ExportRegistration> exportedRegistrations = ((RemoteServiceAdmin) getRemoteServiceAdmin())
+ .getExportedRegistrations();
+ for (RemoteServiceAdmin.ExportRegistration exportedRegistration : exportedRegistrations) {
+ if (exportedRegistration.match(serviceReference)) {
+ trace("handleServiceUnregistering", "closing exportRegistration for serviceReference=" //$NON-NLS-1$ //$NON-NLS-2$
+ + serviceReference);
+ exportedRegistration.close();
}
}
- // If no matching export registrations then we return null and are done
- if (matchingExportRegistrations == null
- || matchingExportRegistrations.size() == 0)
- return null;
- // We close all matching export registrations
- for (Iterator<org.osgi.service.remoteserviceadmin.ExportRegistration> i = matchingExportRegistrations
- .keySet().iterator(); i.hasNext();) {
- org.osgi.service.remoteserviceadmin.ExportRegistration exportRegistration = i
- .next();
- trace("unexportService", "closing exportRegistration=" //$NON-NLS-1$ //$NON-NLS-2$
- + exportRegistration);
- exportRegistration.close();
- }
- // And return endpointDescriptions for matching registrations
- return matchingExportRegistrations.values();
}
- protected void unimportService(
- org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) {
- List<org.osgi.service.remoteserviceadmin.ImportRegistration> removedRegistrations = null;
- synchronized (importedRegistrations) {
- for (Iterator<org.osgi.service.remoteserviceadmin.ImportRegistration> i = importedRegistrations
- .iterator(); i.hasNext();) {
- if (removedRegistrations == null)
- removedRegistrations = new ArrayList<org.osgi.service.remoteserviceadmin.ImportRegistration>();
- org.osgi.service.remoteserviceadmin.ImportRegistration importRegistration = i
- .next();
- if (importRegistration.getException() == null) {
- org.osgi.service.remoteserviceadmin.ImportReference importRef = importRegistration
- .getImportReference();
- if (importRef != null) {
- org.osgi.service.remoteserviceadmin.EndpointDescription ed = importRef
- .getImportedEndpoint();
- if (ed != null && ed.isSameService(endpointDescription)) {
- removedRegistrations.add(importRegistration);
- i.remove();
- }
- }
- }
- }
+ /**
+ * @since 3.0
+ */
+ protected void handleRSAEvent(Event event) {
+ Object o = event.getProperty("bundle"); //$NON-NLS-1$
+ if (o == null || !(o instanceof Bundle))
+ return;
+ Bundle b = (Bundle) o;
+ if (b.getSymbolicName().equals(
+ "org.eclipse.ecf.osgi.services.remoteservices"))return; //$NON-NLS-1$
+ RemoteServiceAdmin.RemoteServiceAdminEvent rsaEvent = (RemoteServiceAdmin.RemoteServiceAdminEvent) event
+ .getProperty("event"); //$NON-NLS-1$
+ if (rsaEvent == null)
+ return;
+ int eventType = rsaEvent.getType();
+ RemoteServiceAdmin.RemoteServiceAdminEvent rsaEvent1 = (RemoteServiceAdmin.RemoteServiceAdminEvent) rsaEvent;
+ switch (eventType) {
+ case RemoteServiceAdminEvent.EXPORT_REGISTRATION:
+ advertiseEndpointDescription(rsaEvent1.getEndpointDescription());
+ break;
+ case RemoteServiceAdminEvent.EXPORT_UNREGISTRATION:
+ unadvertiseEndpointDescription(rsaEvent1.getEndpointDescription());
+ break;
+ case RemoteServiceAdminEvent.EXPORT_ERROR:
+ logError(
+ "handleExportError", "Export error with event=" + rsaEvent1); //$NON-NLS-1$ //$NON-NLS-2$
+ break;
+ case RemoteServiceAdminEvent.IMPORT_REGISTRATION:
+ break;
+ case RemoteServiceAdminEvent.IMPORT_UNREGISTRATION:
+ break;
+ case RemoteServiceAdminEvent.IMPORT_ERROR:
+ break;
+ default:
+ logWarning(
+ "handleRemoteAdminEvent", "RemoteServiceAdminEvent=" + rsaEvent + " received with unrecognized type"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- // Now close all of them
- if (removedRegistrations != null)
- for (org.osgi.service.remoteserviceadmin.ImportRegistration removedReg : removedRegistrations) {
- trace("unimportService", "closing importRegistration=" //$NON-NLS-1$ //$NON-NLS-2$
- + removedReg);
- removedReg.close();
- }
}
-
}
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java
index e30a4134e..2ed980271 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java
@@ -10,7 +10,6 @@
package org.eclipse.ecf.osgi.services.remoteserviceadmin;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -225,13 +224,6 @@ public class EndpointDescription extends
.getFrameworkUUID()));
}
- public String toString() {
- return "EndpointDescription[containerID=" + containerID //$NON-NLS-1$
- + ",connectTargetID=" + connectTargetID + ",idFilter=" //$NON-NLS-1$ //$NON-NLS-2$
- + Arrays.toString(idFilter) + ",rsFilter=" + rsFilter //$NON-NLS-1$
- + ",properties=" + getProperties() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
void setPropertiesOverrides(Map propertiesOverrides) {
this.overrides = PropertiesUtil.mergeProperties(super.getProperties(),
propertiesOverrides);
@@ -249,4 +241,12 @@ public class EndpointDescription extends
return overrides;
return super.getProperties();
}
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer("ECFEndpointDescription["); //$NON-NLS-1$
+ sb.append("id").append(getId()); //$NON-NLS-1$
+ sb.append(";endpoint.service.id=").append(getServiceId()); //$NON-NLS-1$
+ sb.append(";frameworkid=").append(getFrameworkUUID()).append("]"); //$NON-NLS-1$//$NON-NLS-2$
+ return sb.toString();
+ }
}
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionAdvertiser.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionAdvertiser.java
index 3ccbcfeb1..edd310c9e 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionAdvertiser.java
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionAdvertiser.java
@@ -19,6 +19,8 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
import org.eclipse.ecf.discovery.IServiceInfo;
import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.Activator;
+import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.DebugOptions;
+import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.LogUtility;
/**
* Default implementation of {@link IEndpointDescriptionAdvertiser}.
@@ -44,13 +46,23 @@ public class EndpointDescriptionAdvertiser implements
/**
* @since 3.0
*/
+ protected void trace(String methodName, String message) {
+ LogUtility.trace(methodName, DebugOptions.ENDPOINT_DESCRIPTION_ADVERTISER, this.getClass(), message);
+ }
+
+ /**
+ * @since 3.0
+ */
protected IStatus doDiscovery(IDiscoveryAdvertiser discoveryAdvertiser,
IServiceInfo serviceInfo, boolean advertise) {
try {
- if (advertise)
+ if (advertise) {
+ trace("doDiscovery","discoveryAdvertiser="+discoveryAdvertiser+" serviceInfo="+serviceInfo); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
discoveryAdvertiser.registerService(serviceInfo);
- else
+ } else {
+ trace("doUndiscovery","discoveryAdvertiser="+discoveryAdvertiser+" serviceInfo="+serviceInfo); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
discoveryAdvertiser.unregisterService(serviceInfo);
+ }
return Status.OK_STATUS;
} catch (Exception e) {
return createErrorStatus((advertise ? "registerService" //$NON-NLS-1$
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java
index 94222418f..3aed23234 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionLocator.java
@@ -337,6 +337,7 @@ public class EndpointDescriptionLocator {
advertiserTracker = null;
}
}
+ this.serviceIDs.clear();
this.executor = null;
this.context = null;
}
@@ -796,6 +797,8 @@ public class EndpointDescriptionLocator {
}
}
+ private List<IServiceID> serviceIDs = new ArrayList<IServiceID>();
+
class LocatorServiceListener implements IServiceListener {
private Object listenerLock = new Object();
@@ -828,8 +831,19 @@ public class EndpointDescriptionLocator {
logInfo("handleService", "serviceInfo=" + serviceInfo //$NON-NLS-1$ //$NON-NLS-2$
+ ",discovered=" + discovered); //$NON-NLS-1$
IServiceID serviceID = serviceInfo.getServiceID();
- if (matchServiceID(serviceID))
+ if (matchServiceID(serviceID)) {
+ synchronized (serviceIDs) {
+ if (discovered) {
+ if (serviceIDs.contains(serviceID)) {
+ trace("handleService", "Found serviceInfo with same serviceID=" + serviceID + "...ignoring"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return;
+ }
+ serviceIDs.add(serviceID);
+ } else
+ serviceIDs.remove(serviceID);
+ }
handleOSGiServiceEndpoint(serviceID, serviceInfo, discovered);
+ }
}
private void handleOSGiServiceEndpoint(IServiceID serviceId,
@@ -842,20 +856,24 @@ public class EndpointDescriptionLocator {
handleEndpointDescription(
discoveredEndpointDescription.getEndpointDescription(),
discovered);
- } else {
+ } else
logWarning("handleOSGiServiceEvent", //$NON-NLS-1$
"discoveredEndpointDescription is null for service info=" //$NON-NLS-1$
+ serviceInfo + ",discovered=" + discovered); //$NON-NLS-1$
- }
}
- public void handleEndpointDescription(
+ void handleEndpointDescription(
org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription,
boolean discovered) {
synchronized (listenerLock) {
- if (discovered)
+ if (discovered) {
+ if (discoveredEndpointDescriptions
+ .contains(endpointDescription)) {
+ trace("handleEndpointDescription", "endpointDescription previously discovered...ignoring"); //$NON-NLS-1$ //$NON-NLS-2$
+ return;
+ }
discoveredEndpointDescriptions.add(endpointDescription);
- else
+ } else
discoveredEndpointDescriptions.remove(endpointDescription);
queueEndpointDescription(endpointDescription, discovered);
@@ -882,10 +900,6 @@ public class EndpointDescriptionLocator {
message);
}
- private void logError(String methodName, String message) {
- logError(methodName, message, null);
- }
-
private void logError(String methodName, String message, Throwable t) {
LogUtility.logError(methodName,
DebugOptions.ENDPOINT_DESCRIPTION_LOCATOR, this.getClass(),
@@ -898,14 +912,6 @@ public class EndpointDescriptionLocator {
// Get IEndpointDescriptionFactory
final String methodName = "getDiscoveredEndpointDescription"; //$NON-NLS-1$
IDiscoveredEndpointDescriptionFactory factory = getDiscoveredEndpointDescriptionFactory();
- if (factory == null) {
- logError(
- methodName,
- "No IEndpointDescriptionFactory found, could not create EndpointDescription for " //$NON-NLS-1$
- + (discovered ? "discovered" : "undiscovered") //$NON-NLS-1$ //$NON-NLS-2$
- + " serviceInfo=" + serviceInfo); //$NON-NLS-1$
- return null;
- }
try {
// Else get endpoint description factory to create
// EndpointDescription
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java
index 598d8e0c9..b208a4661 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java
@@ -113,6 +113,17 @@ public class RemoteServiceAdmin implements
private Collection<ExportRegistration> exportedRegistrations = new ArrayList<ExportRegistration>();
private Collection<ImportRegistration> importedRegistrations = new ArrayList<ImportRegistration>();
+ List<ExportRegistration> getExportedRegistrations() {
+ synchronized (exportedRegistrations) {
+ return new ArrayList(exportedRegistrations);
+ }
+ }
+ List<ImportRegistration> getImportedRegistrations() {
+ synchronized (importedRegistrations) {
+ return new ArrayList(importedRegistrations);
+ }
+ }
+
public RemoteServiceAdmin(Bundle clientBundle) {
this.clientBundle = clientBundle;
Assert.isNotNull(this.clientBundle);
@@ -224,15 +235,22 @@ public class RemoteServiceAdmin implements
(Map<String, Object>) overridingProperties,
exportedInterfaces, exportedConfigs, serviceIntents);
} catch (SelectContainerException e) {
+ // If exception, create error export registration
ExportRegistration errorRegistration = createErrorExportRegistration(
serviceReference,
(Map<String, Object>) overridingProperties,
"Error selecting or creating host container for serviceReference=" //$NON-NLS-1$
+ serviceReference + " properties=" //$NON-NLS-1$
+ overridingProperties, e);
+ // Add to exportedRegistrations
+ synchronized (exportedRegistrations) {
+ exportedRegistrations.add(errorRegistration);
+ }
+ // Publish export event
+ publishExportEvent(errorRegistration);
+ // Return collection
Collection<org.osgi.service.remoteserviceadmin.ExportRegistration> result = new ArrayList<org.osgi.service.remoteserviceadmin.ExportRegistration>();
result.add(errorRegistration);
- publishExportEvent(errorRegistration);
return result;
}
// If none found, log warning and return
@@ -339,7 +357,13 @@ public class RemoteServiceAdmin implements
try {
rsContainer = consumerContainerSelector.selectConsumerContainer(ed);
} catch (SelectContainerException e) {
+ // If failed, create an error ImportRegistration
ImportRegistration errorRegistration = new ImportRegistration(ed, e);
+ // Add it to the set of imported registrations
+ synchronized (importedRegistrations) {
+ importedRegistrations.add(errorRegistration);
+ }
+ // publish import event
publishImportEvent(errorRegistration);
return errorRegistration;
}
@@ -431,40 +455,26 @@ public class RemoteServiceAdmin implements
private void addImportRegistration(ImportRegistration importRegistration) {
synchronized (importedRegistrations) {
importedRegistrations.add(importRegistration);
- trace("addImportRegistration", "importRegistration=" //$NON-NLS-1$ //$NON-NLS-2$
- + importRegistration + " importedRegistrations=" //$NON-NLS-1$
- + importedRegistrations);
}
}
private void addExportRegistration(ExportRegistration exportRegistration) {
synchronized (exportedRegistrations) {
exportedRegistrations.add(exportRegistration);
- trace("addExportRegistration", "exportRegistration=" //$NON-NLS-1$ //$NON-NLS-2$
- + exportRegistration + " exportedRegistrations=" //$NON-NLS-1$
- + exportedRegistrations);
}
}
private boolean removeExportRegistration(
ExportRegistration exportRegistration) {
synchronized (exportedRegistrations) {
- boolean removed = exportedRegistrations.remove(exportRegistration);
- trace("removeExportRegistration", "exportRegistration=" //$NON-NLS-1$ //$NON-NLS-2$
- + exportRegistration + " exportedRegistrations=" //$NON-NLS-1$
- + exportedRegistrations + " removed=" + removed); //$NON-NLS-1$
- return removed;
+ return exportedRegistrations.remove(exportRegistration);
}
}
private boolean removeImportRegistration(
ImportRegistration importRegistration) {
synchronized (importedRegistrations) {
- boolean removed = importedRegistrations.remove(importRegistration);
- trace("removeImportRegistration", "importRegistration=" //$NON-NLS-1$ //$NON-NLS-2$
- + importRegistration + " importedRegistrations=" //$NON-NLS-1$
- + importedRegistrations + " removed=" + removed); //$NON-NLS-1$
- return removed;
+ return importedRegistrations.remove(importRegistration);
}
}
@@ -643,7 +653,7 @@ public class RemoteServiceAdmin implements
if (publish && rsaBundle != null)
publishEvent(new RemoteServiceAdminEvent(containerID,
RemoteServiceAdminEvent.EXPORT_UNREGISTRATION,
- rsaBundle, exportReference, exception),
+ rsaBundle, exportReference, exception, endpointDescription),
endpointDescription);
}
@@ -831,7 +841,11 @@ public class RemoteServiceAdmin implements
boolean match(IRemoteServiceID remoteServiceID) {
return importReference.match(remoteServiceID);
}
-
+
+ boolean match(EndpointDescription ed) {
+ return (getImportEndpoint(ed) != null);
+ }
+
ImportEndpoint getImportEndpoint(EndpointDescription ed) {
return importReference.match(ed);
}
@@ -862,7 +876,7 @@ public class RemoteServiceAdmin implements
if (publish && rsaBundle != null)
publishEvent(new RemoteServiceAdminEvent(containerID,
RemoteServiceAdminEvent.IMPORT_UNREGISTRATION,
- rsaBundle, importReference, exception),
+ rsaBundle, importReference, exception, endpointDescription),
endpointDescription);
}
@@ -1072,24 +1086,26 @@ public class RemoteServiceAdmin implements
Throwable exception = exportRegistration.getException();
org.osgi.service.remoteserviceadmin.ExportReference exportReference = (exception == null) ? exportRegistration
.getExportReference() : null;
+ EndpointDescription endpointDescription = exportRegistration.getEndpointDescription();
RemoteServiceAdminEvent rsaEvent = new RemoteServiceAdminEvent(
exportRegistration.getContainerID(),
(exception == null) ? RemoteServiceAdminEvent.EXPORT_REGISTRATION
: RemoteServiceAdminEvent.EXPORT_ERROR, getRSABundle(),
- exportReference, exception);
- publishEvent(rsaEvent, exportRegistration.getEndpointDescription());
+ exportReference, exception, endpointDescription);
+ publishEvent(rsaEvent, endpointDescription);
}
private void publishImportEvent(ImportRegistration importRegistration) {
Throwable exception = importRegistration.getException();
org.osgi.service.remoteserviceadmin.ImportReference importReference = (exception == null) ? importRegistration
.getImportReference() : null;
+ EndpointDescription endpointDescription = importRegistration.getEndpointDescription();
RemoteServiceAdminEvent rsaEvent = new RemoteServiceAdminEvent(
importRegistration.getContainerID(),
(exception == null) ? RemoteServiceAdminEvent.IMPORT_REGISTRATION
: RemoteServiceAdminEvent.IMPORT_ERROR, getRSABundle(),
- importReference, exception);
- publishEvent(rsaEvent, importRegistration.getEndpointDescription());
+ importReference, exception, endpointDescription);
+ publishEvent(rsaEvent, endpointDescription);
}
private void closeRemoteServiceAdminListenerTracker() {
@@ -2142,15 +2158,17 @@ public class RemoteServiceAdmin implements
org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent {
private ID containerID;
-
+ private EndpointDescription endpointDescription;
+
public RemoteServiceAdminEvent(
ID containerID,
int type,
Bundle source,
org.osgi.service.remoteserviceadmin.ExportReference exportReference,
- Throwable exception) {
+ Throwable exception, EndpointDescription endpointDescription) {
super(type, source, exportReference, exception);
this.containerID = containerID;
+ this.endpointDescription = endpointDescription;
}
public RemoteServiceAdminEvent(
@@ -2158,11 +2176,19 @@ public class RemoteServiceAdmin implements
int type,
Bundle source,
org.osgi.service.remoteserviceadmin.ImportReference importReference,
- Throwable exception) {
+ Throwable exception, EndpointDescription endpointDescription) {
super(type, source, importReference, exception);
this.containerID = containerID;
+ this.endpointDescription = endpointDescription;
}
+ /**
+ * @since 3.0
+ */
+ public EndpointDescription getEndpointDescription() {
+ return endpointDescription;
+ }
+
public ID getContainerID() {
return containerID;
}
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdminEvent.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdminEvent.java
deleted file mode 100644
index 013c29adb..000000000
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdminEvent.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.eclipse.ecf.osgi.services.remoteserviceadmin;
-
-import org.eclipse.ecf.core.identity.ID;
-import org.osgi.framework.Bundle;
-import org.osgi.service.remoteserviceadmin.ExportReference;
-import org.osgi.service.remoteserviceadmin.ImportReference;
-import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener;
-
-/**
- * ECF implementationm of
- * {@link org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent}.
- * Instances of this class are delivered to {@link RemoteServiceAdminListener}s
- * via the ECF implemenation of {@link RemoteServiceAdmin} as per the OSGi 4.2
- * Remote Service Admin specification (chap 122 of OSGi 4.2 specification).
- *
- */
-public class RemoteServiceAdminEvent extends
- org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent {
-
- private ID containerID;
-
- public RemoteServiceAdminEvent(ID containerID, int type, Bundle source,
- ExportReference exportReference, Throwable exception) {
- super(type, source, exportReference, exception);
- this.containerID = containerID;
- }
-
- public RemoteServiceAdminEvent(ID containerID, int type, Bundle source,
- ImportReference importReference, Throwable exception) {
- super(type, source, importReference, exception);
- this.containerID = containerID;
- }
-
- public ID getContainerID() {
- return containerID;
- }
-
- public String toString() {
- return "RemoteServiceAdminEvent[containerID=" + containerID //$NON-NLS-1$
- + ", getType()=" + getType() + ", getSource()=" + getSource() //$NON-NLS-1$ //$NON-NLS-2$
- + ", getException()=" + getException() //$NON-NLS-1$
- + ", getImportReference()=" + getImportReference() //$NON-NLS-1$
- + ", getExportReference()=" + getExportReference() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}

Back to the top