diff options
author | slewis | 2009-02-02 07:12:44 +0000 |
---|---|---|
committer | slewis | 2009-02-02 07:12:44 +0000 |
commit | fa8ce6be718882d89a43162e455c121508fa10c7 (patch) | |
tree | 18b489568f9668eb37ba3f37710b2766201acbac /compendium | |
parent | d88548bc4642579bbd1ba79a53dadf64414daa45 (diff) | |
download | org.eclipse.ecf-fa8ce6be718882d89a43162e455c121508fa10c7.tar.gz org.eclipse.ecf-fa8ce6be718882d89a43162e455c121508fa10c7.tar.xz org.eclipse.ecf-fa8ce6be718882d89a43162e455c121508fa10c7.zip |
Simplification of distributin. Added code for ServicePublication in discovery
Diffstat (limited to 'compendium')
8 files changed, 298 insertions, 245 deletions
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/AbstractEventHookImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/AbstractEventHookImpl.java index 9cdae982d..f9ff3c13b 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/AbstractEventHookImpl.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/AbstractEventHookImpl.java @@ -1,29 +1,23 @@ /******************************************************************************* -* Copyright (c) 2009 EclipseSource 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: -* EclipseSource - initial API and implementation -******************************************************************************/ + * Copyright (c) 2009 EclipseSource 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: + * EclipseSource - initial API and implementation + ******************************************************************************/ package org.eclipse.ecf.internal.osgi.services.distribution; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Dictionary; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Properties; -import org.eclipse.ecf.core.IContainer; -import org.eclipse.ecf.core.IContainerManager; -import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.util.Trace; import org.eclipse.ecf.osgi.services.distribution.ServiceConstants; -import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter; import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration; import org.osgi.framework.Constants; import org.osgi.framework.ServiceEvent; @@ -33,11 +27,11 @@ import org.osgi.framework.hooks.service.EventHook; public abstract class AbstractEventHookImpl implements EventHook { private final static String[] EMPTY_STRING_ARRAY = new String[0]; - + private final DistributionProviderImpl distributionProvider; - + private final Map remoteServiceReferences = new HashMap(); - + public AbstractEventHookImpl(DistributionProviderImpl distributionProvider) { this.distributionProvider = distributionProvider; } @@ -45,15 +39,16 @@ public abstract class AbstractEventHookImpl implements EventHook { public void event(ServiceEvent event, Collection contexts) { switch (event.getType()) { case ServiceEvent.MODIFIED: - handleModifiedServiceEvent(event.getServiceReference(),contexts); + handleModifiedServiceEvent(event.getServiceReference(), contexts); break; case ServiceEvent.MODIFIED_ENDMATCH: break; case ServiceEvent.REGISTERED: - handleRegisteredServiceEvent(event.getServiceReference(),contexts); + handleRegisteredServiceEvent(event.getServiceReference(), contexts); break; case ServiceEvent.UNREGISTERING: - handleUnregisteringServiceEvent(event.getServiceReference(),contexts); + handleUnregisteringServiceEvent(event.getServiceReference(), + contexts); break; default: break; @@ -62,70 +57,99 @@ public abstract class AbstractEventHookImpl implements EventHook { protected void handleRegisteredServiceEvent( ServiceReference serviceReference, Collection contexts) { - // This checks to see if the serviceReference has any remote interfaces declared via + // This checks to see if the serviceReference has any remote interfaces + // declared via // osgi.remote.interfaces - Object osgiRemotes = serviceReference.getProperty(ServiceConstants.OSGI_REMOTE_INTERFACES); - // If osgi.remote.interfaces required property is non-null then we handle further, if null then ignore + Object osgiRemotes = serviceReference + .getProperty(ServiceConstants.OSGI_REMOTE_INTERFACES); + // If osgi.remote.interfaces required property is non-null then we + // handle further, if null then ignore if (osgiRemotes != null) { - // The osgiRemotes should be of type String [] according to RFC119...if it's not String [] we ignore - String [] remoteInterfacesArr = (String []) ((osgiRemotes instanceof String[])?osgiRemotes:null); + // The osgiRemotes should be of type String [] according to + // RFC119...if it's not String [] we ignore + String[] remoteInterfacesArr = (String[]) ((osgiRemotes instanceof String[]) ? osgiRemotes + : null); if (remoteInterfacesArr == null) { - trace("handleRegisteredServiceEvent","remoteInterfaces not of String [] type as required by RFC 119"); + trace("handleRegisteredServiceEvent", + "remoteInterfaces not of String [] type as required by RFC 119"); return; } - trace("handleRegisteredServiceEvent","serviceReference="+serviceReference+" has remoteInterfaces="+Arrays.asList(remoteInterfacesArr)); - // We compare the osgi.remote.interfaces with those exposed by the service reference and + trace("handleRegisteredServiceEvent", "serviceReference=" + + serviceReference + " has remoteInterfaces=" + + Arrays.asList(remoteInterfacesArr)); + // We compare the osgi.remote.interfaces with those exposed by the + // service reference and // make sure that expose some common interfaces - String [] remoteInterfaces = (remoteInterfacesArr != null)?getInterfacesForServiceReference(remoteInterfacesArr, serviceReference):null; + String[] remoteInterfaces = (remoteInterfacesArr != null) ? getInterfacesForServiceReference( + remoteInterfacesArr, serviceReference) + : null; if (remoteInterfaces == null) { - trace("handleRegisteredServiceEvent","No exposed remoteInterfaces found for serviceReference="+serviceReference); + trace("handleRegisteredServiceEvent", + "No exposed remoteInterfaces found for serviceReference=" + + serviceReference); return; } // Now get optional service property osgi.remote.configuration.type - Object osgiRemoteConfigurationType = serviceReference.getProperty(ServiceConstants.OSGI_REMOTE_CONFIGURATION_TYPE); - // The osgiRemoteConfigurationType is optional and can be null. If non-null, it should be of type String [] according to RFC119...if it's non-null and not String [] we ignore + Object osgiRemoteConfigurationType = serviceReference + .getProperty(ServiceConstants.OSGI_REMOTE_CONFIGURATION_TYPE); + // The osgiRemoteConfigurationType is optional and can be null. If + // non-null, it should be of type String [] according to RFC119...if + // it's non-null and not String [] we ignore String[] remoteConfigurationType = null; if (osgiRemoteConfigurationType != null) { if (!(osgiRemoteConfigurationType instanceof String[])) { - trace("handleRegisteredServiceEvent","osgi.remote.configuration.type is not String[] as required by RFC 119"); + trace("handleRegisteredServiceEvent", + "osgi.remote.configuration.type is not String[] as required by RFC 119"); return; } - remoteConfigurationType = (String []) osgiRemoteConfigurationType; + remoteConfigurationType = (String[]) osgiRemoteConfigurationType; } // Now call registerRemoteService - registerRemoteService(serviceReference,remoteInterfaces,remoteConfigurationType); + registerRemoteService(serviceReference, remoteInterfaces, + remoteConfigurationType); } } - - protected abstract void registerRemoteService(ServiceReference serviceReference, String[] remoteInterfaces, String [] remoteConfigurationType); - - protected void fireRemoteServiceRegistered(ServiceReference serviceReference, IRemoteServiceRegistration remoteServiceRegistration) { - remoteServiceReferences.put(serviceReference, remoteServiceRegistration); + + protected abstract void registerRemoteService( + ServiceReference serviceReference, String[] remoteInterfaces, + String[] remoteConfigurationType); + + protected void fireRemoteServiceRegistered( + ServiceReference serviceReference, + IRemoteServiceRegistration remoteServiceRegistration) { + remoteServiceReferences + .put(serviceReference, remoteServiceRegistration); distributionProvider.addExposedService(serviceReference); } private String[] getInterfacesForServiceReference( String[] remoteInterfaces, ServiceReference serviceReference) { - if (remoteInterfaces == null || remoteInterfaces.length == 0) return EMPTY_STRING_ARRAY; + if (remoteInterfaces == null || remoteInterfaces.length == 0) + return EMPTY_STRING_ARRAY; List results = new ArrayList(); - List interfaces = Arrays.asList((String []) serviceReference.getProperty(Constants.OBJECTCLASS)); - for(int i=0; i < remoteInterfaces.length; i++) { + List interfaces = Arrays.asList((String[]) serviceReference + .getProperty(Constants.OBJECTCLASS)); + for (int i = 0; i < remoteInterfaces.length; i++) { String intf = remoteInterfaces[i]; - if (ServiceConstants.OSGI_REMOTE_INTERFACES_WILDCARD.equals(intf)) return (String []) interfaces.toArray(new String[] {}); - if (intf != null && interfaces.contains(intf)) results.add(intf); + if (ServiceConstants.OSGI_REMOTE_INTERFACES_WILDCARD.equals(intf)) + return (String[]) interfaces.toArray(new String[] {}); + if (intf != null && interfaces.contains(intf)) + results.add(intf); } - return (String []) results.toArray(new String [] {}); + return (String[]) results.toArray(new String[] {}); } protected void trace(String methodName, String message) { - Trace.trace(Activator.PLUGIN_ID, DebugOptions.EVENTHOOKDEBUG, this.getClass(), methodName, message); + Trace.trace(Activator.PLUGIN_ID, DebugOptions.EVENTHOOKDEBUG, this + .getClass(), methodName, message); } - + protected void handleUnregisteringServiceEvent( ServiceReference serviceReference, Collection contexts) { IRemoteServiceRegistration remoteRegistration = removeRemoteRegistration(serviceReference); if (remoteRegistration != null) { - trace("handleUnregisteringServiceEvent","found serviceRegistration="+remoteRegistration); + trace("handleUnregisteringServiceEvent", + "found serviceRegistration=" + remoteRegistration); distributionProvider.removeRemoteService(serviceReference); remoteRegistration.unregister(); } @@ -133,16 +157,17 @@ public abstract class AbstractEventHookImpl implements EventHook { private IRemoteServiceRegistration removeRemoteRegistration( ServiceReference serviceReference) { - return (IRemoteServiceRegistration) remoteServiceReferences.remove(serviceReference); + return (IRemoteServiceRegistration) remoteServiceReferences + .remove(serviceReference); } - protected void handleModifiedServiceEvent(ServiceReference serviceReference, Collection contexts) { + protected void handleModifiedServiceEvent( + ServiceReference serviceReference, Collection contexts) { // TODO } - protected Object getService(ServiceReference sr) { return Activator.getDefault().getContext().getService(sr); } - + } diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/AbstractFindHookImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/AbstractFindHookImpl.java deleted file mode 100644 index 17060fb37..000000000 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/AbstractFindHookImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 EclipseSource 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: -* EclipseSource - initial API and implementation -******************************************************************************/ -package org.eclipse.ecf.internal.osgi.services.distribution; - -import java.util.Collection; - -import org.eclipse.ecf.core.util.Trace; -import org.osgi.framework.BundleContext; -import org.osgi.framework.hooks.service.FindHook; - -public abstract class AbstractFindHookImpl implements FindHook { - - private final DistributionProviderImpl distributionProvider; - - public AbstractFindHookImpl(DistributionProviderImpl distributionProvider) { - this.distributionProvider = distributionProvider; - } - - public void find(BundleContext context, String name, String filter, - boolean allServices, Collection references) { - handleFind(context,name,filter,allServices,references); - } - - private void handleFind(BundleContext context, String name, String filter, - boolean allServices, Collection references) { - trace("handleFind","params="+new Object[] { context, name, filter, new Boolean(allServices), references }); - // TODO Auto-generated method stub - } - - private void trace(String methodName, String message) { - Trace.trace(Activator.PLUGIN_ID, DebugOptions.FINDHOOKDEBUG, this.getClass(), methodName, message); - } - - -} diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java index 0c137f28c..1619fa04e 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java @@ -1,12 +1,12 @@ /******************************************************************************* -* Copyright (c) 2009 EclipseSource 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: -* EclipseSource - initial API and implementation -******************************************************************************/ + * Copyright (c) 2009 EclipseSource 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: + * EclipseSource - initial API and implementation + ******************************************************************************/ package org.eclipse.ecf.internal.osgi.services.distribution; import org.eclipse.ecf.core.IContainerManager; @@ -14,36 +14,37 @@ import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; import org.osgi.framework.hooks.service.EventHook; -import org.osgi.framework.hooks.service.FindHook; import org.osgi.service.distribution.DistributionProvider; import org.osgi.util.tracker.ServiceTracker; public class Activator implements BundleActivator { public static final String PLUGIN_ID = "org.eclipse.ecf.osgi.services.distribution"; - + private static Activator plugin; private BundleContext context; - - private ServiceRegistration findHookRegistration; + private ServiceRegistration eventHookRegistration; private ServiceRegistration distributionProviderRegistration; - + private DistributionProviderImpl distributionProvider; - + private ServiceTracker containerManagerTracker; - + public static Activator getDefault() { return plugin; } - + public 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 ctxt) throws Exception { plugin = this; @@ -54,34 +55,36 @@ public class Activator implements BundleActivator { } private void addServiceRegistryHooks() { - this.findHookRegistration = this.context.registerService(FindHook.class.getName(), new ECFFindHookImpl(distributionProvider), null); - this.eventHookRegistration = this.context.registerService(EventHook.class.getName(), new ECFEventHookImpl(distributionProvider), null); + this.eventHookRegistration = this.context.registerService( + EventHook.class.getName(), new ECFEventHookImpl( + distributionProvider), null); } private void addDistributionProvider() { - this.distributionProviderRegistration = this.context.registerService(DistributionProvider.class.getName(),distributionProvider,null); + this.distributionProviderRegistration = this.context.registerService( + DistributionProvider.class.getName(), distributionProvider, + null); } - + private void removeServiceRegistryHooks() { - if (this.findHookRegistration != null) { - this.findHookRegistration.unregister(); - this.findHookRegistration = null; - } if (this.eventHookRegistration != null) { this.eventHookRegistration.unregister(); this.eventHookRegistration = null; } } - + private void removeDistributionProvider() { if (this.distributionProviderRegistration != null) { this.distributionProviderRegistration.unregister(); this.distributionProviderRegistration = null; } } + /* * (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 ctxt) throws Exception { removeDistributionProvider(); @@ -97,7 +100,8 @@ public class Activator implements BundleActivator { public IContainerManager getContainerManager() { if (containerManagerTracker == null) { - containerManagerTracker = new ServiceTracker(this.context,IContainerManager.class.getName(),null); + containerManagerTracker = new ServiceTracker(this.context, + IContainerManager.class.getName(), null); containerManagerTracker.open(); } return (IContainerManager) containerManagerTracker.getService(); diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DebugOptions.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DebugOptions.java index 9953fc610..25ad8f676 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DebugOptions.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DebugOptions.java @@ -1,28 +1,30 @@ /******************************************************************************* -* Copyright (c) 2009 EclipseSource 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: -* EclipseSource - initial API and implementation -******************************************************************************/ + * Copyright (c) 2009 EclipseSource 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: + * EclipseSource - initial API and implementation + ******************************************************************************/ package org.eclipse.ecf.internal.osgi.services.distribution; public interface DebugOptions { public static final String DEBUG = Activator.PLUGIN_ID + "/debug"; //$NON-NLS-1$ - public static final String EXCEPTIONS_CATCHING = DEBUG + "/exceptions/catching"; //$NON-NLS-1$ + public static final String EXCEPTIONS_CATCHING = DEBUG + + "/exceptions/catching"; //$NON-NLS-1$ - public static final String EXCEPTIONS_THROWING = DEBUG + "/exceptions/throwing"; //$NON-NLS-1$ + public static final String EXCEPTIONS_THROWING = DEBUG + + "/exceptions/throwing"; //$NON-NLS-1$ public static final String METHODS_ENTERING = DEBUG + "/methods/entering"; //$NON-NLS-1$ public static final String METHODS_EXITING = DEBUG + "/methods/exiting"; //$NON-NLS-1$ public static final String EVENTHOOKDEBUG = DEBUG + "/eventhook"; - + public static final String FINDHOOKDEBUG = DEBUG + "/findhook"; } diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DistributionProviderImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DistributionProviderImpl.java index 8ffbb7819..3f2a35747 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DistributionProviderImpl.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DistributionProviderImpl.java @@ -1,12 +1,12 @@ /******************************************************************************* -* Copyright (c) 2009 EclipseSource 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: -* EclipseSource - initial API and implementation -******************************************************************************/ + * Copyright (c) 2009 EclipseSource 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: + * EclipseSource - initial API and implementation + ******************************************************************************/ package org.eclipse.ecf.internal.osgi.services.distribution; import java.util.Collections; @@ -22,46 +22,52 @@ public class DistributionProviderImpl implements DistributionProvider { Map exposedServices = Collections.synchronizedMap(new HashMap()); Map publishedServices = Collections.synchronizedMap(new HashMap()); Map remoteServices = Collections.synchronizedMap(new HashMap()); - + Long getServiceId(ServiceReference sr) { return (Long) sr.getProperty(Constants.SERVICE_ID); } - + ServiceReference addExposedService(ServiceReference sr) { - if (sr == null) return null; - return (ServiceReference) exposedServices.put(getServiceId(sr),sr); + if (sr == null) + return null; + return (ServiceReference) exposedServices.put(getServiceId(sr), sr); } - + ServiceReference addPublishedService(ServiceReference sr) { - if (sr == null) return null; - return (ServiceReference) publishedServices.put(getServiceId(sr),sr); + if (sr == null) + return null; + return (ServiceReference) publishedServices.put(getServiceId(sr), sr); } - + ServiceReference addRemoteService(ServiceReference sr) { - if (sr == null) return null; - return (ServiceReference) remoteServices.put(getServiceId(sr),sr); + if (sr == null) + return null; + return (ServiceReference) remoteServices.put(getServiceId(sr), sr); } - + ServiceReference removeExposedService(Long sid) { - if (sid == null) return null; + if (sid == null) + return null; return (ServiceReference) exposedServices.remove(sid); } - + ServiceReference removeExposedService(ServiceReference sr) { return removeExposedService(getServiceId(sr)); } - + ServiceReference removePublishedService(Long sid) { - if (sid == null) return null; + if (sid == null) + return null; return (ServiceReference) publishedServices.remove(sid); } - + ServiceReference removePublishedService(ServiceReference sr) { return removePublishedService(getServiceId(sr)); } ServiceReference removeRemoteService(Long sid) { - if (sid == null) return null; + if (sid == null) + return null; return (ServiceReference) remoteServices.remove(sid); } @@ -69,67 +75,78 @@ public class DistributionProviderImpl implements DistributionProvider { return removeRemoteService(getServiceId(sr)); } - boolean containsExposedService(Long sid) { - if (sid == null) return false; + if (sid == null) + return false; return exposedServices.containsKey(sid); } - + boolean containsPublishedService(Long sid) { - if (sid == null) return false; + if (sid == null) + return false; return publishedServices.containsKey(sid); } - + boolean containsRemoteService(Long sid) { - if (sid == null) return false; + if (sid == null) + return false; return remoteServices.containsKey(sid); } ServiceReference getExposedService(Long sid) { - if (sid == null) return null; + if (sid == null) + return null; return (ServiceReference) exposedServices.get(sid); } - + ServiceReference getPublishedService(Long sid) { - if (sid == null) return null; + if (sid == null) + return null; return (ServiceReference) publishedServices.get(sid); } ServiceReference getRemoteService(Long sid) { - if (sid == null) return null; + if (sid == null) + return null; return (ServiceReference) remoteServices.get(sid); } public ServiceReference[] getExposedServices() { - return (ServiceReference[]) exposedServices.entrySet().toArray(new ServiceReference[] {}); + return (ServiceReference[]) exposedServices.entrySet().toArray( + new ServiceReference[] {}); } public Map getPublicationProperties(ServiceReference sr) { - // the spec or javadocs don't say what should happen if given sr is null or + // the spec or javadocs don't say what should happen if given sr is null + // or // the given sr is not found in those published... Map result = new HashMap(); - if (sr == null) return result; + if (sr == null) + return result; ServiceReference publishedService = getPublishedService(getServiceId(sr)); - if (publishedService == null) return result; - return getPropertyMap(result,publishedService); + if (publishedService == null) + return result; + return getPropertyMap(result, publishedService); } private Map getPropertyMap(Map result, ServiceReference sr) { - String [] propKeys = sr.getPropertyKeys(); + String[] propKeys = sr.getPropertyKeys(); if (propKeys != null) { - for(int i=0; i < propKeys.length; i++) { + for (int i = 0; i < propKeys.length; i++) { result.put(propKeys[i], sr.getProperty(propKeys[i])); } } return result; } - + public ServiceReference[] getPublishedServices() { - return (ServiceReference[]) publishedServices.entrySet().toArray(new ServiceReference[] {}); + return (ServiceReference[]) publishedServices.entrySet().toArray( + new ServiceReference[] {}); } public ServiceReference[] getRemoteServices() { - return (ServiceReference[]) remoteServices.entrySet().toArray(new ServiceReference[] {}); + return (ServiceReference[]) remoteServices.entrySet().toArray( + new ServiceReference[] {}); } } diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ECFEventHookImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ECFEventHookImpl.java index 2af80f3d2..e6125c66f 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ECFEventHookImpl.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ECFEventHookImpl.java @@ -1,12 +1,12 @@ /******************************************************************************* -* Copyright (c) 2009 EclipseSource 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: -* EclipseSource - initial API and implementation -******************************************************************************/ + * Copyright (c) 2009 EclipseSource 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: + * EclipseSource - initial API and implementation + ******************************************************************************/ package org.eclipse.ecf.internal.osgi.services.distribution; import java.util.ArrayList; @@ -32,26 +32,39 @@ public class ECFEventHookImpl extends AbstractEventHookImpl { } protected void registerRemoteService(ServiceReference serviceReference, - String[] remoteInterfaces, String [] remoteConfigurationType) { - if (remoteConfigurationType == null || remoteConfigurationType.length == 0) { - trace("registerRemoteService","remoteConfigurationType is null or empty so does not match ECF remote configuration type"); + String[] remoteInterfaces, String[] remoteConfigurationType) { + if (remoteConfigurationType == null + || remoteConfigurationType.length == 0) { + trace( + "registerRemoteService", + "remoteConfigurationType is null or empty so does not match ECF remote configuration type"); return; } - // If the first remote configuration type value is not for us, then we don't do anything with it - if (!remoteConfigurationType[0].equals(ServiceConstants.ECF_REMOTE_CONFIGURATION_TYPE)) { - trace("registerRemoteService","remoteConfigurationType not ECF type"); + // If the first remote configuration type value is not for us, then we + // don't do anything with it + if (!remoteConfigurationType[0] + .equals(ServiceConstants.ECF_REMOTE_CONFIGURATION_TYPE)) { + trace("registerRemoteService", + "remoteConfigurationType not ECF type"); return; } Map ecfConfiguration = parseECFConfigurationType(remoteConfigurationType); - // We get the list of ECF distribution providers (IRemoteServiceContainerAdapters) - IRemoteServiceContainerAdapter [] rscas = findRemoteServiceContainerAdapters(serviceReference,ecfConfiguration); - // If there are relevant ones then actually register a remote service with them. + // We get the list of ECF distribution providers + // (IRemoteServiceContainerAdapters) + IRemoteServiceContainerAdapter[] rscas = findRemoteServiceContainerAdapters( + serviceReference, ecfConfiguration); + // If there are relevant ones then actually register a remote service + // with them. if (rscas == null) { - trace("registerRemoteService","No remote service container adapters found for serviceReference="+serviceReference+" and configuration="+ecfConfiguration); + trace("registerRemoteService", + "No remote service container adapters found for serviceReference=" + + serviceReference + " and configuration=" + + ecfConfiguration); return; } - // Now actually register remote service with remote service container adapters - registerRemoteService(rscas,remoteInterfaces,serviceReference); + // Now actually register remote service with remote service container + // adapters + registerRemoteService(rscas, remoteInterfaces, serviceReference); } private Map parseECFConfigurationType(String[] remoteConfigurationType) { @@ -60,59 +73,104 @@ public class ECFEventHookImpl extends AbstractEventHookImpl { return results; } - protected void registerRemoteService(IRemoteServiceContainerAdapter[] rscas, String[] remoteInterfaces, ServiceReference sr) { - for(int i=0; i < rscas.length; i++) { - IRemoteServiceRegistration remoteRegistration = rscas[i].registerRemoteService(remoteInterfaces, getService(sr), createPropertiesForRemoteService(rscas[i],remoteInterfaces,sr)); - trace("registerRemoteService","REGISTERED REMOTE SERVICE serviceReference="+sr+" remoteRegistration="+remoteRegistration); - fireRemoteServiceRegistered(sr,remoteRegistration); + protected void registerRemoteService( + IRemoteServiceContainerAdapter[] rscas, String[] remoteInterfaces, + ServiceReference sr) { + for (int i = 0; i < rscas.length; i++) { + IRemoteServiceRegistration remoteRegistration = rscas[i] + .registerRemoteService(remoteInterfaces, getService(sr), + createPropertiesForRemoteService(rscas[i], + remoteInterfaces, sr)); + trace("registerRemoteService", + "REGISTERED REMOTE SERVICE serviceReference=" + sr + + " remoteRegistration=" + remoteRegistration); + fireRemoteServiceRegistered(sr, remoteRegistration); } } - + protected Dictionary createPropertiesForRemoteService( IRemoteServiceContainerAdapter iRemoteServiceContainerAdapter, String[] remotes, ServiceReference sr) { - String [] propKeys = sr.getPropertyKeys(); + String[] propKeys = sr.getPropertyKeys(); Properties newProps = new Properties(); - for(int i=0; i < propKeys.length; i++) { + for (int i = 0; i < propKeys.length; i++) { newProps.put(propKeys[i], sr.getProperty(propKeys[i])); } return newProps; } - protected IRemoteServiceContainerAdapter[] findRemoteServiceContainerAdapters(ServiceReference serviceReference, Map ecfConfiguration) { - IContainerManager containerManager = Activator.getDefault().getContainerManager(); - return (containerManager != null)?getRSCAsFromContainers(containerManager.getAllContainers(),serviceReference,ecfConfiguration):null; + protected IRemoteServiceContainerAdapter[] findRemoteServiceContainerAdapters( + ServiceReference serviceReference, Map ecfConfiguration) { + IContainerManager containerManager = Activator.getDefault() + .getContainerManager(); + return (containerManager != null) ? getRSCAsFromContainers( + containerManager.getAllContainers(), serviceReference, + ecfConfiguration) : null; } private IRemoteServiceContainerAdapter[] getRSCAsFromContainers( - IContainer[] containers, ServiceReference serviceReference, Map ecfConfiguration) { - if (containers == null) return null; + IContainer[] containers, ServiceReference serviceReference, + Map ecfConfiguration) { + if (containers == null) + return null; List rscas = new ArrayList(); - for(int i=0; i < containers.length; i++) { - IRemoteServiceContainerAdapter rsca = (IRemoteServiceContainerAdapter) containers[i].getAdapter(IRemoteServiceContainerAdapter.class); + for (int i = 0; i < containers.length; i++) { + IRemoteServiceContainerAdapter rsca = (IRemoteServiceContainerAdapter) containers[i] + .getAdapter(IRemoteServiceContainerAdapter.class); if (rsca == null) { - Trace.trace(Activator.PLUGIN_ID, DebugOptions.DEBUG, this.getClass(), "getRCSAsFromContainers", "Container="+containers[i]+" not an IRemoteServiceContainerAdapter. Excluding rsca="+rsca+" from remote registration"); + Trace + .trace( + Activator.PLUGIN_ID, + DebugOptions.DEBUG, + this.getClass(), + "getRCSAsFromContainers", + "Container=" + + containers[i] + + " not an IRemoteServiceContainerAdapter. Excluding rsca=" + + rsca + " from remote registration"); continue; - } else if (includeContainer(containers[i],rsca,serviceReference,ecfConfiguration)) rscas.add(rsca); + } else if (includeContainer(containers[i], rsca, serviceReference, + ecfConfiguration)) + rscas.add(rsca); } - return (IRemoteServiceContainerAdapter[]) rscas.toArray(new IRemoteServiceContainerAdapter[] {}); + return (IRemoteServiceContainerAdapter[]) rscas + .toArray(new IRemoteServiceContainerAdapter[] {}); } - - protected boolean includeContainer(IContainer container, IRemoteServiceContainerAdapter rsca, ServiceReference serviceReference, Map ecfConfiguration) { - Object cID = serviceReference.getProperty(org.eclipse.ecf.remoteservice.Constants.REMOTE_SERVICE_CONTAINER_ID); + + protected boolean includeContainer(IContainer container, + IRemoteServiceContainerAdapter rsca, + ServiceReference serviceReference, Map ecfConfiguration) { + Object cID = serviceReference + .getProperty(org.eclipse.ecf.remoteservice.Constants.REMOTE_SERVICE_CONTAINER_ID); if (cID == null || !(cID instanceof ID)) { - Trace.trace(Activator.PLUGIN_ID, DebugOptions.DEBUG, this.getClass(), "includeContainer", "serviceReference="+serviceReference+" does not set remote service container id service property. INCLUDING containerID="+container.getID()+" in remote registration"); + Trace + .trace( + Activator.PLUGIN_ID, + DebugOptions.DEBUG, + this.getClass(), + "includeContainer", + "serviceReference=" + + serviceReference + + " does not set remote service container id service property. INCLUDING containerID=" + + container.getID() + + " in remote registration"); return true; } ID containerID = (ID) cID; if (container.getID().equals(containerID)) { - Trace.trace(Activator.PLUGIN_ID, DebugOptions.DEBUG, this.getClass(), "includeContainer", "serviceReference="+serviceReference+" has MATCHING container id="+containerID+". INCLUDING rsca="+rsca+" in remote registration"); + Trace.trace(Activator.PLUGIN_ID, DebugOptions.DEBUG, this + .getClass(), "includeContainer", "serviceReference=" + + serviceReference + " has MATCHING container id=" + + containerID + ". INCLUDING rsca=" + rsca + + " in remote registration"); return true; } - Trace.trace(Activator.PLUGIN_ID, DebugOptions.DEBUG, this.getClass(), "includeContainer", "serviceReference="+serviceReference+" has non-matching container id="+containerID+". EXCLUDING rsca="+rsca+" in remote registration"); + Trace.trace(Activator.PLUGIN_ID, DebugOptions.DEBUG, this.getClass(), + "includeContainer", "serviceReference=" + serviceReference + + " has non-matching container id=" + containerID + + ". EXCLUDING rsca=" + rsca + + " in remote registration"); return false; } - - } diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ECFFindHookImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ECFFindHookImpl.java deleted file mode 100644 index 8f13c54b3..000000000 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ECFFindHookImpl.java +++ /dev/null @@ -1,18 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 EclipseSource 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: -* EclipseSource - initial API and implementation -******************************************************************************/ -package org.eclipse.ecf.internal.osgi.services.distribution; - -public class ECFFindHookImpl extends AbstractFindHookImpl { - - public ECFFindHookImpl(DistributionProviderImpl distributionProvider) { - super(distributionProvider); - } - -} diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/ServiceConstants.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/ServiceConstants.java index b1c27b410..f656fa595 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/ServiceConstants.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/osgi/services/distribution/ServiceConstants.java @@ -11,12 +11,19 @@ package org.eclipse.ecf.osgi.services.distribution; public interface ServiceConstants { + public static final String OSGI_INTENTS = "osgi.intents"; + public static final String OSGI_REMOTE_INTERFACES = "osgi.remote.interfaces"; + public static final String OSGI_REMOTE_REQUIRES_INTENTS = "osgi.remote.requires.intents"; + + public static final String OSGI_REMOTE_CONFIGURATION_TYPE = "osgi.remote.configuration.type"; + + public static final String OSGI_REMOTE = "osgi.remote"; + public static final String OSGI_REMOTE_INTERFACES_WILDCARD = "*"; // ecf,org.eclipse.ecf.containerID=<id> - public static final String OSGI_REMOTE_CONFIGURATION_TYPE = "osgi.remote.configuration.type"; public static final String ECF_REMOTE_CONFIGURATION_TYPE = "ecf"; |