diff options
author | slewis | 2009-05-01 19:28:02 +0000 |
---|---|---|
committer | slewis | 2009-05-01 19:28:02 +0000 |
commit | fd690bd48520592db48db4fc9f7345a102f6258c (patch) | |
tree | a259cd834e6d23531e0fc508e295c42e3bb6997c | |
parent | 5324c0721b5be055b00ee0563a523024923d174c (diff) | |
download | org.eclipse.ecf-fd690bd48520592db48db4fc9f7345a102f6258c.tar.gz org.eclipse.ecf-fd690bd48520592db48db4fc9f7345a102f6258c.tar.xz org.eclipse.ecf-fd690bd48520592db48db4fc9f7345a102f6258c.zip |
Added new API: IHostDistributionListener, IProxyDistributionListener, IHostDiscoveryListener, IProxyDiscoveryListener to allow notification of discovery and distribution for host and proxy events.
11 files changed, 358 insertions, 79 deletions
diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/.settings/org.eclipse.jdt.core.prefs b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/.settings/org.eclipse.jdt.core.prefs index 7a347b9cb..73e4e2669 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/.settings/org.eclipse.jdt.core.prefs +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#Tue Feb 03 16:43:43 PST 2009 +#Fri May 01 09:29:50 PDT 2009 eclipse.preferences.version=1 org.eclipse.jdt.core.builder.cleanOutputFolder=clean org.eclipse.jdt.core.builder.duplicateResourceTask=warning @@ -8,8 +8,16 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.maxProblemPerUnit=100 org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning org.eclipse.jdt.core.compiler.problem.deadCode=warning @@ -18,6 +26,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore @@ -71,5 +80,6 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.source=1.5 org.eclipse.jdt.core.incompatibleJDKLevel=ignore org.eclipse.jdt.core.incompleteClasspath=error diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/.settings/org.eclipse.jdt.ui.prefs b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/.settings/org.eclipse.jdt.ui.prefs index 9bb86c1d3..71b405fb2 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/.settings/org.eclipse.jdt.ui.prefs +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/.settings/org.eclipse.jdt.ui.prefs @@ -1,11 +1,11 @@ -#Wed Oct 10 22:18:36 EDT 2007 +#Fri May 01 09:30:31 PDT 2009 eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_core formatter_settings_version=11 org.eclipse.jdt.ui.ignorelowercasenames=true org.eclipse.jdt.ui.importorder=; -org.eclipse.jdt.ui.ondemandthreshold=3 +org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.staticondemandthreshold=99 sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_generated_serial_version_id=false diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/.settings/org.eclipse.pde.api.tools.prefs b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/.settings/org.eclipse.pde.api.tools.prefs new file mode 100644 index 000000000..c824b7ce4 --- /dev/null +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/.settings/org.eclipse.pde.api.tools.prefs @@ -0,0 +1,91 @@ +#Fri May 01 09:30:02 PDT 2009 +ANNOTATION_ELEMENT_TYPE_ADDED_METHOD_WITHOUT_DEFAULT_VALUE=Error +ANNOTATION_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error +ANNOTATION_ELEMENT_TYPE_REMOVED_FIELD=Error +ANNOTATION_ELEMENT_TYPE_REMOVED_METHOD=Error +ANNOTATION_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error +API_COMPONENT_ELEMENT_TYPE_REMOVED_API_TYPE=Error +API_COMPONENT_ELEMENT_TYPE_REMOVED_TYPE=Error +CLASS_ELEMENT_TYPE_ADDED_METHOD=Error +CLASS_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error +CLASS_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error +CLASS_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error +CLASS_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error +CLASS_ELEMENT_TYPE_CHANGED_NON_ABSTRACT_TO_ABSTRACT=Error +CLASS_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error +CLASS_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error +CLASS_ELEMENT_TYPE_REMOVED_CONSTRUCTOR=Error +CLASS_ELEMENT_TYPE_REMOVED_FIELD=Error +CLASS_ELEMENT_TYPE_REMOVED_METHOD=Error +CLASS_ELEMENT_TYPE_REMOVED_SUPERCLASS=Error +CLASS_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error +CLASS_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error +CONSTRUCTOR_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error +CONSTRUCTOR_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error +CONSTRUCTOR_ELEMENT_TYPE_CHANGED_VARARGS_TO_ARRAY=Error +CONSTRUCTOR_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error +ENUM_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error +ENUM_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error +ENUM_ELEMENT_TYPE_REMOVED_ENUM_CONSTANT=Error +ENUM_ELEMENT_TYPE_REMOVED_FIELD=Error +ENUM_ELEMENT_TYPE_REMOVED_METHOD=Error +ENUM_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error +FIELD_ELEMENT_TYPE_ADDED_VALUE=Error +FIELD_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error +FIELD_ELEMENT_TYPE_CHANGED_FINAL_TO_NON_FINAL_STATIC_CONSTANT=Error +FIELD_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error +FIELD_ELEMENT_TYPE_CHANGED_NON_STATIC_TO_STATIC=Error +FIELD_ELEMENT_TYPE_CHANGED_STATIC_TO_NON_STATIC=Error +FIELD_ELEMENT_TYPE_CHANGED_TYPE=Error +FIELD_ELEMENT_TYPE_CHANGED_VALUE=Error +FIELD_ELEMENT_TYPE_REMOVED_TYPE_ARGUMENT=Error +FIELD_ELEMENT_TYPE_REMOVED_VALUE=Error +ILLEGAL_EXTEND=Warning +ILLEGAL_IMPLEMENT=Warning +ILLEGAL_INSTANTIATE=Warning +ILLEGAL_OVERRIDE=Warning +ILLEGAL_REFERENCE=Warning +INTERFACE_ELEMENT_TYPE_ADDED_FIELD=Error +INTERFACE_ELEMENT_TYPE_ADDED_METHOD=Error +INTERFACE_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error +INTERFACE_ELEMENT_TYPE_ADDED_SUPER_INTERFACE_WITH_METHODS=Error +INTERFACE_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error +INTERFACE_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error +INTERFACE_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error +INTERFACE_ELEMENT_TYPE_REMOVED_FIELD=Error +INTERFACE_ELEMENT_TYPE_REMOVED_METHOD=Error +INTERFACE_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error +INTERFACE_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error +INVALID_JAVADOC_TAG=Ignore +INVALID_REFERENCE_IN_SYSTEM_LIBRARIES=Ignore +LEAK_EXTEND=Warning +LEAK_FIELD_DECL=Warning +LEAK_IMPLEMENT=Warning +LEAK_METHOD_PARAM=Warning +LEAK_METHOD_RETURN_TYPE=Warning +METHOD_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error +METHOD_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error +METHOD_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error +METHOD_ELEMENT_TYPE_CHANGED_NON_ABSTRACT_TO_ABSTRACT=Error +METHOD_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error +METHOD_ELEMENT_TYPE_CHANGED_NON_STATIC_TO_STATIC=Error +METHOD_ELEMENT_TYPE_CHANGED_STATIC_TO_NON_STATIC=Error +METHOD_ELEMENT_TYPE_CHANGED_VARARGS_TO_ARRAY=Error +METHOD_ELEMENT_TYPE_REMOVED_ANNOTATION_DEFAULT_VALUE=Error +METHOD_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error +TYPE_PARAMETER_ELEMENT_TYPE_ADDED_CLASS_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_ADDED_INTERFACE_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_CHANGED_CLASS_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_CHANGED_INTERFACE_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_REMOVED_CLASS_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_REMOVED_INTERFACE_BOUND=Error +UNUSED_PROBLEM_FILTERS=Warning +eclipse.preferences.version=1 +incompatible_api_component_version=Error +incompatible_api_component_version_include_major_without_breaking_change=Disabled +incompatible_api_component_version_include_minor_without_api_change=Disabled +invalid_since_tag_version=Error +malformed_since_tag=Error +missing_since_tag=Error +report_api_breakage_when_major_version_incremented=Disabled +report_resolution_errors_api_component=Warning diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/Activator.java b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/Activator.java index e05353ec5..2ca58ac5e 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/Activator.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/Activator.java @@ -9,6 +9,7 @@ ******************************************************************************/ package org.eclipse.ecf.internal.osgi.services.discovery; +import java.util.Arrays; import java.util.Dictionary; import java.util.Hashtable; import org.eclipse.core.runtime.IStatus; @@ -16,8 +17,14 @@ import org.eclipse.ecf.core.util.LogHelper; import org.eclipse.ecf.core.util.SystemLogService; import org.eclipse.ecf.discovery.IDiscoveryAdvertiser; import org.eclipse.ecf.discovery.IDiscoveryLocator; -import org.osgi.framework.*; -import org.osgi.service.discovery.*; +import org.eclipse.ecf.osgi.services.discovery.IHostDiscoveryListener; +import org.eclipse.ecf.osgi.services.discovery.IProxyDiscoveryListener; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.discovery.DiscoveredServiceTracker; +import org.osgi.service.discovery.Discovery; +import org.osgi.service.discovery.ServicePublication; import org.osgi.service.log.LogService; import org.osgi.util.tracker.ServiceTracker; import org.osgi.util.tracker.ServiceTrackerCustomizer; @@ -44,6 +51,9 @@ public class Activator implements BundleActivator { return plugin; } + private ServiceTracker hostPublicationListenerTracker; + private ServiceTracker proxyDiscoveredListenerTracker; + /* * (non-Javadoc) * @@ -80,7 +90,9 @@ public class Activator implements BundleActivator { } } - protected LogService getLogService() { + protected synchronized LogService getLogService() { + if (this.context == null) + return null; if (logServiceTracker == null) { logServiceTracker = new ServiceTracker(this.context, LogService.class.getName(), null); @@ -120,7 +132,10 @@ public class Activator implements BundleActivator { return servicePublicationHandler; } - public IDiscoveryAdvertiser getAdvertiser() throws InterruptedException { + public synchronized IDiscoveryAdvertiser getAdvertiser() + throws InterruptedException { + if (this.context == null) + return null; if (advertiserTracker == null) { advertiserTracker = new ServiceTracker(this.context, IDiscoveryAdvertiser.class.getName(), null); @@ -139,6 +154,36 @@ public class Activator implements BundleActivator { return discoveredServiceTrackerTracker.getServiceReferences(); } + public synchronized IHostDiscoveryListener[] getHostPublicationListeners() { + if (this.context == null) + return null; + if (hostPublicationListenerTracker == null) { + hostPublicationListenerTracker = new ServiceTracker(this.context, + IHostDiscoveryListener.class.getName(), null); + hostPublicationListenerTracker.open(); + } + Object[] objs = hostPublicationListenerTracker.getServices(); + if (objs == null) + return null; + return (IHostDiscoveryListener[]) Arrays.asList(objs).toArray( + new IHostDiscoveryListener[] {}); + } + + public synchronized IProxyDiscoveryListener[] getProxyDiscoveredListeners() { + if (this.context == null) + return null; + if (proxyDiscoveredListenerTracker == null) { + proxyDiscoveredListenerTracker = new ServiceTracker(this.context, + IProxyDiscoveryListener.class.getName(), null); + proxyDiscoveredListenerTracker.open(); + } + Object[] objs = proxyDiscoveredListenerTracker.getServices(); + if (objs == null) + return null; + return (IProxyDiscoveryListener[]) Arrays.asList(objs).toArray( + new IProxyDiscoveryListener[] {}); + } + /* * (non-Javadoc) * @@ -171,6 +216,14 @@ public class Activator implements BundleActivator { logServiceTracker = null; logService = null; } + if (hostPublicationListenerTracker != null) { + hostPublicationListenerTracker.close(); + hostPublicationListenerTracker = null; + } + if (proxyDiscoveredListenerTracker != null) { + proxyDiscoveredListenerTracker.close(); + proxyDiscoveredListenerTracker = null; + } this.context = null; plugin = null; } diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/RemoteServiceEndpointDescriptionImpl.java b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/RemoteServiceEndpointDescriptionImpl.java index 226848a97..6a48880c9 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/RemoteServiceEndpointDescriptionImpl.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/RemoteServiceEndpointDescriptionImpl.java @@ -10,8 +10,12 @@ ******************************************************************************/ package org.eclipse.ecf.internal.osgi.services.discovery; -import org.eclipse.ecf.core.identity.*; -import org.eclipse.ecf.discovery.*; +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.core.identity.IDCreateException; +import org.eclipse.ecf.core.identity.IDFactory; +import org.eclipse.ecf.discovery.IServiceInfo; +import org.eclipse.ecf.discovery.IServiceProperties; +import org.eclipse.ecf.discovery.ServiceProperties; import org.eclipse.ecf.discovery.identity.IServiceID; import org.eclipse.ecf.osgi.services.discovery.RemoteServiceEndpointDescription; import org.eclipse.ecf.osgi.services.discovery.RemoteServicePublication; diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/ServicePropertyUtils.java b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/ServicePropertyUtils.java index 14bc6ce81..2414ca680 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/ServicePropertyUtils.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/ServicePropertyUtils.java @@ -9,10 +9,14 @@ ******************************************************************************/ package org.eclipse.ecf.internal.osgi.services.discovery; -import org.osgi.service.discovery.ServicePublication; - -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; import org.osgi.framework.ServiceReference; +import org.osgi.service.discovery.ServicePublication; public class ServicePropertyUtils { @@ -77,7 +81,8 @@ public class ServicePropertyUtils { if (value == null) { return null; } - final StringTokenizer t = new StringTokenizer(value, COLLECTION_SEPARATOR); + final StringTokenizer t = new StringTokenizer(value, + COLLECTION_SEPARATOR); final List result = new ArrayList(); while (t.hasMoreTokens()) { result.add(t.nextToken()); diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/ServicePublicationHandler.java b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/ServicePublicationHandler.java index a42f92857..b05305ceb 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/ServicePublicationHandler.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/ServicePublicationHandler.java @@ -10,17 +10,43 @@ package org.eclipse.ecf.internal.osgi.services.discovery; import java.io.Serializable; -import java.net.*; -import java.util.*; -import org.eclipse.ecf.core.identity.*; +import java.net.InetAddress; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import org.eclipse.core.runtime.ISafeRunnable; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.core.identity.IDCreateException; +import org.eclipse.ecf.core.identity.Namespace; import org.eclipse.ecf.core.util.ECFRuntimeException; import org.eclipse.ecf.core.util.Trace; -import org.eclipse.ecf.discovery.*; -import org.eclipse.ecf.discovery.identity.*; +import org.eclipse.ecf.discovery.IDiscoveryAdvertiser; +import org.eclipse.ecf.discovery.IServiceEvent; +import org.eclipse.ecf.discovery.IServiceInfo; +import org.eclipse.ecf.discovery.IServiceListener; +import org.eclipse.ecf.discovery.IServiceProperties; +import org.eclipse.ecf.discovery.ServiceInfo; +import org.eclipse.ecf.discovery.ServiceProperties; +import org.eclipse.ecf.discovery.identity.IServiceID; +import org.eclipse.ecf.discovery.identity.IServiceTypeID; +import org.eclipse.ecf.discovery.identity.ServiceIDFactory; +import org.eclipse.ecf.osgi.services.discovery.IHostDiscoveryListener; +import org.eclipse.ecf.osgi.services.discovery.IProxyDiscoveryListener; import org.eclipse.ecf.osgi.services.discovery.RemoteServicePublication; import org.eclipse.ecf.remoteservice.Constants; import org.osgi.framework.ServiceReference; -import org.osgi.service.discovery.*; +import org.osgi.service.discovery.DiscoveredServiceNotification; +import org.osgi.service.discovery.DiscoveredServiceTracker; +import org.osgi.service.discovery.Discovery; +import org.osgi.service.discovery.ServicePublication; import org.osgi.util.tracker.ServiceTrackerCustomizer; public class ServicePublicationHandler implements ServiceTrackerCustomizer, @@ -36,8 +62,18 @@ public class ServicePublicationHandler implements ServiceTrackerCustomizer, * org.eclipse.ecf.discovery.IServiceListener#serviceDiscovered(org.eclipse * .ecf.discovery.IServiceEvent) */ - public void serviceDiscovered(IServiceEvent anEvent) { - handleServiceDiscovered(anEvent); + public void serviceDiscovered(IServiceEvent event) { + IServiceInfo serviceInfo = event.getServiceInfo(); + IServiceID serviceID = serviceInfo.getServiceID(); + trace("handleOSGIServiceDiscovered", " serviceInfo=" + serviceInfo); //$NON-NLS-1$ //$NON-NLS-2$ + if (matchServiceID(serviceID)) { + fireProxyDiscoveredUndiscovered(serviceInfo, true); + trace( + "handleOSGIServiceDiscovered matched", " serviceInfo=" + serviceInfo); //$NON-NLS-1$ //$NON-NLS-2$ + DiscoveredServiceTracker[] discoveredTrackers = findMatchingDiscoveredServiceTrackers(serviceInfo); + notifyDiscoveredServiceTrackers(discoveredTrackers, serviceInfo, + true); + } } /* @@ -47,43 +83,29 @@ public class ServicePublicationHandler implements ServiceTrackerCustomizer, * org.eclipse.ecf.discovery.IServiceListener#serviceUndiscovered(org.eclipse * .ecf.discovery.IServiceEvent) */ - public void serviceUndiscovered(IServiceEvent anEvent) { - handleServiceUndiscovered(anEvent); - } - - private void handleServiceDiscovered(IServiceEvent event) { + public void serviceUndiscovered(IServiceEvent event) { IServiceInfo serviceInfo = event.getServiceInfo(); IServiceID serviceID = serviceInfo.getServiceID(); - trace("handleOSGIServiceDiscovered", " serviceInfo=" + serviceInfo); //$NON-NLS-1$ //$NON-NLS-2$ if (matchServiceID(serviceID)) { + fireProxyDiscoveredUndiscovered(serviceInfo, false); trace( - "handleOSGIServiceDiscovered matched", " serviceInfo=" + serviceInfo); //$NON-NLS-1$ //$NON-NLS-2$ + "handleOSGIServiceUndiscovered", " serviceInfo=" + serviceInfo); //$NON-NLS-1$ //$NON-NLS-2$ DiscoveredServiceTracker[] discoveredTrackers = findMatchingDiscoveredServiceTrackers(serviceInfo); - if (discoveredTrackers != null) { - for (int i = 0; i < discoveredTrackers.length; i++) { - discoveredTrackers[i] - .serviceChanged(new DiscoveredServiceNotificationImpl( - DiscoveredServiceNotification.AVAILABLE, - serviceInfo)); - } - } + notifyDiscoveredServiceTrackers(discoveredTrackers, serviceInfo, + false); } } - private void handleServiceUndiscovered(IServiceEvent event) { - IServiceInfo serviceInfo = event.getServiceInfo(); - IServiceID serviceID = serviceInfo.getServiceID(); - if (matchServiceID(serviceID)) { - trace( - "handleOSGIServiceUndiscovered", " serviceInfo=" + serviceInfo); //$NON-NLS-1$ //$NON-NLS-2$ - DiscoveredServiceTracker[] discoveredTrackers = findMatchingDiscoveredServiceTrackers(serviceInfo); - if (discoveredTrackers != null) { - for (int i = 0; i < discoveredTrackers.length; i++) { - discoveredTrackers[i] - .serviceChanged(new DiscoveredServiceNotificationImpl( - DiscoveredServiceNotification.UNAVAILABLE, - serviceInfo)); - } + private void notifyDiscoveredServiceTrackers( + DiscoveredServiceTracker[] discoveredTrackers, + IServiceInfo serviceInfo, boolean available) { + if (discoveredTrackers != null) { + for (int i = 0; i < discoveredTrackers.length; i++) { + discoveredTrackers[i] + .serviceChanged(new DiscoveredServiceNotificationImpl( + (available ? DiscoveredServiceNotification.AVAILABLE + : DiscoveredServiceNotification.UNAVAILABLE), + serviceInfo)); } } } @@ -154,7 +176,7 @@ public class ServicePublicationHandler implements ServiceTrackerCustomizer, "handleServicePublication", //$NON-NLS-1$ "ignoring " //$NON-NLS-1$ + reference - + ". ServicePublication.PROP_KEY_SERVICE_INTERFACE_NAME not set", //$NON-NLS-1$ + + ". ServicePublication.SERVICE_INTERFACE_NAME not set", //$NON-NLS-1$ null); return; } @@ -167,19 +189,11 @@ public class ServicePublicationHandler implements ServiceTrackerCustomizer, Map servicePublicationServiceProperties = ServicePropertyUtils .getMapProperty(reference, ServicePublication.SERVICE_PROPERTIES); - if (servicePublicationServiceProperties == null) { - logError( - "handleServicePublication", //$NON-NLS-1$ - "ignoring " //$NON-NLS-1$ - + reference - + ". ServicePublication.PROP_KEY_SERVICE_PROPERTIES not set", //$NON-NLS-1$ - null); - return; - } // Add them - - addPropertiesToDiscoveryServiceProperties(discoveryServiceProperties, - servicePublicationServiceProperties); + if (servicePublicationServiceProperties != null) + addPropertiesToDiscoveryServiceProperties( + discoveryServiceProperties, + servicePublicationServiceProperties); // See EventHookImpl.getServicePublicationProperties() // Get and then serialize and set @@ -229,24 +243,16 @@ public class ServicePublicationHandler implements ServiceTrackerCustomizer, // add remote service namespace String rsnamespace = ServicePropertyUtils.getStringProperty(reference, Constants.SERVICE_NAMESPACE); - if (rsnamespace == null) { - logError("handleServicePublication", "ignoring " + reference //$NON-NLS-1$ //$NON-NLS-2$ - + ". Constants.SERVICE_NAMESPACE not set", null); //$NON-NLS-1$ - return; - } - discoveryServiceProperties.setPropertyString( - Constants.SERVICE_NAMESPACE, rsnamespace); + if (rsnamespace != null) + discoveryServiceProperties.setPropertyString( + Constants.SERVICE_NAMESPACE, rsnamespace); // and remote service id Long remoteServiceID = (Long) reference .getProperty(Constants.SERVICE_ID); - if (remoteServiceID == null) { - logError("handleServicePublication", "ignoring " + reference //$NON-NLS-1$ //$NON-NLS-2$ - + ". Constants.SERVICE_ID not set", null); //$NON-NLS-1$ - return; - } - discoveryServiceProperties.setProperty(Constants.SERVICE_ID, - remoteServiceID); + if (remoteServiceID != null) + discoveryServiceProperties.setProperty(Constants.SERVICE_ID, + remoteServiceID); Namespace advertiserNamespace = getAdvertiser().getServicesNamespace(); IServiceInfo svcInfo = null; @@ -271,6 +277,9 @@ public class ServicePublicationHandler implements ServiceTrackerCustomizer, logError("handleServicePublication", "Exception creating URI", e); //$NON-NLS-1$ //$NON-NLS-2$ return; } + + fireHostPublishUnpublish(reference, svcInfo, true); + synchronized (serviceInfos) { try { trace("publishService", "publishing serviceReference=" //$NON-NLS-1$ //$NON-NLS-2$ @@ -283,6 +292,64 @@ public class ServicePublicationHandler implements ServiceTrackerCustomizer, } } + private void fireHostPublishUnpublish(final ServiceReference reference, + final IServiceInfo serviceInfo, final boolean publish) { + Activator activator = Activator.getDefault(); + if (activator != null) { + IHostDiscoveryListener[] listeners = activator + .getHostPublicationListeners(); + if (listeners != null) { + for (int i = 0; i < listeners.length; i++) { + final IHostDiscoveryListener l = listeners[i]; + SafeRunner.run(new ISafeRunnable() { + public void handleException(Throwable exception) { + logError( + "fireHostPublishUnpublish", + "Exception calling host discovery listener", + exception); + } + + public void run() throws Exception { + if (publish) + l.publish(reference, serviceInfo); + else + l.unpublish(reference, serviceInfo); + } + }); + } + } + } + } + + private void fireProxyDiscoveredUndiscovered( + final IServiceInfo serviceInfo, final boolean discovered) { + Activator activator = Activator.getDefault(); + if (activator != null) { + IProxyDiscoveryListener[] listeners = activator + .getProxyDiscoveredListeners(); + if (listeners != null) { + for (int i = 0; i < listeners.length; i++) { + final IProxyDiscoveryListener l = listeners[i]; + SafeRunner.run(new ISafeRunnable() { + public void handleException(Throwable exception) { + logError( + "fireProxyDiscoveredUndiscovered", + "Exception calling proxy discovery listener", + exception); + } + + public void run() throws Exception { + if (discovered) + l.discovered(serviceInfo); + else + l.undiscovered(serviceInfo); + } + }); + } + } + } + } + private void logError(String method, String message, Throwable exception) { LogUtility.logError(method, message, this.getClass(), exception); } @@ -356,6 +423,8 @@ public class ServicePublicationHandler implements ServiceTrackerCustomizer, } private String getPropertyWithDefault(Map properties, String key, String def) { + if (properties == null) + return def; String val = (String) properties.get(key); return (val == null) ? def : val; } @@ -414,6 +483,8 @@ public class ServicePublicationHandler implements ServiceTrackerCustomizer, + svcInfo, e); } } + if (svcInfo != null) + fireHostPublishUnpublish(reference, svcInfo, false); } protected void trace(String methodName, String message) { diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/IHostDiscoveryListener.java b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/IHostDiscoveryListener.java new file mode 100644 index 000000000..2c5490446 --- /dev/null +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/IHostDiscoveryListener.java @@ -0,0 +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 + ******************************************************************************/ +package org.eclipse.ecf.osgi.services.discovery; + +import org.eclipse.ecf.discovery.IServiceInfo; +import org.osgi.framework.ServiceReference; + +public interface IHostDiscoveryListener { + + public void publish(ServiceReference publicationServiceReference, + IServiceInfo serviceInfo); + + public void unpublish(ServiceReference publicationServiceReference, + IServiceInfo serviceInfo); + +} diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/IProxyDiscoveryListener.java b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/IProxyDiscoveryListener.java new file mode 100644 index 000000000..bf1edb2ac --- /dev/null +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/IProxyDiscoveryListener.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * 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.osgi.services.discovery; + +import org.eclipse.ecf.discovery.IServiceInfo; + +public interface IProxyDiscoveryListener { + + public void discovered(IServiceInfo serviceInfo); + + public void undiscovered(IServiceInfo serviceInfo); +} diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/IRemoteServiceEndpointDescription.java b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/IRemoteServiceEndpointDescription.java index 72bdb605f..27ba558eb 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/IRemoteServiceEndpointDescription.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/IRemoteServiceEndpointDescription.java @@ -13,7 +13,8 @@ import java.util.Map; import org.eclipse.ecf.core.identity.ID; import org.osgi.service.discovery.ServiceEndpointDescription; -public interface IRemoteServiceEndpointDescription extends ServiceEndpointDescription { +public interface IRemoteServiceEndpointDescription extends + ServiceEndpointDescription { /** * Get the ECF endpoint ID (the ID of the endpoint that exposes the given diff --git a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/RemoteServiceEndpointDescription.java b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/RemoteServiceEndpointDescription.java index 9b99a277e..01644c71c 100644 --- a/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/RemoteServiceEndpointDescription.java +++ b/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/osgi/services/discovery/RemoteServiceEndpointDescription.java @@ -11,7 +11,9 @@ package org.eclipse.ecf.osgi.services.discovery; import java.net.URI; import java.net.URISyntaxException; -import java.util.*; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.ecf.core.identity.ID; |