diff options
author | slewis | 2009-01-29 04:24:32 +0000 |
---|---|---|
committer | slewis | 2009-01-29 04:24:32 +0000 |
commit | cd8c8bb5fa26cd2cb8658953d5a2be09f9c27ded (patch) | |
tree | 770030ad16344ab7454fa73f1a4bb91330ac7edd /compendium | |
parent | f1cb691426310c7c0e54682a50f08d3783fa4bff (diff) | |
download | org.eclipse.ecf-cd8c8bb5fa26cd2cb8658953d5a2be09f9c27ded.tar.gz org.eclipse.ecf-cd8c8bb5fa26cd2cb8658953d5a2be09f9c27ded.tar.xz org.eclipse.ecf-cd8c8bb5fa26cd2cb8658953d5a2be09f9c27ded.zip |
Additions for rfc 119 support
Diffstat (limited to 'compendium')
6 files changed, 235 insertions, 9 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 885b6370b..0573dd408 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 @@ -8,6 +8,7 @@ Bundle-Vendor: %pluginProvider Bundle-RequiredExecutionEnvironment: J2SE-1.4 Import-Package: org.eclipse.ecf.core.util, org.osgi.framework;version="1.3.0", - org.osgi.framework.hooks.service + org.osgi.framework.hooks.service, + org.osgi.service.distribution;version="1.0.0" Bundle-ActivationPolicy: lazy Bundle-Localization: plugin 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 c8055439f..13c8988a7 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 @@ -14,6 +14,7 @@ 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; public class Activator implements BundleActivator { @@ -24,6 +25,9 @@ public class Activator implements BundleActivator { private ServiceRegistration findHookRegistration; private ServiceRegistration eventHookRegistration; + private ServiceRegistration distributionProviderRegistration; + + private ECFRSDistributionProvider distributionProvider; public static Activator getDefault() { return plugin; @@ -40,14 +44,20 @@ public class Activator implements BundleActivator { public void start(BundleContext ctxt) throws Exception { plugin = this; this.context = ctxt; + this.distributionProvider = new ECFRSDistributionProvider(); addServiceRegistryHooks(); + addDistributionProvider(); } private void addServiceRegistryHooks() { - this.findHookRegistration = this.context.registerService(FindHook.class.getName(), new FindHookImpl(), null); - this.eventHookRegistration = this.context.registerService(EventHook.class.getName(), new EventHookImpl(), null); + this.findHookRegistration = this.context.registerService(FindHook.class.getName(), new FindHookImpl(distributionProvider), null); + this.eventHookRegistration = this.context.registerService(EventHook.class.getName(), new EventHookImpl(distributionProvider), null); } + private void addDistributionProvider() { + this.distributionProviderRegistration = this.context.registerService(DistributionProvider.class.getName(),distributionProvider,null); + } + private void removeServiceRegistryHooks() { if (this.findHookRegistration != null) { this.findHookRegistration.unregister(); @@ -59,12 +69,20 @@ public class Activator implements BundleActivator { } } + 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) */ public void stop(BundleContext ctxt) throws Exception { + removeDistributionProvider(); removeServiceRegistryHooks(); + this.distributionProvider = 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/ECFRSDistributionProvider.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ECFRSDistributionProvider.java new file mode 100644 index 000000000..371070003 --- /dev/null +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ECFRSDistributionProvider.java @@ -0,0 +1,122 @@ +/******************************************************************************* +* 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; +import java.util.HashMap; +import java.util.Map; + +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceReference; +import org.osgi.service.distribution.DistributionProvider; + +public class ECFRSDistributionProvider 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); + } + + ServiceReference addPublishedService(ServiceReference 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); + } + + ServiceReference removeExposedService(Long sid) { + if (sid == null) return null; + return (ServiceReference) exposedServices.remove(sid); + } + + ServiceReference removePublishedService(Long sid) { + if (sid == null) return null; + return (ServiceReference) publishedServices.remove(sid); + } + + ServiceReference removeRemoteService(Long sid) { + if (sid == null) return null; + return (ServiceReference) remoteServices.remove(sid); + } + + boolean containsExposedService(Long sid) { + if (sid == null) return false; + return exposedServices.containsKey(sid); + } + + boolean containsPublishedService(Long sid) { + if (sid == null) return false; + return publishedServices.containsKey(sid); + } + + boolean containsRemoteService(Long sid) { + if (sid == null) return false; + return remoteServices.containsKey(sid); + } + + ServiceReference getExposedService(Long sid) { + if (sid == null) return null; + return (ServiceReference) exposedServices.get(sid); + } + + ServiceReference getPublishedService(Long sid) { + if (sid == null) return null; + return (ServiceReference) publishedServices.get(sid); + } + + ServiceReference getRemoteService(Long sid) { + if (sid == null) return null; + return (ServiceReference) remoteServices.get(sid); + } + + public ServiceReference[] getExposedServices() { + 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 given sr is not found in those published... + Map result = new HashMap(); + if (sr == null) return result; + ServiceReference publishedService = getPublishedService(getServiceId(sr)); + if (publishedService == null) return result; + return getPropertyMap(result,publishedService); + } + + private Map getPropertyMap(Map result, ServiceReference sr) { + String [] propKeys = sr.getPropertyKeys(); + if (propKeys != null) { + 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[] {}); + } + + public ServiceReference[] getRemoteServices() { + 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/EventHookImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/EventHookImpl.java index 4b4633135..b83f6b19b 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/EventHookImpl.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/EventHookImpl.java @@ -13,19 +13,82 @@ import java.util.Collection; import org.eclipse.ecf.core.util.Trace; import org.osgi.framework.ServiceEvent; +import org.osgi.framework.ServiceReference; import org.osgi.framework.hooks.service.EventHook; public class EventHookImpl implements EventHook { + private final ECFRSDistributionProvider distributionProvider; + + public EventHookImpl(ECFRSDistributionProvider distributionProvider) { + this.distributionProvider = distributionProvider; + } + public void event(ServiceEvent event, Collection contexts) { - Trace.entering(Activator.PLUGIN_ID,DebugOptions.METHODS_ENTERING,this.getClass(),"event"); - handleEvent(event,contexts); - Trace.exiting(Activator.PLUGIN_ID, DebugOptions.METHODS_EXITING, this.getClass(), "event"); + traceEntering("event"); + switch (event.getType()) { + case ServiceEvent.MODIFIED: + handleModifiedServiceEvent(event.getServiceReference(),event.getSource(),contexts); + break; + case ServiceEvent.MODIFIED_ENDMATCH: + break; + case ServiceEvent.REGISTERED: + handleRegisteredServiceEvent(event.getServiceReference(),event.getSource(),contexts); + break; + case ServiceEvent.UNREGISTERING: + handleUnregisteringServiceEvent(event.getServiceReference(),event.getSource(),contexts); + break; + default: + break; + } + traceExiting("event"); + } + + private void handleUnregisteringServiceEvent( + ServiceReference serviceReference, Object source, + Collection contexts) { + traceEntering("handleUnregisteringServiceEvent"); + // TODO + traceExiting("handleUnregisteringServiceEvent"); } - private void handleEvent(ServiceEvent event, Collection contexts) { - // TODO Auto-generated method stub - + Object getRemoteInterfaces(ServiceReference sr) { + return sr.getProperty(ServiceInterfaceConstants.OSGI_REMOTE_INTERFACES_KEY); + } + + private void handleRegisteredServiceEvent( + ServiceReference serviceReference, Object source, + Collection contexts) { + traceEntering("handleRegisteredServiceEvent"); + Object remoteInterfaces = getRemoteInterfaces(serviceReference); + if (remoteInterfaces != null) { + trace("handleRegisteredServiceEvent","serviceReference="+serviceReference+" has remoteInterfaces="+remoteInterfaces); + // XXX todo + + } else { + trace("handleRegisteredServiceEvent","serviceReference="+serviceReference+" has no remoteInterfaces"); + } + traceExiting("handleRegisteredServiceEvent"); } + private void handleModifiedServiceEvent(ServiceReference serviceReference, + Object source, Collection contexts) { + traceEntering("handleModifiedServiceEvent"); + // TODO + traceExiting("handleModifiedServiceEvent"); + } + + + private void traceEntering(String methodName) { + Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, this.getClass(), methodName); + } + + private void traceExiting(String methodName) { + Trace.exiting(Activator.PLUGIN_ID, DebugOptions.METHODS_EXITING, this.getClass(), "handleUnregisteringServiceEvent"); + } + + private void trace(String methodName, String message) { + Trace.trace(Activator.PLUGIN_ID, DebugOptions.DEBUG, this.getClass(), methodName, message); + } + } diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/FindHookImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/FindHookImpl.java index 03b19a852..206210353 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/FindHookImpl.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/FindHookImpl.java @@ -16,6 +16,12 @@ import org.osgi.framework.hooks.service.FindHook; public class FindHookImpl implements FindHook { + private final ECFRSDistributionProvider distributionProvider; + + public FindHookImpl(ECFRSDistributionProvider distributionProvider) { + this.distributionProvider = distributionProvider; + } + public void find(BundleContext context, String name, String filter, boolean allServices, Collection references) { // TODO Auto-generated method stub diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ServiceInterfaceConstants.java b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ServiceInterfaceConstants.java new file mode 100644 index 000000000..800dad910 --- /dev/null +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/ServiceInterfaceConstants.java @@ -0,0 +1,16 @@ +/******************************************************************************* +* 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 ServiceInterfaceConstants { + + public static final String OSGI_REMOTE_INTERFACES_KEY = "osgi.remote.interfaces"; + +} |