Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF2
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java55
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/LocatorServiceListener.java151
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractEndpointDescriptionFactory.java18
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractMetadataFactory.java31
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractServiceInfoFactory.java206
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DefaultEndpointDescriptionFactory.java26
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DefaultServiceInfoFactory.java6
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java36
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionFactory.java3
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IServiceInfoFactory.java12
-rw-r--r--incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteConstants.java30
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/META-INF/MANIFEST.MF2
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/endpointdescription1.xml49
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/Activator.java101
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionDiscoveryContainerAdapter.java134
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionParser.java1
-rw-r--r--osgi/bundles/org.eclipse.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF1
18 files changed, 751 insertions, 113 deletions
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF
index 7c7e902f3..8130aeffa 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF
@@ -21,3 +21,5 @@ Import-Package: org.eclipse.ecf.core.identity,
Bundle-ActivationPolicy: lazy
Bundle-Localization: bundle
Require-Bundle: org.eclipse.equinox.common;bundle-version="3.6.0"
+Export-Package: org.eclipse.ecf.internal.osgi.services.remoteserviceadmin;x-internal:=true,
+ org.eclipse.ecf.osgi.services.remoteserviceadmin
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
index c75abc757..310a9cd22 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
@@ -7,6 +7,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -14,13 +15,20 @@ import org.eclipse.ecf.core.util.LogHelper;
import org.eclipse.ecf.core.util.SystemLogService;
import org.eclipse.ecf.discovery.IDiscoveryLocator;
import org.eclipse.ecf.discovery.IServiceInfo;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.AbstractEndpointDescriptionFactory;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.AbstractServiceInfoFactory;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.DefaultEndpointDescriptionFactory;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.DefaultServiceInfoFactory;
import org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionFactory;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.IServiceInfoFactory;
import org.eclipse.equinox.concurrent.future.IExecutor;
import org.eclipse.equinox.concurrent.future.IProgressRunnable;
import org.eclipse.equinox.concurrent.future.ThreadsExecutor;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogService;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
import org.osgi.service.remoteserviceadmin.EndpointListener;
@@ -42,18 +50,25 @@ public class Activator implements BundleActivator {
return instance;
}
+ private AbstractServiceInfoFactory serviceInfoFactory;
+ private ServiceRegistration serviceInfoFactoryRegistration;
+
+ private AbstractEndpointDescriptionFactory endpointDescriptionFactory;
+ private ServiceRegistration endpointDescriptionFactoryRegistration;
+
private IExecutor executor;
- private ServiceTracker logServiceTracker = null;
- private LogService logService = null;
- private Object logServiceTrackerLock = new Object();
-
private LocatorServiceListener locatorServiceListener;
private ServiceTracker locatorServiceTracker;
private ServiceTracker endpointListenerServiceTracker;
private Object endpointListenerServiceTrackerLock = new Object();
+ private ServiceTracker logServiceTracker = null;
+ private LogService logService = null;
+ private Object logServiceTrackerLock = new Object();
+
+
/*
* (non-Javadoc)
*
@@ -64,7 +79,20 @@ public class Activator implements BundleActivator {
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
Activator.instance = this;
+ // For the service info factory and the endpointdescription factory
+ // registration, set the service ranking property to Integer.MIN_VALUE so
+ // that any other registered factories will be preferred.
+ final Properties properties = new Properties();
+ properties.put(Constants.SERVICE_RANKING, new Integer(
+ Integer.MIN_VALUE));
+ serviceInfoFactory = new DefaultServiceInfoFactory();
+ serviceInfoFactoryRegistration = context.registerService(IServiceInfoFactory.class.getName(), serviceInfoFactory, properties);
+ // also endpoint description factory
+ endpointDescriptionFactory = new DefaultEndpointDescriptionFactory();
+ endpointDescriptionFactoryRegistration = context.registerService(IEndpointDescriptionFactory.class.getName(), endpointDescriptionFactory, properties);
+
executor = new ThreadsExecutor();
+
// Create service listener
locatorServiceListener = new LocatorServiceListener();
// Create locator service tracker
@@ -132,6 +160,24 @@ public class Activator implements BundleActivator {
* org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext bundleContext) throws Exception {
+ if (endpointDescriptionFactoryRegistration != null) {
+ endpointDescriptionFactoryRegistration.unregister();
+ endpointDescriptionFactoryRegistration = null;
+ }
+ if (endpointDescriptionFactory != null) {
+ endpointDescriptionFactory.close();
+ endpointDescriptionFactory = null;
+ }
+
+ if (serviceInfoFactoryRegistration != null) {
+ serviceInfoFactoryRegistration.unregister();
+ serviceInfoFactoryRegistration = null;
+ }
+ if (serviceInfoFactory != null) {
+ serviceInfoFactory.close();
+ serviceInfoFactory = null;
+ }
+
synchronized (endpointListenerServiceTrackerLock) {
if (endpointListenerServiceTracker != null) {
endpointListenerServiceTracker.close();
@@ -145,7 +191,6 @@ public class Activator implements BundleActivator {
logService = null;
}
}
-
synchronized (endpointDescriptionFactoryServiceTrackerLock) {
if (endpointDescriptionFactoryServiceTracker != null) {
endpointDescriptionFactoryServiceTracker.close();
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/LocatorServiceListener.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/LocatorServiceListener.java
index 1b9b5f0fd..7da6a491e 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/LocatorServiceListener.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/LocatorServiceListener.java
@@ -20,6 +20,7 @@ import org.eclipse.ecf.discovery.IServiceInfo;
import org.eclipse.ecf.discovery.IServiceListener;
import org.eclipse.ecf.discovery.identity.IServiceID;
import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.Activator.EndpointListenerHolder;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteConstants;
import org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionFactory;
import org.eclipse.osgi.framework.eventmgr.CopyOnWriteIdentityMap;
import org.eclipse.osgi.framework.eventmgr.EventDispatcher;
@@ -32,11 +33,14 @@ class LocatorServiceListener implements IServiceListener {
private Object listenerLock = new Object();
+ private Object initializationLock = new Object();
+ private boolean initialized = false;
+
private ListenerQueue queue;
private EventManager eventManager;
class EndpointListenerEvent {
-
+
private EndpointListenerHolder holder;
private boolean discovered;
@@ -56,65 +60,82 @@ class LocatorServiceListener implements IServiceListener {
}
public LocatorServiceListener() {
- ThreadGroup eventGroup = new ThreadGroup(
- "EventAdmin EndpointListener Dispatcher"); //$NON-NLS-1$
- eventGroup.setDaemon(true);
- eventManager = new EventManager(
- "EventAdmin EndpointListener Dispatcher", eventGroup); //$NON-NLS-1$
- queue = new ListenerQueue(eventManager);
- CopyOnWriteIdentityMap listeners = new CopyOnWriteIdentityMap();
- listeners.put(this, this);
- queue.queueListeners(listeners.entrySet(), new EventDispatcher() {
- public void dispatchEvent(Object eventListener,
- Object listenerObject, int eventAction, Object eventObject) {
- EndpointListenerHolder endpointListenerHolder = ((EndpointListenerEvent) eventObject).getEndpointListenerHolder();
- final boolean discovered = ((EndpointListenerEvent) eventObject).isDiscovered();
-
- final EndpointListener endpointListener = endpointListenerHolder.getListener();
- final EndpointDescription endpointDescription = endpointListenerHolder
- .getDescription();
- final String matchingFilter = endpointListenerHolder
- .getMatchingFilter();
-
- // run with SafeRunner, so that any exceptions are logged by
- // our logger
- SafeRunner.run(new ISafeRunnable() {
- public void handleException(Throwable exception) {
- logError("Exception notifying EndpointListener ",
- exception);
- Activator a = Activator.getDefault();
- if (a != null)
- a.log(new Status(
- IStatus.ERROR,
- Activator.PLUGIN_ID,
- IStatus.ERROR,
- "Exception in EndpointListener listener="+endpointListener+" description="+endpointDescription+" matchingFilter="+matchingFilter, exception)); //$NON-NLS-1$
- }
-
- public void run() throws Exception {
- // Call endpointAdded or endpointRemoved
- if (discovered)
- endpointListener.endpointAdded(endpointDescription, matchingFilter);
- else
- endpointListener.endpointRemoved(endpointDescription,
- matchingFilter);
- }
- });
- }
- });
}
public void serviceDiscovered(IServiceEvent anEvent) {
+ synchronized (initializationLock) {
+ initialize();
+ }
handleService(anEvent.getServiceInfo(), true);
}
+ private void initialize() {
+ if (!initialized) {
+ ThreadGroup eventGroup = new ThreadGroup(
+ "EventAdmin EndpointListener Dispatcher"); //$NON-NLS-1$
+ eventGroup.setDaemon(true);
+ eventManager = new EventManager(
+ "EventAdmin EndpointListener Dispatcher", eventGroup); //$NON-NLS-1$
+ queue = new ListenerQueue(eventManager);
+ CopyOnWriteIdentityMap listeners = new CopyOnWriteIdentityMap();
+ listeners.put(this, this);
+ queue.queueListeners(listeners.entrySet(), new EventDispatcher() {
+ public void dispatchEvent(Object eventListener,
+ Object listenerObject, int eventAction,
+ Object eventObject) {
+ EndpointListenerHolder endpointListenerHolder = ((EndpointListenerEvent) eventObject)
+ .getEndpointListenerHolder();
+ final boolean discovered = ((EndpointListenerEvent) eventObject)
+ .isDiscovered();
+
+ final EndpointListener endpointListener = endpointListenerHolder
+ .getListener();
+ final EndpointDescription endpointDescription = endpointListenerHolder
+ .getDescription();
+ final String matchingFilter = endpointListenerHolder
+ .getMatchingFilter();
+
+ // run with SafeRunner, so that any exceptions are logged by
+ // our logger
+ SafeRunner.run(new ISafeRunnable() {
+ public void handleException(Throwable exception) {
+ logError("Exception notifying EndpointListener ",
+ exception);
+ Activator a = Activator.getDefault();
+ if (a != null)
+ a.log(new Status(
+ IStatus.ERROR,
+ Activator.PLUGIN_ID,
+ IStatus.ERROR,
+ "Exception in EndpointListener listener=" + endpointListener + " description=" + endpointDescription + " matchingFilter=" + matchingFilter, exception)); //$NON-NLS-1$
+ }
+
+ public void run() throws Exception {
+ // Call endpointAdded or endpointRemoved
+ if (discovered)
+ endpointListener.endpointAdded(
+ endpointDescription, matchingFilter);
+ else
+ endpointListener.endpointRemoved(
+ endpointDescription, matchingFilter);
+ }
+ });
+ }
+ });
+ initialized = true;
+ }
+ }
+
public void serviceUndiscovered(IServiceEvent anEvent) {
+ synchronized (initializationLock) {
+ initialize();
+ }
handleService(anEvent.getServiceInfo(), false);
}
private boolean matchServiceID(IServiceID serviceId) {
if (Arrays.asList(serviceId.getServiceTypeID().getServices()).contains(
- "osgiservices"))
+ RemoteConstants.SERVICE_TYPE))
return true;
return false;
}
@@ -176,25 +197,37 @@ class LocatorServiceListener implements IServiceListener {
return null;
}
try {
- // Else get endpoint description factory to create EndpointDescription
- // for given serviceID and serviceInfo
- return (discovered) ? factory.createDiscoveredEndpointDescription(
- serviceInfo) : factory
- .getUndiscoveredEndpointDescription(serviceId, serviceInfo);
+ // Else get endpoint description factory to create
+ // EndpointDescription
+ // for given serviceID and serviceInfo
+ return (discovered) ? factory
+ .createDiscoveredEndpointDescription(serviceInfo) : factory
+ .getUndiscoveredEndpointDescription(serviceId);
} catch (Exception e) {
- logError("Exception calling IEndpointDescriptionFactory."+((discovered)?"createDiscoveredEndpointDescription":"getUndiscoveredEndpointDescription"), e);
+ logError("Exception calling IEndpointDescriptionFactory."
+ + ((discovered) ? "createDiscoveredEndpointDescription"
+ : "getUndiscoveredEndpointDescription"), e);
return null;
} catch (NoClassDefFoundError e) {
- logError("NoClassDefFoundError calling IEndpointDescriptionFactory."+((discovered)?"createDiscoveredEndpointDescription":"getUndiscoveredEndpointDescription"), e);
+ logError(
+ "NoClassDefFoundError calling IEndpointDescriptionFactory."
+ + ((discovered) ? "createDiscoveredEndpointDescription"
+ : "getUndiscoveredEndpointDescription"), e);
return null;
}
}
public void close() {
- if (eventManager != null) {
- eventManager.close();
- eventManager = null;
- queue = null;
+ synchronized (initializationLock) {
+ if (initialized) {
+ synchronized (listenerLock) {
+ if (eventManager != null) {
+ eventManager.close();
+ eventManager = null;
+ queue = null;
+ }
+ }
+ }
}
}
} \ No newline at end of file
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractEndpointDescriptionFactory.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractEndpointDescriptionFactory.java
new file mode 100644
index 000000000..8fbdc22e7
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractEndpointDescriptionFactory.java
@@ -0,0 +1,18 @@
+package org.eclipse.ecf.osgi.services.remoteserviceadmin;
+
+import org.eclipse.ecf.discovery.IServiceInfo;
+import org.eclipse.ecf.discovery.identity.IServiceID;
+
+public abstract class AbstractEndpointDescriptionFactory extends AbstractMetadataFactory implements IEndpointDescriptionFactory {
+
+ public EndpointDescription createDiscoveredEndpointDescription(
+ IServiceInfo discoveredServiceInfo) {
+ return null;
+ }
+
+ public EndpointDescription getUndiscoveredEndpointDescription(
+ IServiceID serviceID) {
+ return null;
+ }
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractMetadataFactory.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractMetadataFactory.java
new file mode 100644
index 000000000..21d3f3118
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractMetadataFactory.java
@@ -0,0 +1,31 @@
+package org.eclipse.ecf.osgi.services.remoteserviceadmin;
+
+import java.util.Map;
+
+public abstract class AbstractMetadataFactory {
+
+ protected String[] getStringArrayPropertyWithDefault(
+ Map<String, Object> properties, String key,
+ String[] def) {
+ if (properties == null) return def;
+ Object o = properties.get(key);
+ if (o instanceof String) {
+ return new String[] { (String) o };
+ } else if (o instanceof String[]) {
+ return (String[]) o;
+ } else
+ return def;
+ }
+
+ protected String getStringPropertyWithDefault(Map props,
+ String key, String def) {
+ if (props == null) return def;
+ Object o = props.get(key);
+ if (o == null || (!(o instanceof String))) return def;
+ return (String) o;
+ }
+
+ public void close() {
+ // nothing to do
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractServiceInfoFactory.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractServiceInfoFactory.java
new file mode 100644
index 000000000..adc825afe
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/AbstractServiceInfoFactory.java
@@ -0,0 +1,206 @@
+package org.eclipse.ecf.osgi.services.remoteserviceadmin;
+
+import java.net.InetAddress;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
+import org.eclipse.ecf.discovery.IServiceInfo;
+import org.eclipse.ecf.discovery.IServiceProperties;
+import org.eclipse.ecf.discovery.ServiceInfo;
+import org.eclipse.ecf.discovery.identity.IServiceTypeID;
+import org.eclipse.ecf.discovery.identity.ServiceIDFactory;
+
+public abstract class AbstractServiceInfoFactory extends
+ AbstractMetadataFactory implements IServiceInfoFactory {
+
+ protected Map<ServiceInfoKey, IServiceInfo> serviceInfos = new HashMap();
+
+ protected class ServiceInfoKey {
+ private EndpointDescription endpointDescription;
+ private Namespace discoveryNamespace;
+ private int hashCode = 7;
+
+ public ServiceInfoKey(EndpointDescription endpointDescription,
+ Namespace discoveryNamespace) {
+ this.endpointDescription = endpointDescription;
+ this.discoveryNamespace = discoveryNamespace;
+ this.hashCode = 31 * this.hashCode + endpointDescription.hashCode();
+ this.hashCode = 31 * this.hashCode + discoveryNamespace.hashCode();
+ }
+
+ public boolean equals(Object other) {
+ if (other == null)
+ return false;
+ if (!(other instanceof ServiceInfoKey))
+ return false;
+ ServiceInfoKey otherKey = (ServiceInfoKey) other;
+ return (this.endpointDescription
+ .equals(otherKey.endpointDescription) && this.discoveryNamespace
+ .equals(otherKey.discoveryNamespace));
+ }
+
+ public int hashCode() {
+ return hashCode;
+ }
+ }
+
+ public IServiceInfo createServiceInfoForDiscovery(
+ EndpointDescription endpointDescription,
+ IDiscoveryAdvertiser advertiser) {
+ Namespace advertiserNamespace = advertiser.getServicesNamespace();
+ ServiceInfoKey key = new ServiceInfoKey(endpointDescription,advertiserNamespace);
+ IServiceInfo existingServiceInfo = null;
+ synchronized (serviceInfos) {
+ existingServiceInfo = serviceInfos.get(key);
+ // If it's already there, then we return null
+ if (existingServiceInfo != null)
+ return null;
+ IServiceTypeID serviceTypeID = createServiceTypeID(endpointDescription,
+ advertiser);
+ String serviceName = createServiceName(endpointDescription, advertiser,
+ serviceTypeID);
+ URI uri = null;
+ try {
+ uri = createURI(endpointDescription, advertiser, serviceTypeID,
+ serviceName);
+ } catch (URISyntaxException e) {
+ String message = "URI could not be created for endpoint description="
+ + endpointDescription;
+ logError("createURI", message, e);
+ throw new RuntimeException(message, e);
+ }
+ IServiceProperties serviceProperties = createServiceProperties(
+ endpointDescription, advertiser, serviceTypeID, serviceName,
+ uri);
+ IServiceInfo newServiceInfo = new ServiceInfo(uri,
+ serviceName, serviceTypeID, serviceProperties);
+ // put into map using key
+ serviceInfos.put(key, newServiceInfo);
+ return newServiceInfo;
+ }
+ }
+
+ protected IServiceProperties createServiceProperties(
+ EndpointDescription endpointDescription,
+ IDiscoveryAdvertiser advertiser, IServiceTypeID serviceTypeID,
+ String serviceName, URI uri) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ protected URI createURI(EndpointDescription endpointDescription,
+ IDiscoveryAdvertiser advertiser, IServiceTypeID serviceTypeID,
+ String serviceName) throws URISyntaxException {
+ String path = "/" + serviceName;
+ String str = endpointDescription.getID().getName();
+ URI uri = null;
+ while (true) {
+ try {
+ uri = new URI(str);
+ if (uri.getHost() != null) {
+ break;
+ } else {
+ final String rawSchemeSpecificPart = uri
+ .getRawSchemeSpecificPart();
+ // make sure we break eventually
+ if (str.equals(rawSchemeSpecificPart)) {
+ uri = null;
+ break;
+ } else {
+ str = rawSchemeSpecificPart;
+ }
+ }
+ } catch (URISyntaxException e) {
+ uri = null;
+ break;
+ }
+ }
+ String scheme = RemoteConstants.SERVICE_TYPE;
+ int port = 32565;
+ if (uri != null) {
+ port = uri.getPort();
+ if (port == -1)
+ port = 32565;
+ }
+ String host = null;
+ if (uri != null) {
+ host = uri.getHost();
+ } else {
+ try {
+ host = InetAddress.getLocalHost().getHostAddress();
+ } catch (Exception e) {
+ logInfo("createURI", //$NON-NLS-1$
+ "failed to get local host adress, falling back to \'localhost\'.", e); //$NON-NLS-1$
+ host = "localhost"; //$NON-NLS-1$
+ }
+ }
+ return new URI(scheme, null, host, port, path, null, null);
+ }
+
+ protected void logInfo(String methodName, String message, Throwable t) {
+ // XXX todo
+ }
+
+ protected void logError(String methodName, String message, Throwable t) {
+ // XXX todo
+ }
+
+ protected String createServiceName(EndpointDescription endpointDescription,
+ IDiscoveryAdvertiser advertiser, IServiceTypeID serviceTypeID) {
+ // First create unique default name
+ String defaultServiceName = createDefaultServiceName(
+ endpointDescription, advertiser, serviceTypeID);
+ // Look for service name that was explicitly set
+ String serviceName = getStringPropertyWithDefault(
+ endpointDescription.getProperties(),
+ RemoteConstants.DISCOVERY_SERVICE_NAME, defaultServiceName);
+ return serviceName;
+ }
+
+ protected String createDefaultServiceName(
+ EndpointDescription endpointDescription,
+ IDiscoveryAdvertiser advertiser, IServiceTypeID serviceTypeID) {
+ return RemoteConstants.DISCOVERY_DEFAULT_SERVICE_NAME_PREFIX
+ + IDFactory.getDefault().createGUID().getName();
+ }
+
+ protected IServiceTypeID createServiceTypeID(
+ EndpointDescription endpointDescription,
+ IDiscoveryAdvertiser advertiser) {
+ Map props = endpointDescription.getProperties();
+ String[] scopes = getStringArrayPropertyWithDefault(props,
+ RemoteConstants.DISCOVERY_SCOPE, IServiceTypeID.DEFAULT_SCOPE);
+ String[] protocols = getStringArrayPropertyWithDefault(props,
+ RemoteConstants.DISCOVERY_PROTOCOLS,
+ IServiceTypeID.DEFAULT_SCOPE);
+ String namingAuthority = getStringPropertyWithDefault(props,
+ RemoteConstants.DISCOVERY_NAMING_AUTHORITY,
+ IServiceTypeID.DEFAULT_NA);
+ return ServiceIDFactory.getDefault().createServiceTypeID(
+ advertiser.getServicesNamespace(),
+ new String[] { RemoteConstants.SERVICE_TYPE }, scopes,
+ protocols, namingAuthority);
+ }
+
+ public IServiceInfo removeServiceInfoForUndiscovery(
+ EndpointDescription endpointDescription,
+ IDiscoveryAdvertiser advertiser) {
+ Namespace advertiserNamespace = advertiser.getServicesNamespace();
+ ServiceInfoKey key = new ServiceInfoKey(endpointDescription,advertiserNamespace);
+ synchronized (serviceInfos) {
+ return serviceInfos.remove(key);
+ }
+ }
+
+ public void close() {
+ synchronized (serviceInfos) {
+ serviceInfos.clear();
+ }
+ super.close();
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DefaultEndpointDescriptionFactory.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DefaultEndpointDescriptionFactory.java
index 455d416be..37bfe8e3b 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DefaultEndpointDescriptionFactory.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DefaultEndpointDescriptionFactory.java
@@ -9,31 +9,7 @@
******************************************************************************/
package org.eclipse.ecf.osgi.services.remoteserviceadmin;
-import org.eclipse.ecf.discovery.IServiceInfo;
-import org.eclipse.ecf.discovery.identity.IServiceID;
-public class DefaultEndpointDescriptionFactory implements IEndpointDescriptionFactory {
-
- protected void logWarning(String message) {
- // XXX change to log
- System.out.println(message);
- }
-
- protected EndpointDescription getECFEndpointDescription(IServiceID serviceID, IServiceInfo serviceInfo) {
- // XXX todo
- return null;
- }
-
- public EndpointDescription getUndiscoveredEndpointDescription(
- IServiceID serviceId, IServiceInfo undiscoveredServiceInfo) {
- // XXX todo
- return null;
- }
-
- public EndpointDescription createDiscoveredEndpointDescription(
- IServiceInfo discoveredServiceInfo) {
- // TODO Auto-generated method stub
- return null;
- }
+public class DefaultEndpointDescriptionFactory extends AbstractEndpointDescriptionFactory {
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DefaultServiceInfoFactory.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DefaultServiceInfoFactory.java
new file mode 100644
index 000000000..bb7f0d2e6
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DefaultServiceInfoFactory.java
@@ -0,0 +1,6 @@
+package org.eclipse.ecf.osgi.services.remoteserviceadmin;
+
+
+public class DefaultServiceInfoFactory extends AbstractServiceInfoFactory {
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java
index 827bd40f3..b7c248c3b 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java
@@ -9,10 +9,10 @@
******************************************************************************/
package org.eclipse.ecf.osgi.services.remoteserviceadmin;
+import java.util.Arrays;
import java.util.Map;
import org.eclipse.ecf.core.identity.ID;
-import org.eclipse.ecf.discovery.IServiceInfo;
import org.osgi.framework.ServiceReference;
public class EndpointDescription extends
@@ -40,11 +40,31 @@ public class EndpointDescription extends
}
private void initRemoteServiceProperties() {
- // XXX todo
+ Map properties = getProperties();
+
+ containerID = (ID) properties.get(RemoteConstants.CONTAINER_ID_PROPNAME);
+ if (containerID == null)
+ throw new NullPointerException(
+ "ECF EndpointDescription must include non-null containerID");
+
+ Object rsid = properties.get(RemoteConstants.REMOTE_SERVICE_ID_PROPNAME);
+ if (rsid != null)
+ remoteServiceId = ((Long) rsid).longValue();
+
+ Object ctid = properties.get(RemoteConstants.CONNECT_TARGET_ID_PROPNAME);
+ if (ctid != null)
+ connectTargetID = (ID) ctid;
+
+ Object idf = properties.get(RemoteConstants.IDFILTER_PROPNAME);
+ if (idf != null)
+ idFilter = (ID[]) idf;
+
+ Object rsf = properties.get(RemoteConstants.REMOTESERVICE_FILTER_PROPNAME);
+ if (rsf != null)
+ rsFilter = (String) rsFilter;
}
- public EndpointDescription(IServiceInfo discoveredServiceInfo,
- Map osgiProperties) {
+ public EndpointDescription(Map osgiProperties) {
super(osgiProperties);
initRemoteServiceProperties();
computeHashCode();
@@ -84,4 +104,12 @@ public class EndpointDescription extends
return rsFilter;
}
+ public String toString() {
+ return "ECFEndpointDescription[properties=" + super.toString()
+ + ",containerID=" + containerID + ", remoteServiceId="
+ + remoteServiceId + ", connectTargetID=" + connectTargetID
+ + ", idFilter=" + Arrays.toString(idFilter) + ", rsFilter="
+ + rsFilter + ", hashCode=" + hashCode + "]";
+ }
+
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionFactory.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionFactory.java
index e3c59059f..a0d737f0e 100644
--- a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionFactory.java
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionFactory.java
@@ -33,11 +33,10 @@ public interface IEndpointDescriptionFactory {
* <code>null</code> if no notification should occur.
*
* @param serviceId the discovered service ID. Must not be <code>null</code>.
- * @param discoveredServiceInfo the discovered service info. May be <code>null</code>.
* @return EndpointDescription that will be used to notify EndpointListeners
* about an undiscovered EndpointDescription. If <code>null</code> is returned, no
* notification should be performed by the calling code.
*/
- public EndpointDescription getUndiscoveredEndpointDescription(IServiceID serviceID, IServiceInfo undiscoveredServiceInfo);
+ public EndpointDescription getUndiscoveredEndpointDescription(IServiceID serviceID);
}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IServiceInfoFactory.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IServiceInfoFactory.java
new file mode 100644
index 000000000..6e7d0648e
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IServiceInfoFactory.java
@@ -0,0 +1,12 @@
+package org.eclipse.ecf.osgi.services.remoteserviceadmin;
+
+import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
+import org.eclipse.ecf.discovery.IServiceInfo;
+
+public interface IServiceInfoFactory {
+
+ public IServiceInfo createServiceInfoForDiscovery(EndpointDescription endpointDescription, IDiscoveryAdvertiser advertiser);
+
+ public IServiceInfo removeServiceInfoForUndiscovery(EndpointDescription endpointDescription, IDiscoveryAdvertiser advertiser);
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteConstants.java b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteConstants.java
new file mode 100644
index 000000000..f5aa3e6d7
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteConstants.java
@@ -0,0 +1,30 @@
+package org.eclipse.ecf.osgi.services.remoteserviceadmin;
+
+public class RemoteConstants {
+
+ public static final String SERVICE_TYPE = "osgirsvc";
+
+ public static final String DISCOVERY_SCOPE = "ecf.endpoint.discovery.scope";
+ public static final String DISCOVERY_PROTOCOLS = "ecf.endpoint.discovery.protocols";
+ public static final String DISCOVERY_NAMING_AUTHORITY = "ecf.endpoint.discovery.na";
+ public static final String DISCOVERY_SERVICE_NAME = "ecf.endpoint.discovery.servicename";
+ public static final String DISCOVERY_DEFAULT_SERVICE_NAME_PREFIX = "osgirsvc_";
+
+ // value of this property is expected to be of type ID
+ public static final String CONTAINER_ID_PROPNAME = "ecf.endpoint.containerid";
+ public static final String CONTAINER_ID_NAMESPACE_PROPNAME = "ecf.endpoint.containerid.namespace";
+ // value of this property is expected to be of type Long
+ public static final String REMOTE_SERVICE_ID_PROPNAME = "ecf.endpoint.remoteserviceid";
+
+
+ // value of this property is expected to be ID
+ public static final String CONNECT_TARGET_ID_PROPNAME = "ecf.endpoint.connecttargetid";
+ public static final String CONNECT_TARGET_ID_NAMESPACE_PROPNAME = "ecf.endpoint.connecttargetid.namespace";
+
+ // value of this property is expected to be ID[]
+ public static final String IDFILTER_PROPNAME = "ecf.endpoint.idfilter";
+ public static final String IDFILTER_NAMESPACE_PROPNAME = "ecf.endpoint.idfilter.namespace";
+ // value of this property is expected to be String
+ public static final String REMOTESERVICE_FILTER_PROPNAME = "ecf.endpoint.remoteservicefilter";
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/META-INF/MANIFEST.MF b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/META-INF/MANIFEST.MF
index 645bac105..a4d0b7653 100644
--- a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/META-INF/MANIFEST.MF
+++ b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/META-INF/MANIFEST.MF
@@ -13,8 +13,10 @@ Import-Package: org.eclipse.ecf.core;version="3.0.0",
org.eclipse.ecf.core.security,
org.eclipse.ecf.discovery;version="4.0.0",
org.eclipse.ecf.discovery.identity,
+ org.eclipse.ecf.osgi.services.remoteserviceadmin,
org.eclipse.equinox.concurrent.future;version="1.0.0",
org.osgi.framework;version="1.3.0",
+ org.osgi.service.remoteserviceadmin;version="1.0.0",
org.osgi.util.tracker
Bundle-Localization: plugin
Require-Bundle: org.eclipse.equinox.common;bundle-version="3.6.0"
diff --git a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/endpointdescription1.xml b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/endpointdescription1.xml
new file mode 100644
index 000000000..6e661a7cf
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/endpointdescription1.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<endpoint-descriptions xmlns="http://www.osgi.org/xmlns/rsa/v1.0.0">
+ <endpoint-description>
+ <!-- osgi required endpoint description properties -->
+ <property name="objectClass" value="com.acme.Foo"/>
+ <property name="endpoint.service.id" value="100"/>
+ <property name="endpoint.framework.uuid" value="frameworkid.1000"/>
+ <property name="endpoint.id" value="http://ws.acme.com:9000/hello"/>
+ <property name="service.imported.configs" value="com.acme"/>
+
+ <!-- ecf required endpoint description properties -->
+ <property name="ecf.endpoint.containerid" value="ecftcp://localhost:3283/server" />
+ <property name="ecf.endpoint.containerid.namespace" value="org.eclipse.ecf.core.identity.StringID" />
+ <property name="ecf.endpoint.remoteserviceid" value="1000" />
+
+ <!-- osgi optional endpoint description properties -->
+ <property name="endpoint.package.version.com.acme" value="4.2"/>
+ <property name="service.imported.configs" value="com.acme"/>
+ <property name="service.intents">
+ <list>
+ <value>SOAP</value>
+ <value>HTTP</value>
+ </list>
+ </property>
+ <property name="integers" value-type="int">
+ <array>
+ <value> 1 </value>
+ <value>2</value>
+ <value> 3 </value>
+ </array>
+ </property>
+ <property name="floats" value-type="Float">
+ <set>
+ <value> 1.45 </value>
+ <value>2.0</value>
+ <value> 3 </value>
+ </set>
+ </property>
+
+ <property name="com.acme.ws.xml">
+ <xml>
+ <config xmlns:cfg="http://acme.com/defs" foo="bar">
+ <cfg:port>1029</cfg:port>
+ <host>www.acme.com</host>
+ </config>
+ </xml>
+ </property>
+ </endpoint-description>
+</endpoint-descriptions>
diff --git a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/Activator.java b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/Activator.java
index f7282192e..b11e3ad37 100644
--- a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/Activator.java
+++ b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/Activator.java
@@ -1,7 +1,18 @@
package org.eclipse.ecf.provider.internal.endpointdescription.localdiscovery;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import javax.xml.parsers.SAXParserFactory;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.discovery.IServiceInfo;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.IServiceInfoFactory;
+import org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteConstants;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
@@ -12,25 +23,94 @@ public class Activator implements BundleActivator {
private static Activator instance;
private ServiceTracker parserTracker;
-
+
+ private ServiceTracker serviceInfoFactoryTracker;
+
static BundleContext getContext() {
return context;
}
/*
* (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ *
+ * @see
+ * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
+ * )
*/
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
instance = this;
+
+ // test code
+ testParseServiceDescription();
+ }
+
+ private Map convertProperties(Map properties) {
+ Map result = new HashMap();
+
+ String svcimportedcfgs = (String) properties.get(org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_IMPORTED_CONFIGS);
+ result.put(org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_IMPORTED_CONFIGS,svcimportedcfgs);
+
+
+ String objectClass = (String) properties.get("objectClass");
+ result.put("objectClass", new String[] { objectClass });
+ String endpointid = (String) properties.get(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_ID);
+ result.put(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_ID, endpointid);
+
+ String endpointsvcid = (String) properties.get(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_SERVICE_ID);
+ result.put(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_SERVICE_ID, new Long(endpointsvcid));
+
+ String endpointfmkid = (String) properties.get(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID);
+ result.put(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID, endpointfmkid);
+
+ String containerid = (String) properties.get(RemoteConstants.CONTAINER_ID_PROPNAME);
+ String containerns = (String) properties.get(RemoteConstants.CONTAINER_ID_NAMESPACE_PROPNAME);
+ result.put(RemoteConstants.CONTAINER_ID_PROPNAME, IDFactory.getDefault().createID(containerns, containerid));
+
+ String rsid = (String) properties.get(RemoteConstants.REMOTE_SERVICE_ID_PROPNAME);
+ result.put(RemoteConstants.REMOTE_SERVICE_ID_PROPNAME, new Long(rsid));
+
+ return result;
+ }
+ private void testParseServiceDescription() {
+ try {
+ URL file = context.getBundle().getEntry("/endpointdescription1.xml");
+ InputStream ins = file.openStream();
+ EndpointDescriptionParser parser = new EndpointDescriptionParser();
+ parser.parse(ins);
+ List<org.eclipse.ecf.provider.internal.endpointdescription.localdiscovery.EndpointDescriptionParser.EndpointDescription> descs = parser.getEndpointDescriptions();
+ IServiceInfoFactory serviceInfoFactory = getServiceInfoFactory();
+ for(EndpointDescriptionParser.EndpointDescription d: descs) {
+ Map props = convertProperties(d.getProperties());
+ EndpointDescription ed = new EndpointDescription(props);
+ System.out.println("endpoint description="+ed);
+ IServiceInfo serviceInfo = serviceInfoFactory.createServiceInfoForDiscovery(ed,null);
+ System.out.println("serviceInfo="+serviceInfo);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public synchronized IServiceInfoFactory getServiceInfoFactory() {
+ if (instance == null)
+ return null;
+ if (serviceInfoFactoryTracker == null) {
+ serviceInfoFactoryTracker = new ServiceTracker(context,
+ IServiceInfoFactory.class.getName(), null);
+ serviceInfoFactoryTracker.open();
+ }
+ return (IServiceInfoFactory) serviceInfoFactoryTracker.getService();
}
/*
* (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ *
+ * @see
+ * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext bundleContext) throws Exception {
+ closeServiceInfoFactoryTracker();
closeSAXParserTracker();
Activator.context = null;
instance = null;
@@ -41,18 +121,27 @@ public class Activator implements BundleActivator {
}
public synchronized SAXParserFactory getSAXParserFactory() {
- if (instance == null) return null;
+ if (instance == null)
+ return null;
if (parserTracker == null) {
- parserTracker = new ServiceTracker(context,SAXParserFactory.class.getName(),null);
+ parserTracker = new ServiceTracker(context,
+ SAXParserFactory.class.getName(), null);
parserTracker.open();
}
return (SAXParserFactory) parserTracker.getService();
}
-
+
private synchronized void closeSAXParserTracker() {
if (parserTracker != null) {
parserTracker.close();
parserTracker = null;
}
}
+
+ private synchronized void closeServiceInfoFactoryTracker() {
+ if (serviceInfoFactoryTracker != null) {
+ serviceInfoFactoryTracker.close();
+ serviceInfoFactoryTracker = null;
+ }
+ }
}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionDiscoveryContainerAdapter.java b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionDiscoveryContainerAdapter.java
index b7e8ca2e8..95a32d9d0 100644
--- a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionDiscoveryContainerAdapter.java
+++ b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionDiscoveryContainerAdapter.java
@@ -1,50 +1,158 @@
package org.eclipse.ecf.provider.internal.endpointdescription.localdiscovery;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.security.IConnectContext;
import org.eclipse.ecf.discovery.AbstractDiscoveryContainerAdapter;
import org.eclipse.ecf.discovery.DiscoveryContainerConfig;
+import org.eclipse.ecf.discovery.IServiceEvent;
import org.eclipse.ecf.discovery.IServiceInfo;
+import org.eclipse.ecf.discovery.IServiceTypeEvent;
import org.eclipse.ecf.discovery.identity.IServiceID;
import org.eclipse.ecf.discovery.identity.IServiceTypeID;
public class EndpointDescriptionDiscoveryContainerAdapter extends
AbstractDiscoveryContainerAdapter {
+ private Map<IServiceID, IServiceInfo> remoteServiceInfos;
+
public EndpointDescriptionDiscoveryContainerAdapter(String aNamespaceName,
DiscoveryContainerConfig aConfig) {
super(aNamespaceName, aConfig);
- // TODO Auto-generated constructor stub
+ remoteServiceInfos = new HashMap<IServiceID, IServiceInfo>();
}
public IServiceInfo getServiceInfo(IServiceID aServiceID) {
- // TODO Auto-generated method stub
- return null;
+ if (aServiceID == null)
+ return null;
+ synchronized (remoteServiceInfos) {
+ return remoteServiceInfos.get(aServiceID);
+ }
}
public IServiceInfo[] getServices() {
- // TODO Auto-generated method stub
- return null;
+ Collection<IServiceInfo> results = new ArrayList<IServiceInfo>();
+ synchronized (remoteServiceInfos) {
+ for (IServiceInfo i : remoteServiceInfos.values())
+ results.add(i);
+ }
+ return (IServiceInfo[]) results.toArray(new IServiceInfo[] {});
}
public IServiceInfo[] getServices(IServiceTypeID aServiceTypeID) {
- // TODO Auto-generated method stub
- return null;
+ Collection<IServiceInfo> results = new ArrayList<IServiceInfo>();
+ if (aServiceTypeID == null)
+ return (IServiceInfo[]) results.toArray(new IServiceInfo[] {});
+ synchronized (remoteServiceInfos) {
+ for (IServiceInfo i : remoteServiceInfos.values()) {
+ if (i.getServiceID().getServiceTypeID().equals(aServiceTypeID))
+ results.add(i);
+ }
+ }
+ return (IServiceInfo[]) results.toArray(new IServiceInfo[] {});
+ }
+
+ private Collection<IServiceTypeID> getServiceTypesAsCollection() {
+ Collection<IServiceTypeID> results = new ArrayList<IServiceTypeID>();
+ synchronized (remoteServiceInfos) {
+ for (IServiceInfo i : remoteServiceInfos.values())
+ results.add(i.getServiceID().getServiceTypeID());
+ }
+ return results;
}
public IServiceTypeID[] getServiceTypes() {
- // TODO Auto-generated method stub
- return null;
+ return (IServiceTypeID[]) getServiceTypesAsCollection().toArray(
+ new IServiceTypeID[] {});
}
+
public void registerService(IServiceInfo serviceInfo) {
- // TODO Auto-generated method stub
+ if (serviceInfo == null)
+ throw new NullPointerException("serviceInfo cannot be null"); //$NON-NLS-1$
+ addServiceInfo(serviceInfo);
+ }
+
+ private void addServiceInfo(IServiceInfo serviceInfo) {
+ IServiceID serviceID = serviceInfo.getServiceID();
+ IServiceInfo addResult = null;
+ IServiceTypeID serviceTypeAdded = null;
+ synchronized (remoteServiceInfos) {
+ // First add..
+ addResult = remoteServiceInfos.put(serviceID, serviceInfo);
+ if (addResult == null) {
+ Collection<IServiceTypeID> serviceTypes = getServiceTypesAsCollection();
+ IServiceTypeID stID = serviceID.getServiceTypeID();
+ if (serviceTypes.contains(stID))
+ serviceTypeAdded = stID;
+ }
+ }
+ if (serviceTypeAdded != null)
+ fireServiceTypeDiscovered(createDiscoveredServiceTypeEvent(serviceTypeAdded));
+ if (addResult == null)
+ fireServiceDiscovered(createDiscoveredServiceEvent(serviceInfo));
+ }
+ private IServiceTypeEvent createDiscoveredServiceTypeEvent(
+ final IServiceTypeID serviceTypeID) {
+ return new IServiceTypeEvent() {
+
+ public ID getLocalContainerID() {
+ return getID();
+ }
+
+ public IServiceTypeID getServiceTypeID() {
+ return serviceTypeID;
+ }
+ };
+ }
+
+ private IServiceEvent createDiscoveredServiceEvent(
+ final IServiceInfo serviceInfo) {
+ return new IServiceEvent() {
+
+ public ID getLocalContainerID() {
+ return getID();
+ }
+
+ public IServiceInfo getServiceInfo() {
+ return serviceInfo;
+ }
+ };
}
public void unregisterService(IServiceInfo serviceInfo) {
- // TODO Auto-generated method stub
+ if (serviceInfo == null)
+ throw new NullPointerException("serviceInfo cannot be null"); //$NON-NLS-1$
+ removeServiceInfo(serviceInfo);
+ }
+
+ private void removeServiceInfo(IServiceInfo serviceInfo) {
+ IServiceID serviceID = serviceInfo.getServiceID();
+ IServiceInfo addResult = null;
+ synchronized (remoteServiceInfos) {
+ addResult = remoteServiceInfos.remove(serviceID);
+ }
+ if (addResult == null)
+ fireServiceUndiscovered(createUndiscoveredServiceEvent(serviceInfo));
+ }
+ private IServiceEvent createUndiscoveredServiceEvent(
+ final IServiceInfo serviceInfo) {
+ return new IServiceEvent() {
+
+ public ID getLocalContainerID() {
+ return getID();
+ }
+
+ public IServiceInfo getServiceInfo() {
+ return serviceInfo;
+ }
+ };
}
public void connect(ID targetID, IConnectContext connectContext)
@@ -71,4 +179,8 @@ public class EndpointDescriptionDiscoveryContainerAdapter extends
return "ecf.discovery.local"; //$NON-NLS-1$
}
+ public void dispose() {
+ remoteServiceInfos.clear();
+ super.dispose();
+ }
}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionParser.java b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionParser.java
index d3febe7f9..d42cd83f1 100644
--- a/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionParser.java
+++ b/incubation/bundles/org.eclipse.ecf.provider.endpointdescription.localdiscovery/src/org/eclipse/ecf/provider/internal/endpointdescription/localdiscovery/EndpointDescriptionParser.java
@@ -591,7 +591,6 @@ public class EndpointDescriptionParser {
}
buf.append(">"); //$NON-NLS-1$
characters = new StringBuffer();
- System.out.println(buf);
}
public void startElement(String name, Attributes attributes)
diff --git a/osgi/bundles/org.eclipse.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF b/osgi/bundles/org.eclipse.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF
index f36b2170e..c80684a60 100644
--- a/osgi/bundles/org.eclipse.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF
+++ b/osgi/bundles/org.eclipse.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF
@@ -11,3 +11,4 @@ Bundle-Localization: bundle
Bundle-Description: %bundle.description
Bundle-Copyright: %bundle.copyright
Export-Package: org.osgi.service.remoteserviceadmin; version="1.0"
+Import-Package: org.osgi.framework

Back to the top