diff options
author | Markus Alexander Kuppe | 2013-12-18 12:18:48 +0000 |
---|---|---|
committer | Markus Alexander Kuppe | 2013-12-18 12:29:53 +0000 |
commit | 4a7dfbda7c9b87ef684ab16a7d0e6b490d643b40 (patch) | |
tree | 57d9d1fd2a2c6299c67af7dc889739d8aa398507 /osgi | |
parent | 695a5cee6021806d7d8a05b106ee7baec3073bf8 (diff) | |
download | org.eclipse.ecf-4a7dfbda7c9b87ef684ab16a7d0e6b490d643b40.tar.gz org.eclipse.ecf-4a7dfbda7c9b87ef684ab16a7d0e6b490d643b40.tar.xz org.eclipse.ecf-4a7dfbda7c9b87ef684ab16a7d0e6b490d643b40.zip |
Bug 424059: RSA not dynamic aware with regards to discovery providers
https://bugs.eclipse.org/bugs/show_bug.cgi?id=424059
Refactor .remoteserviceadmin bundle to interact with ECF discovery via
whiteboard pattern only. Besides code simplifications a major advantage
is removal of startup ordering in that Discovery providers can now be
started but still advertise the endpoint after RSA has published the
service.
Part #1 removes the coupling with IDiscoveryAdvertiser
Signed-off-by: Markus Alexander Kuppe <bugs.eclipse.org@lemmster.de>
Diffstat (limited to 'osgi')
7 files changed, 83 insertions, 625 deletions
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF index fedb577a4..808f1b81a 100644 --- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF +++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %bundle.name Bundle-SymbolicName: org.eclipse.ecf.osgi.services.remoteserviceadmin -Bundle-Version: 3.0.0.qualifier +Bundle-Version: 4.0.0.qualifier Bundle-Activator: org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.Activator Bundle-Vendor: %bundle.provider Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java index 71aca41fc..d27853aa4 100644 --- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java +++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java @@ -28,10 +28,10 @@ import org.eclipse.ecf.core.ContainerTypeDescription; import org.eclipse.ecf.core.IContainerManager; import org.eclipse.ecf.core.util.LogHelper; import org.eclipse.ecf.core.util.SystemLogService; -import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionAdvertiser; import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionLocator; -import org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionAdvertiser; +import org.eclipse.ecf.osgi.services.remoteserviceadmin.IServiceInfoFactory; import org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin; +import org.eclipse.ecf.osgi.services.remoteserviceadmin.ServiceInfoFactory; import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter; import org.osgi.framework.Bundle; import org.osgi.framework.BundleActivator; @@ -66,8 +66,7 @@ public class Activator implements BundleActivator { private ServiceRegistration remoteServiceAdminRegistration; private EndpointDescriptionLocator endpointDescriptionLocator; - private EndpointDescriptionAdvertiser endpointDescriptionAdvertiser; - private ServiceRegistration endpointDescriptionAdvertiserRegistration; + private ServiceRegistration<?> iServiceInfoFactoryRegistration; // Logging private ServiceTracker logServiceTracker = null; @@ -209,11 +208,9 @@ public class Activator implements BundleActivator { final Properties properties = new Properties(); properties.put(Constants.SERVICE_RANKING, new Integer(Integer.MIN_VALUE)); - endpointDescriptionAdvertiser = new EndpointDescriptionAdvertiser( - endpointDescriptionLocator); - endpointDescriptionAdvertiserRegistration = context.registerService( - IEndpointDescriptionAdvertiser.class.getName(), - endpointDescriptionAdvertiser, (Dictionary) properties); + iServiceInfoFactoryRegistration = context.registerService( + IServiceInfoFactory.class.getName(), + new ServiceInfoFactory(), (Dictionary) properties); // start endpointDescriptionLocator endpointDescriptionLocator.start(); @@ -247,13 +244,9 @@ public class Activator implements BundleActivator { remoteServiceAdminRegistration = null; } clearRSAs(); - if (endpointDescriptionAdvertiserRegistration != null) { - endpointDescriptionAdvertiserRegistration.unregister(); - endpointDescriptionAdvertiserRegistration = null; - } - if (endpointDescriptionAdvertiser != null) { - endpointDescriptionAdvertiser.close(); - endpointDescriptionAdvertiser = null; + if (iServiceInfoFactoryRegistration != null) { + iServiceInfoFactoryRegistration.unregister(); + iServiceInfoFactoryRegistration = null; } synchronized (saxParserFactoryTrackerLock) { if (saxParserFactoryTracker != null) { 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 4190756db..d84162cf6 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,8 +9,7 @@ ******************************************************************************/ package org.eclipse.ecf.osgi.services.remoteserviceadmin; -import java.security.AccessController; -import java.security.PrivilegedAction; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -18,6 +17,7 @@ import java.util.StringTokenizer; import java.util.TreeMap; import org.eclipse.core.runtime.IStatus; +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; @@ -27,6 +27,7 @@ import org.osgi.framework.Filter; import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceEvent; import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; import org.osgi.service.remoteserviceadmin.EndpointListener; import org.osgi.service.remoteserviceadmin.ImportRegistration; import org.osgi.util.tracker.ServiceTracker; @@ -47,13 +48,18 @@ public abstract class AbstractTopologyManager { private BundleContext context; - private ServiceTracker endpointDescriptionAdvertiserTracker; - private Object endpointDescriptionAdvertiserTrackerLock = new Object(); + private ServiceTracker<IServiceInfoFactory, IServiceInfoFactory> serviceInfoFactoryTracker; private ServiceTracker remoteServiceAdminTracker; private Object remoteServiceAdminTrackerLock = new Object(); + private final Map<org.osgi.service.remoteserviceadmin.EndpointDescription, ServiceRegistration<IServiceInfo>> registrations = + new HashMap<org.osgi.service.remoteserviceadmin.EndpointDescription, ServiceRegistration<IServiceInfo>>(); + public AbstractTopologyManager(BundleContext context) { + serviceInfoFactoryTracker = new ServiceTracker( + Activator.getContext(), createISIFFilter(), null); + serviceInfoFactoryTracker.open(); this.context = context; } @@ -68,42 +74,7 @@ public abstract class AbstractTopologyManager { return a.getFrameworkUUID(); } - /** - * @since 3.0 - */ - protected IEndpointDescriptionAdvertiser getEndpointDescriptionAdvertiser( - org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) { - IEndpointDescriptionAdvertiser advertiser = AccessController - .doPrivileged(new PrivilegedAction<IEndpointDescriptionAdvertiser>() { - public IEndpointDescriptionAdvertiser run() { - synchronized (endpointDescriptionAdvertiserTrackerLock) { - if (endpointDescriptionAdvertiserTracker == null) { - endpointDescriptionAdvertiserTracker = new ServiceTracker( - getContext(), - IEndpointDescriptionAdvertiser.class - .getName(), null); - endpointDescriptionAdvertiserTracker.open(); - } - } - return (IEndpointDescriptionAdvertiser) endpointDescriptionAdvertiserTracker - .getService(); - } - }); - if (advertiser == null) - logWarning("handleOSGiEndpointAdded", //$NON-NLS-1$ - "No endpoint description advertiser available for endpointDescription=" //$NON-NLS-1$ - + endpointDescription); - - return advertiser; - } - public void close() { - synchronized (endpointDescriptionAdvertiserTrackerLock) { - if (endpointDescriptionAdvertiserTracker != null) { - endpointDescriptionAdvertiserTracker.close(); - endpointDescriptionAdvertiserTracker = null; - } - } synchronized (remoteServiceAdminTrackerLock) { if (remoteServiceAdminTracker != null) { remoteServiceAdminTracker.close(); @@ -129,8 +100,28 @@ public abstract class AbstractTopologyManager { + "=*))"; //$NON-NLS-1$ try { return getContext().createFilter(filterString); - } catch (InvalidSyntaxException e) { + } catch (InvalidSyntaxException doesNotHappen) { + // Should never happen + doesNotHappen.printStackTrace(); + return null; + } + } + + /** + * @since 4.0 + */ + protected Filter createISIFFilter() { + String filterString = "(" //$NON-NLS-1$ + + org.osgi.framework.Constants.OBJECTCLASS + + "=" //$NON-NLS-1$ + + IServiceInfoFactory.class + .getName() + + ")"; //$NON-NLS-1$ + try { + return getContext().createFilter(filterString); + } catch (InvalidSyntaxException doesNotHappen) { // Should never happen + doesNotHappen.printStackTrace(); return null; } } @@ -152,16 +143,29 @@ public abstract class AbstractTopologyManager { */ protected void advertiseEndpointDescription( org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) { - // forward to all other endpoint listener - IEndpointDescriptionAdvertiser advertiser = getEndpointDescriptionAdvertiser(endpointDescription); - if (advertiser != null) { - // Now advertise endpoint description using endpoint description - // advertiser - trace("advertiseEndpointDescription", //$NON-NLS-1$ - "advertising endpointDescription=" + endpointDescription //$NON-NLS-1$ - + " with advertiser=" + advertiser); //$NON-NLS-1$ - handleAdvertisingResult(advertiser.advertise(endpointDescription), - endpointDescription, true); + final IServiceInfoFactory service = serviceInfoFactoryTracker + .getService(); + if (service != null) { + final IServiceInfo serviceInfo = service.createServiceInfo(null, + endpointDescription); + if (serviceInfo != null) { + trace("advertiseEndpointDescription", //$NON-NLS-1$ + "advertising endpointDescription=" + endpointDescription + //$NON-NLS-1$ + " and IServiceInfo " + serviceInfo); //$NON-NLS-1$ + + final ServiceRegistration<IServiceInfo> registerService = this.context + .registerService(IServiceInfo.class, serviceInfo, null); + this.registrations.put(endpointDescription, registerService); + + } else { + logError( + "advertiseEndpointDescription", //$NON-NLS-1$ + "IServiceInfoFactory failed to convert EndpointDescription " + endpointDescription); //$NON-NLS-1$1 + } + } else { + logError( + "advertiseEndpointDescription", //$NON-NLS-1$ + "no IServiceInfoFactory service found"); //$NON-NLS-1$ } } @@ -170,52 +174,15 @@ public abstract class AbstractTopologyManager { */ protected void unadvertiseEndpointDescription( org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) { - IEndpointDescriptionAdvertiser advertiser = getEndpointDescriptionAdvertiser(endpointDescription); - if (advertiser != null) { - // Now unadvertise endpoint description using endpoint description - // advertiser - trace("unadvertiseEndpointDescription", //$NON-NLS-1$ - "unadvertising endpointDescription=" + endpointDescription //$NON-NLS-1$ - + " with advertiser=" + advertiser); //$NON-NLS-1$ - handleAdvertisingResult( - advertiser.unadvertise(endpointDescription), - endpointDescription, false); - } - } - - /** - * @since 3.0 - */ - protected void advertiseEndpointDescription( - EndpointDescription endpointDescription) { - // forward to all other endpoint listener - IEndpointDescriptionAdvertiser advertiser = getEndpointDescriptionAdvertiser(endpointDescription); - if (advertiser != null) { - // Now advertise endpoint description using endpoint description - // advertiser - trace("advertiseEndpointDescription", //$NON-NLS-1$ - "advertising endpointDescription=" + endpointDescription //$NON-NLS-1$ - + " with advertiser=" + advertiser); //$NON-NLS-1$ - handleAdvertisingResult(advertiser.advertise(endpointDescription), - endpointDescription, true); - } - } - - /** - * @since 3.0 - */ - protected void unadvertiseEndpointDescription( - EndpointDescription endpointDescription) { - IEndpointDescriptionAdvertiser advertiser = getEndpointDescriptionAdvertiser(endpointDescription); - if (advertiser != null) { - // Now unadvertise endpoint description using endpoint description - // advertiser - trace("unadvertiseEndpointDescription", //$NON-NLS-1$ - "unadvertising endpointDescription=" + endpointDescription //$NON-NLS-1$ - + " with advertiser=" + advertiser); //$NON-NLS-1$ - handleAdvertisingResult( - advertiser.unadvertise(endpointDescription), - endpointDescription, false); + final ServiceRegistration<IServiceInfo> serviceRegistration = this.registrations + .get(endpointDescription); + if (serviceRegistration != null) { + serviceRegistration.unregister(); + } else { + logWarning("unadvertiseEndpointDescription", //$NON-NLS-1$ + "Failed to unadvertise endpointDescription: " //$NON-NLS-1$ + + endpointDescription + + ". Seems it was never advertised."); //$NON-NLS-1$ } } @@ -310,8 +277,9 @@ public abstract class AbstractTopologyManager { listeners = context.getServiceReferences( EndpointListener.class.getName(), "(" + EndpointListener.ENDPOINT_LISTENER_SCOPE + "=*)"); //$NON-NLS-1$//$NON-NLS-2$ - } catch (InvalidSyntaxException e) { + } catch (InvalidSyntaxException doesNotHappen) { // Should never happen + doesNotHappen.printStackTrace(); } if (listeners != null) { for (int i = 0; i < listeners.length; i++) { @@ -436,5 +404,4 @@ public abstract class AbstractTopologyManager { } } } - } 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 deleted file mode 100644 index 6b4f78d35..000000000 --- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescriptionAdvertiser.java +++ /dev/null @@ -1,296 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Composent, Inc. - initial API and implementation - ******************************************************************************/ -package org.eclipse.ecf.osgi.services.remoteserviceadmin; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.PatternSyntaxException; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.ecf.core.jobs.JobsExecutor; -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; -import org.eclipse.equinox.concurrent.future.IExecutor; -import org.eclipse.equinox.concurrent.future.IProgressRunnable; -import org.eclipse.equinox.concurrent.future.ImmediateExecutor; -import org.eclipse.equinox.concurrent.future.ThreadsExecutor; - -/** - * Default implementation of {@link IEndpointDescriptionAdvertiser}. - * - */ -public class EndpointDescriptionAdvertiser implements - IEndpointDescriptionAdvertiser { - - private static final String advertiserFilter = System - .getProperty("org.eclipse.ecf.osgi.services.remoteserviceadmin.endpointDescriptionDiscoveryAdvertiserFilter"); //$NON-NLS-1$ - - private static final String executorType = System - .getProperty( - "org.eclipse.ecf.osgi.services.remoteserviceadmin.endpointDescriptionDiscoveryAdvertiserExecutorType", "immediate"); //$NON-NLS-1$ //$NON-NLS-2$ - - private EndpointDescriptionLocator endpointDescriptionLocator; - private List<String> filteredAdvertisers = new ArrayList<String>(); - - public EndpointDescriptionAdvertiser( - EndpointDescriptionLocator endpointDescriptionLocator) { - this.endpointDescriptionLocator = endpointDescriptionLocator; - if (advertiserFilter != null) { - try { - String[] fas = advertiserFilter.split(","); //$NON-NLS-1$ - if (fas != null) - for (int i = 0; i < fas.length; i++) - filteredAdvertisers.add(fas[i]); - } catch (PatternSyntaxException e) { - // should never happen - } - } - for (String filteredAdvertiser : filteredAdvertisers) - trace("EndpointDescriptionAdvertiser<init>", //$NON-NLS-1$ - "filtering advertiser=" + filteredAdvertiser); //$NON-NLS-1$ - } - - private IExecutor createExecutor() { - if (executorType.equals("jobs")) { //$NON-NLS-1$ - return new JobsExecutor(this.getClass().getName()); - } else if (executorType.equals("threads")) { //$NON-NLS-1$ - return new ThreadsExecutor(); - } else - return new ImmediateExecutor(); - } - - private IExecutor executor; - - private IExecutor getExecutor() { - synchronized (this) { - if (executor == null) - executor = createExecutor(); - return executor; - } - } - - /** - * @since 3.0 - */ - public IStatus advertise(EndpointDescription endpointDescription) { - return doDiscovery(endpointDescription, true); - } - - /** - * @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( - final IDiscoveryAdvertiser discoveryAdvertiser, - final IServiceInfo serviceInfo, final boolean advertise) { - IProgressRunnable<IStatus> runnable = new IProgressRunnable<IStatus>() { - public IStatus run(IProgressMonitor monitor) throws Exception { - try { - if (advertise) { - trace("doDiscovery", "discoveryAdvertiser=" + discoveryAdvertiser + " serviceInfo=" + serviceInfo); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - synchronized (discoveryAdvertiser) { - discoveryAdvertiser.registerService(serviceInfo); - } - } else { - trace("doUndiscovery", "discoveryAdvertiser=" + discoveryAdvertiser + " serviceInfo=" + serviceInfo); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - synchronized (discoveryAdvertiser) { - discoveryAdvertiser.unregisterService(serviceInfo); - } - } - } catch (Exception e) { - LogUtility - .logError( - "doDiscovery", DebugOptions.ENDPOINT_DESCRIPTION_ADVERTISER, this.getClass(), createErrorStatus("Unexplained exception in discoveryAdvertiserID=" + discoveryAdvertiser + " for serviceInfo=" + serviceInfo + " advertise=" + true)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - return null; - } - }; - // Start/do it - getExecutor().execute(runnable, null); - return Status.OK_STATUS; - } - - protected IServiceInfoFactory getServiceInfoFactory() { - return endpointDescriptionLocator.getServiceInfoFactory(); - } - - protected IDiscoveryAdvertiser[] getDiscoveryAdvertisers() { - IDiscoveryAdvertiser[] unfilteredAdvertisers = endpointDescriptionLocator - .getDiscoveryAdvertisers(); - List<IDiscoveryAdvertiser> results = new ArrayList<IDiscoveryAdvertiser>(); - if (unfilteredAdvertisers != null) - for (int i = 0; i < unfilteredAdvertisers.length; i++) { - String className = unfilteredAdvertisers[i].getClass() - .getName(); - if (!filteredAdvertisers.contains(className)) - results.add(unfilteredAdvertisers[i]); - else - LogUtility - .logWarning( - "getDiscoveryAdvertisers", DebugOptions.ENDPOINT_DESCRIPTION_ADVERTISER, this.getClass(), "Filtering out discoveryAdvertiser=" + className); //$NON-NLS-1$ //$NON-NLS-2$ - } - return results.toArray(new IDiscoveryAdvertiser[results.size()]); - } - - protected IStatus createErrorStatus(String message) { - return createErrorStatus(message, null); - } - - protected IStatus createErrorStatus(String message, Throwable e) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, message, e); - } - - /** - * @since 3.0 - */ - protected IStatus doDiscovery(EndpointDescription endpointDescription, - boolean advertise) { - Assert.isNotNull(endpointDescription); - String messagePrefix = advertise ? "Advertise" : "Unadvertise"; //$NON-NLS-1$ //$NON-NLS-2$ - List<IStatus> statuses = new ArrayList<IStatus>(); - // First get serviceInfoFactory - IServiceInfoFactory serviceInfoFactory = getServiceInfoFactory(); - if (serviceInfoFactory == null) - return createErrorStatus(messagePrefix - + " endpointDescription=" //$NON-NLS-1$ - + endpointDescription - + ". No IServiceInfoFactory is available. Cannot unpublish endpointDescription=" //$NON-NLS-1$ - + endpointDescription); - IDiscoveryAdvertiser[] discoveryAdvertisers = getDiscoveryAdvertisers(); - if (discoveryAdvertisers == null || discoveryAdvertisers.length == 0) - return createErrorStatus(messagePrefix - + " endpointDescription=" //$NON-NLS-1$ - + endpointDescription - + ". No endpointDescriptionLocator advertisers available. Cannot " //$NON-NLS-1$ - + (advertise ? "publish" : "unpublish") //$NON-NLS-1$ //$NON-NLS-2$ - + " endpointDescription=" //$NON-NLS-1$ - + endpointDescription); - for (int i = 0; i < discoveryAdvertisers.length; i++) { - IServiceInfo serviceInfo = (advertise ? serviceInfoFactory - .createServiceInfo(discoveryAdvertisers[i], - endpointDescription) : serviceInfoFactory - .removeServiceInfo(discoveryAdvertisers[i], - endpointDescription)); - if (serviceInfo == null) { - statuses.add(createErrorStatus(messagePrefix - + " endpointDescription=" //$NON-NLS-1$ - + endpointDescription - + ". Service Info is null. Cannot publish endpointDescription=" //$NON-NLS-1$ - + endpointDescription)); - continue; - } - // Now actually unregister with advertiser - statuses.add(doDiscovery(discoveryAdvertisers[i], serviceInfo, - advertise)); - } - return createResultStatus(statuses, messagePrefix - + " endpointDesription=" + endpointDescription //$NON-NLS-1$ - + ". Problem in unadvertise"); //$NON-NLS-1$ - } - - /** - * @since 3.0 - */ - public IStatus unadvertise(EndpointDescription endpointDescription) { - return doDiscovery(endpointDescription, false); - } - - private IStatus createResultStatus(List<IStatus> statuses, - String errorMessage) { - List<IStatus> errorStatuses = new ArrayList<IStatus>(); - for (IStatus status : statuses) - if (!status.isOK()) - errorStatuses.add(status); - if (errorStatuses.size() > 0) - return new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, - (IStatus[]) statuses.toArray(new IStatus[statuses.size()]), - errorMessage, null); - else - return Status.OK_STATUS; - } - - public void close() { - this.filteredAdvertisers.clear(); - this.endpointDescriptionLocator = null; - executor = null; - } - - public IStatus advertise( - org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) { - return doDiscovery(endpointDescription, true); - } - - protected IStatus doDiscovery( - org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription, - boolean advertise) { - Assert.isNotNull(endpointDescription); - String messagePrefix = advertise ? "Advertise" : "Unadvertise"; //$NON-NLS-1$ //$NON-NLS-2$ - List<IStatus> statuses = new ArrayList<IStatus>(); - // First get serviceInfoFactory - IServiceInfoFactory serviceInfoFactory = getServiceInfoFactory(); - if (serviceInfoFactory == null) - return createErrorStatus(messagePrefix - + " endpointDescription=" //$NON-NLS-1$ - + endpointDescription - + ". No IServiceInfoFactory is available. Cannot unpublish endpointDescription=" //$NON-NLS-1$ - + endpointDescription); - IDiscoveryAdvertiser[] discoveryAdvertisers = getDiscoveryAdvertisers(); - if (discoveryAdvertisers == null || discoveryAdvertisers.length == 0) - return createErrorStatus(messagePrefix - + " endpointDescription=" //$NON-NLS-1$ - + endpointDescription - + ". No endpointDescriptionLocator advertisers available. Cannot " //$NON-NLS-1$ - + (advertise ? "publish" : "unpublish") //$NON-NLS-1$ //$NON-NLS-2$ - + " endpointDescription=" //$NON-NLS-1$ - + endpointDescription); - for (int i = 0; i < discoveryAdvertisers.length; i++) { - IServiceInfo serviceInfo = (advertise ? serviceInfoFactory - .createServiceInfo(discoveryAdvertisers[i], - endpointDescription) : serviceInfoFactory - .removeServiceInfo(discoveryAdvertisers[i], - endpointDescription)); - if (serviceInfo == null) { - statuses.add(createErrorStatus(messagePrefix - + " endpointDescription=" //$NON-NLS-1$ - + endpointDescription - + ". Service Info is null. Cannot publish endpointDescription=" //$NON-NLS-1$ - + endpointDescription)); - continue; - } - // Now actually unregister with advertiser - statuses.add(doDiscovery(discoveryAdvertisers[i], serviceInfo, - advertise)); - } - return createResultStatus(statuses, messagePrefix - + " endpointDesription=" + endpointDescription //$NON-NLS-1$ - + ". Problem in unadvertise"); //$NON-NLS-1$ - } - - public IStatus unadvertise( - org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) { - return doDiscovery(endpointDescription, false); - } - -} diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionAdvertiser.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionAdvertiser.java deleted file mode 100644 index f1f293fdd..000000000 --- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IEndpointDescriptionAdvertiser.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Composent, Inc. - initial API and implementation - ******************************************************************************/ -package org.eclipse.ecf.osgi.services.remoteserviceadmin; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.ecf.discovery.IDiscoveryAdvertiser; - -/** - * Endpoint description advertiser service. TopologyManager consumers may use - * this service to advertise/publish endpoint descriptions for discovery. - * Typically, implementations of this service will use the ECF Discovery API to - * advertise/publish EndpointDescriptions over the network. For example, this is - * what {@link EndpointDescriptionAdvertiser} does...i.e. it - * advertises/unadvertises endpoint descriptions by calling and/all available - * instances of - * {@link org.eclipse.ecf.discovery.IDiscoveryAdvertiser#registerService(org.eclipse.ecf.discovery.IServiceInfo)} - * . - * <p> - * <p> - * Note, however, that other implementations of endpoint description advertisers - * are possible that do not use ECF Discovery...or use ECF Discovery in other - * ways. For example, some TopologyManagers may wish to advertise exported - * remote services by creating a static xml file describing the endpoint by - * using the Endpoint Description Extender Format (EDEF) described in section - * 122.8 of the <a - * href="http://www.osgi.org/download/r4v42/r4.enterprise.pdf">OSGi Enterprise - * Specification</a> by calling {@link #advertise(EndpointDescription)} on their - * own implementation of this service that uses an - * {@link EndpointDescriptionWriter} to create an EDEF bundle. - * <p> - * <p> - * If no other instances of this service have been registered, a default - * instance of {@link EndpointDescriptionAdvertiser} will be used. The default - * instance uses ECF {@link IDiscoveryAdvertiser}s to publish the endpoint - * description. Note that the default instance is registered with the lowest - * possible priority, so that if other {@link IEndpointDescriptionAdvertiser} - * instances are registered, they will be preferred/used over the default. - */ -public interface IEndpointDescriptionAdvertiser { - - /** - * Advertise/publish the given endpoint description. - * - * @param endpointDescription - * the endpoint description to advertise. Must not be - * <code>null</code>. - * @return IStatus to indicate the status of the advertisement. If the - * returned status returns <code>false</code> from - * {@link IStatus#isOK()}, then the advertisement failed. The - * IStatus can be further inspected for exception information and/or - * child statuses. - * - * @see IStatus - * @since 3.0 - */ - public IStatus advertise(EndpointDescription endpointDescription); - - /** - * Unadvertise/unpublishe the given endpoint description. - * - * @param endpointDescription - * the endpoint description to unadvertise. Must not be - * <code>null</code>. - * @return IStatus to indicate the status of the unadvertisement. If the - * returned status returns <code>false</code> from - * {@link IStatus#isOK()}, then the unadvertisement failed. The - * IStatus can be further inspected for exception information and/or - * child statuses. - * - * @see IStatus - * @since 3.0 - */ - public IStatus unadvertise(EndpointDescription endpointDescription); - - /** - * Advertise/publish the given endpoint description. - * - * @param endpointDescription - * the endpoint description to advertise. Must not be - * <code>null</code>. - * @return IStatus to indicate the status of the advertisement. If the - * returned status returns <code>false</code> from - * {@link IStatus#isOK()}, then the advertisement failed. The - * IStatus can be further inspected for exception information and/or - * child statuses. - * - * @since 3.0 - * @see IStatus - */ - public IStatus advertise( - org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription); - - /** - * Unadvertise/unpublishe the given endpoint description. - * - * @param endpointDescription - * the endpoint description to unadvertise. Must not be - * <code>null</code>. - * @return IStatus to indicate the status of the unadvertisement. If the - * returned status returns <code>false</code> from - * {@link IStatus#isOK()}, then the unadvertisement failed. The - * IStatus can be further inspected for exception information and/or - * child statuses. - * - * @since 3.0 - * @see IStatus - */ - public IStatus unadvertise( - org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription); - -} diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IServiceInfoFactory.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IServiceInfoFactory.java index 55cc586b8..104b8e795 100644 --- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IServiceInfoFactory.java +++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/IServiceInfoFactory.java @@ -67,26 +67,4 @@ public interface IServiceInfoFactory { public IServiceInfo createServiceInfo( IDiscoveryAdvertiser advertiser, org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription); - -/** - * Remove any previously created service info that is associated with the - * given endpointDescription (and advertiser). - * - * @param advertiser - * the advertiser associated with the service info previously - * created. Must not be <code>null</code>. - * @param endpointDescription - * the endpoint description that the service info was previously - * created for. Must not be <code>null</code>. - * @return IServiceInfo to use to unpublish the endpointDescription for - * discovery (via - * {@link IDiscoveryAdvertiser#unregisterService(IServiceInfo)). If - * <code>null</code> no service info exists that had previously been - * created for the given endpointDescription and advertiser. - * @since 3.0 - */ - public IServiceInfo removeServiceInfo( - IDiscoveryAdvertiser advertiser, - org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription); - } diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ServiceInfoFactory.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ServiceInfoFactory.java index d5a2eb52d..f8159d356 100644 --- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ServiceInfoFactory.java +++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/ServiceInfoFactory.java @@ -12,7 +12,6 @@ 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; @@ -33,41 +32,6 @@ import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.PropertiesUtil; public class ServiceInfoFactory extends AbstractMetadataFactory implements IServiceInfoFactory { - protected Map<ServiceInfoKey, IServiceInfo> serviceInfos = new HashMap(); - - protected class ServiceInfoKey { - private org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription; - private Namespace discoveryNamespace; - private int hashCode = 7; - - /** - * @since 3.0 - */ - public ServiceInfoKey( - org.osgi.service.remoteserviceadmin.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; - } - } - /** * @since 3.0 */ @@ -75,15 +39,6 @@ public class ServiceInfoFactory extends AbstractMetadataFactory implements IDiscoveryAdvertiser advertiser, org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) { try { - 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, @@ -95,10 +50,7 @@ public class ServiceInfoFactory extends AbstractMetadataFactory implements serviceName, uri); IServiceInfo newServiceInfo = createServiceInfo(uri, serviceName, serviceTypeID, serviceProperties); - // put into map using key - serviceInfos.put(key, newServiceInfo); return newServiceInfo; - } } catch (Exception e) { logError( "createServiceInfo", //$NON-NLS-1$ @@ -213,6 +165,13 @@ public class ServiceInfoFactory extends AbstractMetadataFactory implements protected IServiceTypeID createServiceTypeID( org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription, IDiscoveryAdvertiser advertiser) { + + Namespace servicesNamespace = IDFactory.getDefault() + .getNamespaceByName("ecf.namespace.discovery"); //$NON-NLS-1$ + if (advertiser != null) { + servicesNamespace = advertiser.getServicesNamespace(); + } + Map props = endpointDescription.getProperties(); String[] scopes = PropertiesUtil.getStringArrayWithDefault(props, RemoteConstants.DISCOVERY_SCOPE, IServiceTypeID.DEFAULT_SCOPE); @@ -223,33 +182,8 @@ public class ServiceInfoFactory extends AbstractMetadataFactory implements RemoteConstants.DISCOVERY_NAMING_AUTHORITY, IServiceTypeID.DEFAULT_NA); return ServiceIDFactory.getDefault().createServiceTypeID( - advertiser.getServicesNamespace(), + servicesNamespace, new String[] { RemoteConstants.DISCOVERY_SERVICE_TYPE }, scopes, protocols, namingAuthority); } - - public void close() { - removeAllServiceInfos(); - super.close(); - } - - private void removeAllServiceInfos() { - synchronized (serviceInfos) { - serviceInfos.clear(); - } - } - - /** - * @since 3.0 - */ - public IServiceInfo removeServiceInfo( - IDiscoveryAdvertiser advertiser, - org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) { - Namespace advertiserNamespace = advertiser.getServicesNamespace(); - ServiceInfoKey key = new ServiceInfoKey(endpointDescription, - advertiserNamespace); - synchronized (serviceInfos) { - return serviceInfos.remove(key); - } - } } |