diff options
author | slewis | 2018-02-28 03:11:49 +0000 |
---|---|---|
committer | slewis | 2018-02-28 03:11:49 +0000 |
commit | cdec999cfe3c26e21186d523106a887d35fdaeb8 (patch) | |
tree | 9d52faf4285a160f16e47cee792e559f83dd6791 /compendium/bundles/org.eclipse.ecf.osgi.services.distribution | |
parent | 7421d1219725f3f87e443ed88024f8fb94c1eee4 (diff) | |
download | org.eclipse.ecf-cdec999cfe3c26e21186d523106a887d35fdaeb8.tar.gz org.eclipse.ecf-cdec999cfe3c26e21186d523106a887d35fdaeb8.tar.xz org.eclipse.ecf-cdec999cfe3c26e21186d523106a887d35fdaeb8.zip |
Simplification of BasicTopologyManager
Change-Id: I77ac6269d7c413b656c0f017bb23b2536a765aa1
Diffstat (limited to 'compendium/bundles/org.eclipse.ecf.osgi.services.distribution')
8 files changed, 50 insertions, 989 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 7a3a21d00..1840a94c9 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 @@ -4,20 +4,15 @@ Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.ecf.osgi.services.distribution Automatic-Module-Name: org.eclipse.ecf.osgi.services.distribution Bundle-Version: 2.1.200.qualifier -Bundle-Activator: org.eclipse.ecf.internal.osgi.services.distribution.Activator Bundle-Vendor: %pluginProvider Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Import-Package: org.eclipse.ecf.core.util, - org.eclipse.ecf.osgi.services.remoteserviceadmin;version="1.0.0", +Import-Package: org.eclipse.ecf.osgi.services.remoteserviceadmin;version="1.0.0", org.osgi.framework;version="1.3.0", org.osgi.framework.hooks.service;version="1.1.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 + org.osgi.service.component.annotations;resolution:=optional, + org.osgi.service.remoteserviceadmin;version="1.0" Bundle-Localization: plugin Export-Package: org.eclipse.ecf.osgi.services.distribution;version="2.0.0";x-internal:=true -Require-Bundle: org.eclipse.equinox.common Bundle-ActivationPolicy: lazy -Service-Component: OSGI-INF/eventhookcomponent.xml Provide-Capability: osgi.remoteserviceadmin.topology; policy:List<String>="promiscuous"; version:Version=1.1 +Service-Component: OSGI-INF/org.eclipse.ecf.internal.osgi.services.distribution.BasicTopologyManager.xml 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 deleted file mode 100644 index 25a1994ad..000000000 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/OSGI-INF/eventhookcomponent.xml +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" immediate="true" name="org.eclipse.ecf.osgi.services.distribution.basictopologymanager"> - <implementation class="org.eclipse.ecf.internal.osgi.services.distribution.BasicTopologyManagerComponent"/> - <service> - <provide interface="org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener"/> - <provide interface="org.osgi.framework.hooks.service.EventListenerHook"/> - </service> - <reference bind="bindEndpointEventListener" cardinality="1..n" interface="org.osgi.service.remoteserviceadmin.EndpointEventListener" name="EndpointEventListener" policy="static" unbind="unbindEndpointEventListener"/> - <property name="event.topics" type="String" value="org/osgi/service/remoteserviceadmin/*"/> -</scr:component> diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/OSGI-INF/org.eclipse.ecf.internal.osgi.services.distribution.BasicTopologyManager.xml b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/OSGI-INF/org.eclipse.ecf.internal.osgi.services.distribution.BasicTopologyManager.xml new file mode 100644 index 000000000..352d7358c --- /dev/null +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/OSGI-INF/org.eclipse.ecf.internal.osgi.services.distribution.BasicTopologyManager.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" immediate="true" name="org.eclipse.ecf.internal.osgi.services.distribution.BasicTopologyManager"> + <service> + <provide interface="org.osgi.framework.hooks.service.EventListenerHook"/> + <provide interface="org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener"/> + <provide interface="org.eclipse.ecf.osgi.services.remoteserviceadmin.ITopologyManager"/> + </service> + <implementation class="org.eclipse.ecf.internal.osgi.services.distribution.BasicTopologyManager"/> +</scr:component>
\ No newline at end of file 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 deleted file mode 100644 index 9086d476a..000000000 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java +++ /dev/null @@ -1,414 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.internal.osgi.services.distribution; - -import java.util.ArrayList; -import java.util.Dictionary; -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.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.ecf.core.util.LogHelper; -import org.eclipse.ecf.core.util.SystemLogService; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.ServiceFactory; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; -import org.osgi.framework.hooks.service.EventListenerHook; -import org.osgi.service.log.LogService; -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.osgi.service.remoteserviceadmin.EndpointEvent; -import org.osgi.service.remoteserviceadmin.EndpointEventListener; -import org.osgi.service.remoteserviceadmin.EndpointListener; -import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener; -import org.osgi.util.tracker.ServiceTracker; - -public class Activator implements BundleActivator { - - public static final String PLUGIN_ID = "org.eclipse.ecf.osgi.services.distribution"; //$NON-NLS-1$ - - public static final boolean autoCreateProxyContainer = new Boolean( - System.getProperty( - "org.eclipse.ecf.osgi.services.distribution.autoCreateProxyContainer", //$NON-NLS-1$ - "true")).booleanValue(); //$NON-NLS-1$ - - public static final boolean autoCreateHostContainer = new Boolean( - System.getProperty( - "org.eclipse.ecf.osgi.services.distribution.autoCreateHostContainer", //$NON-NLS-1$ - "true")).booleanValue(); //$NON-NLS-1$ - - public static final String defaultHostConfigType = System.getProperty( - "org.eclipse.ecf.osgi.services.distribution.defaultConfigType", //$NON-NLS-1$ - "ecf.generic.server"); //$NON-NLS-1$ - - private static final String PROP_USE_DS = "equinox.use.ds"; //$NON-NLS-1$ - - private static Activator plugin; - private BundleContext context; - - private ServiceTracker logServiceTracker = null; - private LogService logService = null; - - private BasicTopologyManagerImpl basicTopologyManagerImpl; - private ServiceRegistration endpointListenerReg; - private ServiceRegistration endpointEventListenerReg; - private Map<Bundle, List<EndpointEventHolder>> bundleEndpointEventListenerMap = new HashMap<Bundle, List<EndpointEventHolder>>(); - - private BasicTopologyManagerComponent basicTopologyManagerComp; - private ServiceRegistration eventListenerHookRegistration; - private ServiceRegistration eventAdminListenerRegistration; - - private static final boolean disableBasicTopologyManager = new Boolean( - System.getProperty( - "org.eclipse.ecf.osgi.services.distribution.disableBasicTopologyManager", //$NON-NLS-1$ - "false")).booleanValue(); //$NON-NLS-1$ - - private OSGiTopologyManagerImpl osgiTopologyManagerImpl; - - public static Activator getDefault() { - return plugin; - } - - public BundleContext getContext() { - return context; - } - - protected LogService getLogService() { - if (this.context == null) - return null; - if (logServiceTracker == null) { - logServiceTracker = new ServiceTracker(this.context, - LogService.class.getName(), null); - logServiceTracker.open(); - } - logService = (LogService) logServiceTracker.getService(); - if (logService == null) - logService = new SystemLogService(PLUGIN_ID); - return logService; - } - - public void log(IStatus status) { - if (logService == null) - logService = getLogService(); - if (logService != null) - logService.log(null, LogHelper.getLogCode(status), - LogHelper.getLogMessage(status), status.getException()); - } - - public void log(ServiceReference sr, IStatus status) { - log(sr, LogHelper.getLogCode(status), LogHelper.getLogMessage(status), - status.getException()); - } - - public void log(ServiceReference sr, int level, String message, Throwable t) { - if (logService == null) - logService = getLogService(); - if (logService != null) - logService.log(sr, level, message, t); - } - - class EndpointEventHolder { - private final EndpointDescription endpointDescription; - private final String filter; - - public EndpointEventHolder(EndpointDescription d, String f) { - this.endpointDescription = d; - this.filter = f; - } - - public EndpointDescription getEndpoint() { - return this.endpointDescription; - } - - public String getFilter() { - return this.filter; - } - } - - public class ProxyEndpointEventListener implements EndpointEventListener { - - private final Bundle bundle; - - public ProxyEndpointEventListener(Bundle b) { - this.bundle = b; - } - - public void endpointChanged(EndpointEvent event, String filter) { - int type = event.getType(); - if (type == EndpointEvent.ADDED) { - synchronized (bundleEndpointEventListenerMap) { - List<EndpointEventHolder> endpointEventHolders = bundleEndpointEventListenerMap - .get(this.bundle); - if (endpointEventHolders == null) - // create new one - endpointEventHolders = new ArrayList<EndpointEventHolder>(); - endpointEventHolders.add(new EndpointEventHolder(event - .getEndpoint(), filter)); - bundleEndpointEventListenerMap.put(this.bundle, - endpointEventHolders); - } - } else if (type == EndpointEvent.REMOVED) { - synchronized (bundleEndpointEventListenerMap) { - List<EndpointEventHolder> endpointEventHolders = bundleEndpointEventListenerMap - .get(this.bundle); - if (endpointEventHolders != null) { - for (Iterator<EndpointEventHolder> i = endpointEventHolders - .iterator(); i.hasNext();) { - EndpointEventHolder eh = i.next(); - EndpointDescription oldEd = eh.getEndpoint(); - EndpointDescription newEd = event.getEndpoint(); - if (oldEd.equals(newEd)) - i.remove(); - } - if (endpointEventHolders.size() == 0) - bundleEndpointEventListenerMap.remove(this.bundle); - } - - } - } - // Actually call underlying listener - deliverSafe(event, filter); - } - - public BasicTopologyManagerImpl getBasicTopologyManagerImpl() { - return Activator.this.basicTopologyManagerImpl; - } - - private void logError(String methodName, String message, Throwable e) { - getDefault().log( - new Status(IStatus.ERROR, Activator.PLUGIN_ID, - IStatus.ERROR, Activator.class.getName() + ":" //$NON-NLS-1$ - + ((methodName == null) ? "<unknown>" //$NON-NLS-1$ - : methodName) + ":" //$NON-NLS-1$ - + ((message == null) ? "<empty>" //$NON-NLS-1$ - : message), e)); - } - - private void deliverSafe(EndpointEvent endpointEvent, - String matchingFilter) { - EndpointEventListener listener = Activator.this.basicTopologyManagerImpl; - if (listener == null) - return; - try { - listener.endpointChanged(endpointEvent, matchingFilter); - } catch (Exception e) { - String message = "Exception in EndpointEventListener listener=" //$NON-NLS-1$ - + listener + " event=" //$NON-NLS-1$ - + endpointEvent + " matchingFilter=" //$NON-NLS-1$ - + matchingFilter; - logError("deliverSafe", message, e); //$NON-NLS-1$ - } catch (LinkageError e) { - String message = "LinkageError in EndpointEventListener listener=" //$NON-NLS-1$ - + listener + " event=" //$NON-NLS-1$ - + endpointEvent + " matchingFilter=" //$NON-NLS-1$ - + matchingFilter; - logError("deliverSafe", message, e); //$NON-NLS-1$ - } catch (AssertionError e) { - String message = "AssertionError in EndpointEventListener listener=" //$NON-NLS-1$ - + listener + " event=" //$NON-NLS-1$ - + endpointEvent + " matchingFilter=" //$NON-NLS-1$ - + matchingFilter; - logError("deliverSafe", message, e); //$NON-NLS-1$ - } - } - - public void deliverRemoveEventForBundle(EndpointEventHolder eventHolder) { - deliverSafe( - new EndpointEvent(EndpointEvent.REMOVED, - eventHolder.getEndpoint()), eventHolder.getFilter()); - } - } - - /* - * (non-Javadoc) - * - * @see - * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext - * ) - */ - public void start(final BundleContext ctxt) throws Exception { - // Always set plugin and context - plugin = this; - this.context = ctxt; - // If BasicTopologyManager has been disabled (default), then - // use OSGiTopologyManager - if (disableBasicTopologyManager) { - osgiTopologyManagerImpl = new OSGiTopologyManagerImpl(context); - - Properties props = new Properties(); - props.put( - org.osgi.service.remoteserviceadmin.EndpointEventListener.ENDPOINT_LISTENER_SCOPE, - osgiTopologyManagerImpl.getScope()); - - // Register as deprecated EndpointListener - endpointListenerReg = getContext().registerService( - EndpointListener.class.getName(), osgiTopologyManagerImpl, - (Dictionary) props); - - // Also register as EndpointEventListener - endpointEventListenerReg = getContext().registerService( - EndpointEventListener.class.getName(), - osgiTopologyManagerImpl, (Dictionary) props); - - // export any previously registered remote services by calling - // activate - osgiTopologyManagerImpl.activate(); - - } else { - // Create basicTopologyManagerImpl - basicTopologyManagerImpl = new BasicTopologyManagerImpl(context); - - // Register basicTopologyManagerImpl as EndpointListener always, so - // that - // gets notified when Endpoints are discovered - Properties props = new Properties(); - props.put( - org.osgi.service.remoteserviceadmin.EndpointEventListener.ENDPOINT_LISTENER_SCOPE, - basicTopologyManagerImpl.getScope()); - - // Register as deprecated EndpointListener - // endpointListenerReg = getContext().registerService( - // EndpointListener.class.getName(), basicTopologyManagerImpl, - // (Dictionary) props); - - // As per section 122.6.3/Tracking providers -Tracking providers – - // An - // Endpoint Event - // Listener or Endpoint Listener must track the bundles that provide - // it - // with - // Endpoint Descriptions. If a bundle that provided Endpoint - // Descriptions is - // stopped, all Endpoint Descriptions that were provided by that - // bundle - // must - // be removed. This can be implemented straightforwardly with a - // Service - // Factory - endpointEventListenerReg = getContext().registerService( - EndpointEventListener.class.getName(), - new ServiceFactory() { - public Object getService(Bundle bundle, - ServiceRegistration registration) { - return new ProxyEndpointEventListener(bundle); - } - - public void ungetService(Bundle bundle, - ServiceRegistration registration, Object service) { - ProxyEndpointEventListener peel = (service instanceof ProxyEndpointEventListener) ? (ProxyEndpointEventListener) service - : null; - if (peel == null) - return; - synchronized (bundleEndpointEventListenerMap) { - List<EndpointEventHolder> endpointEventHolders = bundleEndpointEventListenerMap - .get(bundle); - if (endpointEventHolders != null) - for (EndpointEventHolder eh : endpointEventHolders) - peel.deliverRemoveEventForBundle(eh); - } - } - }, (Dictionary) props); - - // Like EventAdmin, if equinox ds is running, then we simply return - // (no - // more to do) - if (Boolean.valueOf(context.getProperty(PROP_USE_DS)) - .booleanValue()) - return; // If this property is set we assume DS is being used. - - // The following code is to make sure that we don't do any more if - // EventListenerHook has already been registered for us by DS - // Create serviceFilter for EventListenerHook classname - String serviceName = EventListenerHook.class.getName(); - Filter serviceFilter = context - .createFilter("(objectclass=" + serviceName + ")"); //$NON-NLS-1$ //$NON-NLS-2$ - // if this bundle has already registered EventListenerHook service - // via - // ds, then - // we're done - ServiceReference[] refs = context.getBundle() - .getRegisteredServices(); - if (refs != null) { - for (int i = 0; i < refs.length; i++) - if (serviceFilter.match(refs[i])) - return; // We found a service registered by this bundle - // already so we return - } - - // Otherwise (no DS), we create a basicTopologyManagerComponent - basicTopologyManagerComp = new BasicTopologyManagerComponent(); - // bind the topology manager to it - basicTopologyManagerComp - .bindEndpointEventListener(basicTopologyManagerImpl); - // Register RemoteServiceAdminListener - eventAdminListenerRegistration = this.context.registerService( - RemoteServiceAdminListener.class, basicTopologyManagerComp, - null); - // register the basic topology manager as EventListenerHook service - eventListenerHookRegistration = this.context.registerService( - EventListenerHook.class, basicTopologyManagerComp, null); - // export any previously registered remote services by calling - // activate - basicTopologyManagerComp.activate(); - - } - } - - /* - * (non-Javadoc) - * - * @see - * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext ctxt) throws Exception { - if (eventListenerHookRegistration != null) { - eventListenerHookRegistration.unregister(); - eventListenerHookRegistration = null; - } - if (basicTopologyManagerComp != null) { - basicTopologyManagerComp - .unbindEndpointEventListener(basicTopologyManagerImpl); - basicTopologyManagerComp = null; - } - if (endpointEventListenerReg != null) { - endpointEventListenerReg.unregister(); - endpointEventListenerReg = null; - } - if (endpointListenerReg != null) { - endpointListenerReg.unregister(); - endpointListenerReg = null; - } - if (eventAdminListenerRegistration != null) { - eventAdminListenerRegistration.unregister(); - eventAdminListenerRegistration = null; - } - synchronized (bundleEndpointEventListenerMap) { - bundleEndpointEventListenerMap.clear(); - } - if (basicTopologyManagerImpl != null) { - basicTopologyManagerImpl.close(); - basicTopologyManagerImpl = null; - } - if (logServiceTracker != null) { - logServiceTracker.close(); - logServiceTracker = null; - logService = null; - } - this.context = null; - plugin = null; - } - -} diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManager.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManager.java new file mode 100644 index 000000000..ab17a6e04 --- /dev/null +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManager.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2010 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.internal.osgi.services.distribution; + +import java.util.Map; +import org.eclipse.ecf.osgi.services.remoteserviceadmin.ITopologyManager; +import org.eclipse.ecf.osgi.services.remoteserviceadmin.TopologyManager; +import org.osgi.framework.BundleContext; +import org.osgi.framework.hooks.service.EventListenerHook; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener; + +@Component(immediate = true) +public class BasicTopologyManager extends TopologyManager + implements EventListenerHook, RemoteServiceAdminListener, ITopologyManager { + + @Activate + @Override + protected void activate(BundleContext context, Map<String, ?> properties) throws Exception { + super.activate(context, properties); + } + + @Deactivate + @Override + protected void deactivate() { + super.deactivate(); + } +} 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 deleted file mode 100644 index e5cdf0e48..000000000 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerComponent.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 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.internal.osgi.services.distribution; - -import java.util.Map; -import org.osgi.framework.ServiceEvent; -import org.osgi.framework.hooks.service.EventListenerHook; -import org.osgi.service.remoteserviceadmin.EndpointEventListener; -import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent; -import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener; - -public class BasicTopologyManagerComponent implements EventListenerHook, RemoteServiceAdminListener { - - private boolean exportRegisteredSvcs = new Boolean( - System.getProperty("org.eclipse.ecf.osgi.services.basictopologymanager.exportRegisteredSvcs", "true")) //$NON-NLS-1$ //$NON-NLS-2$ - .booleanValue(); - - private String exportRegisteredSvcsFilter = System.getProperty( - "org.eclipse.ecf.osgi.services.basictopologymanager.exportRegisteredSvcsFilter", //$NON-NLS-1$ - "(service.exported.interfaces=*)"); //$NON-NLS-1$ - - private String exportRegisteredSvcsClassname = System - .getProperty("org.eclipse.ecf.osgi.services.basictopologymanager.exportRegisteredSvcsClassname"); //$NON-NLS-1$ - - private BasicTopologyManagerImpl basicTopologyManagerImpl; - - void bindEndpointEventListener(EndpointEventListener el) { - if (el instanceof Activator.ProxyEndpointEventListener) - basicTopologyManagerImpl = ((Activator.ProxyEndpointEventListener) el).getBasicTopologyManagerImpl(); - else if (el instanceof BasicTopologyManagerImpl) - basicTopologyManagerImpl = (BasicTopologyManagerImpl) el; - } - - void unbindEndpointEventListener(EndpointEventListener el) { - basicTopologyManagerImpl = null; - } - - void activate() { - if (basicTopologyManagerImpl == null) - return; - if (exportRegisteredSvcs) - basicTopologyManagerImpl.exportRegisteredServices(exportRegisteredSvcsClassname, - exportRegisteredSvcsFilter); - } - - // RemoteServiceAdminListener impl - public void remoteAdminEvent(RemoteServiceAdminEvent event) { - if (basicTopologyManagerImpl == null) - return; - basicTopologyManagerImpl.handleRemoteAdminEvent(event); - } - - // EventListenerHook impl - public void event(ServiceEvent event, Map listeners) { - if (basicTopologyManagerImpl == null) - return; - basicTopologyManagerImpl.event(event, listeners); - } - -} 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 deleted file mode 100644 index 2194950ee..000000000 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/BasicTopologyManagerImpl.java +++ /dev/null @@ -1,202 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 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.internal.osgi.services.distribution; - -import java.util.Map; -import org.eclipse.ecf.osgi.services.remoteserviceadmin.AbstractTopologyManager; -import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription; -import org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteConstants; -import org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin; -import org.osgi.framework.BundleContext; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceEvent; -import org.osgi.framework.ServiceReference; -import org.osgi.service.remoteserviceadmin.EndpointEvent; -import org.osgi.service.remoteserviceadmin.EndpointEventListener; -import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent; - -public class BasicTopologyManagerImpl extends AbstractTopologyManager implements EndpointEventListener { - - private static final boolean allowLoopbackReference = new Boolean( - System.getProperty("org.eclipse.ecf.osgi.services.discovery.allowLoopbackReference", //$NON-NLS-1$ - "false")).booleanValue(); //$NON-NLS-1$ - - private static final String defaultScope = System - .getProperty("org.eclipse.ecf.osgi.services.discovery.endpointListenerScope"); //$NON-NLS-1$ - - private String ecfEndpointListenerScope; - private static final String ONLY_ECF_SCOPE = "(" + RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE + "=*)"; //$NON-NLS-1$ //$NON-NLS-2$ - private static final String NO_ECF_SCOPE = "(!(" //$NON-NLS-1$ - + RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE + "=*))"; //$NON-NLS-1$ - - BasicTopologyManagerImpl(BundleContext context) { - super(context); - if (defaultScope != null) - this.ecfEndpointListenerScope = defaultScope; - else - // If loopback is allowed, then for this endpoint listener we only - // consider those that have a namespace (only ECF endpoint descriptions) - if (allowLoopbackReference) - ecfEndpointListenerScope = ONLY_ECF_SCOPE; - else { - // If loopback not allowed, then we have our scope include - // both !frameworkUUID same, and ONLY_ECF_SCOPE - StringBuffer elScope = new StringBuffer(""); //$NON-NLS-1$ - // filter so that local framework uuid is not the same as local - // value - elScope.append("(&(!(").append(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID) //$NON-NLS-1$ - .append("=").append(getFrameworkUUID()).append("))"); //$NON-NLS-1$ //$NON-NLS-2$ - elScope.append(ONLY_ECF_SCOPE); - elScope.append(")"); //$NON-NLS-1$ - ecfEndpointListenerScope = elScope.toString(); - } - } - - String[] getScope() { - return new String[] { ecfEndpointListenerScope, NO_ECF_SCOPE }; - } - - protected String getFrameworkUUID() { - return super.getFrameworkUUID(); - } - - void exportRegisteredServices(String exportRegisteredSvcsClassname, String exportRegisteredSvcsFilter) { - try { - final ServiceReference[] existingServiceRefs = getContext() - .getAllServiceReferences(exportRegisteredSvcsClassname, exportRegisteredSvcsFilter); - // Now export as if the service was registering right now...i.e. - // perform - // export - if (existingServiceRefs != null && existingServiceRefs.length > 0) { - // After having collected all pre-registered services (with - // marker prop) we are going to asynchronously remote them. - // Registering potentially is a long-running operation (due to - // discovery I/O...) and thus should no be carried out in the - // OSGi FW thread. (https://bugs.eclipse.org/405027) - new Thread(new Runnable() { - public void run() { - for (int i = 0; i < existingServiceRefs.length; i++) { - // This method will check the service properties for - // remote service props. If previously registered as - // a - // remote service, it will export the remote - // service if not it will simply return/skip - handleServiceRegistering(existingServiceRefs[i]); - } - } - }, "BasicTopologyManagerPreRegSrvExporter").start(); //$NON-NLS-1$ - } - } catch (InvalidSyntaxException e) { - logError("exportRegisteredServices", //$NON-NLS-1$ - "Could not retrieve existing service references for exportRegisteredSvcsClassname=" //$NON-NLS-1$ - + exportRegisteredSvcsClassname + " and exportRegisteredSvcsFilter=" //$NON-NLS-1$ - + exportRegisteredSvcsFilter, - e); - } - } - - protected void handleEndpointAdded(org.osgi.service.remoteserviceadmin.EndpointDescription endpoint, - String matchedFilter) { - if (matchedFilter.equals(ecfEndpointListenerScope) && (endpoint instanceof EndpointDescription)) { - handleECFEndpointAdded((EndpointDescription) endpoint); - } - } - - protected void handleEndpointRemoved(org.osgi.service.remoteserviceadmin.EndpointDescription endpoint, - String matchedFilter) { - if (matchedFilter.equals(ecfEndpointListenerScope) && (endpoint instanceof EndpointDescription)) { - handleECFEndpointRemoved((EndpointDescription) endpoint); - } - } - - // EventListenerHook impl - void event(ServiceEvent event, Map listeners) { - handleEvent(event, listeners); - } - - // RemoteServiceAdminListener impl - void handleRemoteAdminEvent(RemoteServiceAdminEvent event) { - if (!(event instanceof RemoteServiceAdmin.RemoteServiceAdminEvent)) - return; - RemoteServiceAdmin.RemoteServiceAdminEvent rsaEvent = (RemoteServiceAdmin.RemoteServiceAdminEvent) event; - - int eventType = event.getType(); - EndpointDescription endpointDescription = rsaEvent.getEndpointDescription(); - - switch (eventType) { - case RemoteServiceAdminEvent.EXPORT_REGISTRATION: - advertiseEndpointDescription(endpointDescription); - break; - case RemoteServiceAdminEvent.EXPORT_UNREGISTRATION: - unadvertiseEndpointDescription(endpointDescription); - break; - case RemoteServiceAdminEvent.EXPORT_ERROR: - logError("handleRemoteAdminEvent.EXPORT_ERROR", "Export error with event=" + rsaEvent); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case RemoteServiceAdminEvent.EXPORT_WARNING: - logWarning("handleRemoteAdminEvent.EXPORT_WARNING", "Export warning with event=" + rsaEvent); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case RemoteServiceAdminEvent.EXPORT_UPDATE: - advertiseModifyEndpointDescription(endpointDescription); - break; - case RemoteServiceAdminEvent.IMPORT_REGISTRATION: - break; - case RemoteServiceAdminEvent.IMPORT_UNREGISTRATION: - break; - case RemoteServiceAdminEvent.IMPORT_ERROR: - logError("handleRemoteAdminEvent.IMPORT_ERROR", "Import error with event=" + rsaEvent); //$NON-NLS-1$//$NON-NLS-2$ - break; - case RemoteServiceAdminEvent.IMPORT_WARNING: - logWarning("handleRemoteAdminEvent.IMPORT_WARNING", "Import warning with event=" + rsaEvent); //$NON-NLS-1$ //$NON-NLS-2$ - break; - default: - logWarning("handleRemoteAdminEvent", //$NON-NLS-1$ - "RemoteServiceAdminEvent=" + rsaEvent + " received with unrecognized type"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /** - * Implementation of org.osgi.service.remoteserviceadmin.EndpointEventListener - * for rfc 203/RSA 1.1 - * - * @see EndpointEventListener#endpointChanged(EndpointEvent, String) - */ - public void endpointChanged(EndpointEvent event, String matchedFilter) { - int eventType = event.getType(); - org.osgi.service.remoteserviceadmin.EndpointDescription ed = event.getEndpoint(); - switch (eventType) { - case EndpointEvent.ADDED: - handleEndpointAdded(ed, matchedFilter); - break; - case EndpointEvent.REMOVED: - handleEndpointRemoved(ed, matchedFilter); - break; - case EndpointEvent.MODIFIED: - handleEndpointModified(ed, matchedFilter); - break; - case EndpointEvent.MODIFIED_ENDMATCH: - handleEndpointModifiedEndmatch(ed, matchedFilter); - break; - } - } - - protected void handleEndpointModifiedEndmatch(org.osgi.service.remoteserviceadmin.EndpointDescription endpoint, - String matchedFilter) { - // By default do nothing for end match. subclasses may decide - // to change this behavior - } - - protected void handleEndpointModified(org.osgi.service.remoteserviceadmin.EndpointDescription endpoint, - String matchedFilter) { - if (matchedFilter.equals(ecfEndpointListenerScope) && (endpoint instanceof EndpointDescription)) { - handleECFEndpointModified((EndpointDescription) endpoint); - } - } -} diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/OSGiTopologyManagerImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/OSGiTopologyManagerImpl.java deleted file mode 100644 index 523f16971..000000000 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/OSGiTopologyManagerImpl.java +++ /dev/null @@ -1,287 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 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.internal.osgi.services.distribution; - -import java.util.HashMap; -import java.util.Map; -import org.eclipse.ecf.osgi.services.remoteserviceadmin.AbstractTopologyManager; -import org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription; -import org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteConstants; -import org.osgi.framework.BundleContext; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.osgi.service.remoteserviceadmin.EndpointEvent; -import org.osgi.service.remoteserviceadmin.EndpointEventListener; -import org.osgi.service.remoteserviceadmin.EndpointListener; - -public class OSGiTopologyManagerImpl extends AbstractTopologyManager implements - EndpointListener, EndpointEventListener { - - private static final boolean exportRegisteredSvcs = new Boolean( - System.getProperty( - "org.eclipse.ecf.osgi.services.osgitopologymanager.exportRegisteredSvcs", "true")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$ - - private static final String exportRegisteredSvcsFilter = System - .getProperty( - "org.eclipse.ecf.osgi.services.osgitopologymanager.exportRegisteredSvcsFilter", "(service.exported.interfaces=*)"); //$NON-NLS-1$ //$NON-NLS-2$ - - private static final String exportRegisteredSvcsClassname = System - .getProperty("org.eclipse.ecf.osgi.services.osgitopologymanager.exportRegisteredSvcsClassname"); //$NON-NLS-1$ - - private String ecfLocalEndpointListenerScope; - private String ecfNonLocalEndpointListenerScope; - private String osgiLocalEndpointListenerScope; - private String osgiNonLocalEndpointListenerScope; - - private static final String ONLY_ECF_SCOPE = "(" + RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE + "=*)"; //$NON-NLS-1$ //$NON-NLS-2$ - private static final String NO_ECF_SCOPE = "(!(" //$NON-NLS-1$ - + RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE + "=*))"; //$NON-NLS-1$ - - OSGiTopologyManagerImpl(BundleContext context) { - super(context); - String frameworkUUID = getFrameworkUUID(); - StringBuffer ecfLocalScope = new StringBuffer(""); //$NON-NLS-1$ - ecfLocalScope - .append("(&(").append(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID).append("=").append(frameworkUUID).append(")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - ecfLocalScope.append(ONLY_ECF_SCOPE); - ecfLocalScope.append(")"); //$NON-NLS-1$ - - ecfLocalEndpointListenerScope = ecfLocalScope.toString(); - StringBuffer ecfNonLocalScope = new StringBuffer(""); //$NON-NLS-1$ - ecfNonLocalScope - .append("(&(!(").append(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID).append("=").append(frameworkUUID).append("))"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - ecfNonLocalScope.append(ONLY_ECF_SCOPE); - ecfNonLocalScope.append(")"); //$NON-NLS-1$ - ecfNonLocalEndpointListenerScope = ecfNonLocalScope.toString(); - - StringBuffer localScope = new StringBuffer(""); //$NON-NLS-1$ - localScope - .append("(&(").append(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID).append("=").append(frameworkUUID).append(")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - localScope.append(NO_ECF_SCOPE); - localScope.append(")"); //$NON-NLS-1$ - osgiLocalEndpointListenerScope = localScope.toString(); - - StringBuffer nonlocalScope = new StringBuffer(""); //$NON-NLS-1$ - nonlocalScope - .append("(&(!(").append(org.osgi.service.remoteserviceadmin.RemoteConstants.ENDPOINT_FRAMEWORK_UUID).append("=").append(frameworkUUID).append("))"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - nonlocalScope.append(NO_ECF_SCOPE); - nonlocalScope.append(")"); //$NON-NLS-1$ - - osgiNonLocalEndpointListenerScope = nonlocalScope.toString(); - } - - String[] getScope() { - return new String[] { ecfLocalEndpointListenerScope, - ecfNonLocalEndpointListenerScope, - osgiLocalEndpointListenerScope, - osgiNonLocalEndpointListenerScope }; - } - - protected String getFrameworkUUID() { - return super.getFrameworkUUID(); - } - - void exportRegisteredServices(String exportRegisteredSvcsClassname, - String exportRegisteredSvcsFilter) { - try { - final ServiceReference[] existingServiceRefs = getContext() - .getAllServiceReferences(exportRegisteredSvcsClassname, - exportRegisteredSvcsFilter); - // Now export as if the service was registering right now...i.e. - // perform - // export - if (existingServiceRefs != null && existingServiceRefs.length > 0) { - // After having collected all pre-registered services (with - // marker prop) we are going to asynchronously remote them. - // Registering potentially is a long-running operation (due to - // discovery I/O...) and thus should no be carried out in the - // OSGi FW thread. (https://bugs.eclipse.org/405027) - new Thread(new Runnable() { - public void run() { - for (int i = 0; i < existingServiceRefs.length; i++) { - // This method will check the service properties for - // remote service props. If previously registered as - // a - // remote service, it will export the remote - // service if not it will simply return/skip - handleServiceRegistering(existingServiceRefs[i]); - } - } - }, "BasicTopologyManagerPreRegSrvExporter").start(); //$NON-NLS-1$ - } - } catch (InvalidSyntaxException e) { - logError( - "exportRegisteredServices", //$NON-NLS-1$ - "Could not retrieve existing service references for exportRegisteredSvcsClassname=" //$NON-NLS-1$ - + exportRegisteredSvcsClassname - + " and exportRegisteredSvcsFilter=" //$NON-NLS-1$ - + exportRegisteredSvcsFilter, e); - } - } - - // EndpointListener impl - /* - * (non-Javadoc) - * - * @see - * org.osgi.service.remoteserviceadmin.EndpointListener#endpointAdded(org - * .osgi.service.remoteserviceadmin.EndpointDescription, java.lang.String) - * - * - * From the R5 spec page 329 section 122.6.2: - * - * Notify the Endpoint Listener of a new Endpoint Description. The second - * parameter is the filter that matched the Endpoint Description. - * Registering the same Endpoint multiple times counts as a single - * registration. - */ - public void endpointAdded( - org.osgi.service.remoteserviceadmin.EndpointDescription endpoint, - String matchedFilter) { - handleEndpointAdded(endpoint, matchedFilter); - } - - protected void handleEndpointAdded( - org.osgi.service.remoteserviceadmin.EndpointDescription endpoint, - String matchedFilter) { - if (matchedFilter.equals(osgiLocalEndpointListenerScope)) { - advertiseEndpointDescription(endpoint); - } else if (matchedFilter.equals(osgiNonLocalEndpointListenerScope)) { - EndpointDescription ed = convertEndpointDescriptionFromOSGiToECF(endpoint); - if (ed != null) { - handleECFEndpointAdded(ed); - } - } else if (matchedFilter.equals(ecfNonLocalEndpointListenerScope)) { - handleECFEndpointAdded((EndpointDescription) endpoint); - } else if (matchedFilter.equals(ecfLocalEndpointListenerScope)) { - advertiseEndpointDescription(endpoint); - } - } - - private EndpointDescription convertEndpointDescriptionFromOSGiToECF( - org.osgi.service.remoteserviceadmin.EndpointDescription ed) { - Map<String, Object> newProps = new HashMap<String, Object>(); - newProps.putAll(ed.getProperties()); - - String ecfNS = (String) newProps - .remove(RemoteConstants.OSGI_CONTAINER_ID_NS); - - if (ecfNS == null) - return null; - - newProps.put(RemoteConstants.ENDPOINT_CONTAINER_ID_NAMESPACE, ecfNS); - - return new EndpointDescription(newProps); - } - - /* - * (non-Javadoc) - * - * @see - * org.osgi.service.remoteserviceadmin.EndpointListener#endpointRemoved( - * org.osgi.service.remoteserviceadmin.EndpointDescription, - * java.lang.String) - */ - public void endpointRemoved( - org.osgi.service.remoteserviceadmin.EndpointDescription endpoint, - String matchedFilter) { - handleEndpointRemoved(endpoint, matchedFilter); - } - - protected void handleEndpointRemoved( - org.osgi.service.remoteserviceadmin.EndpointDescription endpoint, - String matchedFilter) { - if (matchedFilter.equals(osgiLocalEndpointListenerScope)) { - unadvertiseEndpointDescription(endpoint); - } else if (matchedFilter.equals(osgiNonLocalEndpointListenerScope)) { - EndpointDescription ed = convertEndpointDescriptionFromOSGiToECF(endpoint); - if (ed != null) - handleECFEndpointRemoved(ed); - } else if (matchedFilter.equals(ecfNonLocalEndpointListenerScope)) { - handleECFEndpointRemoved((EndpointDescription) endpoint); - } else if (matchedFilter.equals(ecfLocalEndpointListenerScope)) { - unadvertiseEndpointDescription(endpoint); - } - } - - /** - * Implementation of - * org.osgi.service.remoteserviceadmin.EndpointEventListener for rfc 203/RSA - * 1.1 - * - * @see EndpointEventListener#endpointChanged(EndpointEvent, String) - */ - public void endpointChanged(EndpointEvent event, String matchedFilter) { - int eventType = event.getType(); - org.osgi.service.remoteserviceadmin.EndpointDescription ed = event - .getEndpoint(); - switch (eventType) { - case EndpointEvent.ADDED: - handleEndpointAdded(ed, matchedFilter); - break; - case EndpointEvent.REMOVED: - handleEndpointRemoved(ed, matchedFilter); - break; - case EndpointEvent.MODIFIED: - handleEndpointModified(ed, matchedFilter); - break; - case EndpointEvent.MODIFIED_ENDMATCH: - handleEndpointModifiedEndmatch(ed, matchedFilter); - break; - } - } - - protected void handleEndpointModifiedEndmatch( - org.osgi.service.remoteserviceadmin.EndpointDescription endpoint, - String matchedFilter) { - // By default do nothing for end match. subclasses may decide - // to change this behavior - } - - private static Long getOSGiEndpointModifiedValue( - Map<String, Object> properties) { - Object modifiedValue = properties - .get(RemoteConstants.OSGI_ENDPOINT_MODIFIED); - if (modifiedValue != null && modifiedValue instanceof String) - return Long.valueOf((String) modifiedValue); - return null; - } - - protected void handleEndpointModified( - org.osgi.service.remoteserviceadmin.EndpointDescription endpoint, - String matchedFilter) { - if (matchedFilter.equals(osgiLocalEndpointListenerScope)) { - Map<String, Object> edProperties = endpoint.getProperties(); - Long modified = getOSGiEndpointModifiedValue(edProperties); - Map<String, Object> newEdProperties = new HashMap<String, Object>(); - newEdProperties.putAll(endpoint.getProperties()); - if (modified != null) { - newEdProperties.remove(RemoteConstants.OSGI_ENDPOINT_MODIFIED); - handleNonECFEndpointModified( - this, - new org.osgi.service.remoteserviceadmin.EndpointDescription( - newEdProperties)); - } else { - newEdProperties.put(RemoteConstants.OSGI_ENDPOINT_MODIFIED, - String.valueOf(System.currentTimeMillis())); - advertiseModifyEndpointDescription(new org.osgi.service.remoteserviceadmin.EndpointDescription( - newEdProperties)); - } - } else if (matchedFilter.equals(osgiNonLocalEndpointListenerScope)) { - handleNonECFEndpointModified(this, endpoint); - } - } - - public void activate() { - if (exportRegisteredSvcs) - exportRegisteredServices(exportRegisteredSvcsClassname, - exportRegisteredSvcsFilter); - } -} |