diff options
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.jmdns')
5 files changed, 68 insertions, 0 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/plugin.xml b/providers/bundles/org.eclipse.ecf.provider.jmdns/plugin.xml index d232114f8..bf5e83bac 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/plugin.xml +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/plugin.xml @@ -17,5 +17,12 @@ description="JMDNS Namespace" name="ecf.namespace.jmdns"/> </extension> + <extension + point="org.eclipse.ecf.start"> + <run + asynchronous="true" + class="org.eclipse.ecf.internal.provider.jmdns.DiscoveryStart"> + </run> + </extension> </plugin> diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/DiscoveryStart.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/DiscoveryStart.java new file mode 100644 index 000000000..52b011a92 --- /dev/null +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/DiscoveryStart.java @@ -0,0 +1,34 @@ +package org.eclipse.ecf.internal.provider.jmdns; + +import java.net.InetAddress; +import java.util.Properties; +import org.eclipse.core.runtime.*; +import org.eclipse.ecf.core.IContainer; +import org.eclipse.ecf.core.start.IECFStart; +import org.eclipse.ecf.discovery.service.IDiscoveryService; +import org.eclipse.ecf.provider.jmdns.container.JMDNSDiscoveryContainer; + +public class DiscoveryStart implements IECFStart { + + public DiscoveryStart() { + // nothing to do + } + + public IStatus run(IProgressMonitor monitor) { + IDiscoveryService discovery = JMDNSPlugin.getDefault().getDiscoveryService(); + if (discovery == null) { + try { + IContainer discoveryContainer = new JMDNSDiscoveryContainer(InetAddress.getLocalHost()); + discoveryContainer.connect(null, null); + Properties props = new Properties(); + props.put(IDiscoveryService.CONTAINER_ID, discoveryContainer.getID()); + JMDNSPlugin.getDefault().getContext().registerService(IDiscoveryService.class.getName(), discoveryContainer, props); + } catch (Exception e) { + e.printStackTrace(); + return new Status(IStatus.WARNING, JMDNSPlugin.PLUGIN_ID, IStatus.WARNING, Messages.ECFStart_WARNING_COULD_NOT_REGISTER_DISCOVERY, e); + } + } + return Status.OK_STATUS; + } + +} diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSPlugin.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSPlugin.java index 8f1ace805..277fdfe8c 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSPlugin.java +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSPlugin.java @@ -12,6 +12,7 @@ package org.eclipse.ecf.internal.provider.jmdns; import org.eclipse.core.runtime.IAdapterManager; import org.eclipse.ecf.core.util.PlatformHelper; +import org.eclipse.ecf.discovery.service.IDiscoveryService; import org.osgi.framework.*; import org.osgi.util.tracker.ServiceTracker; @@ -36,6 +37,10 @@ public class JMDNSPlugin implements BundleActivator { private ServiceTracker adapterManagerTracker = null; + private ServiceTracker discoveryTracker; + + private ServiceRegistration serviceRegistration; + public IAdapterManager getAdapterManager() { // First, try to get the adapter manager via if (adapterManagerTracker == null) { @@ -63,14 +68,34 @@ public class JMDNSPlugin implements BundleActivator { return context.getBundle(); } + protected BundleContext getContext() { + return context; + } + + public IDiscoveryService getDiscoveryService() { + if (discoveryTracker == null) { + discoveryTracker = new ServiceTracker(context, IDiscoveryService.class.getName(), null); + discoveryTracker.open(); + } + return (IDiscoveryService) discoveryTracker.getService(); + } + /** * This method is called when the plug-in is stopped */ public void stop(BundleContext ctxt) throws Exception { + if (serviceRegistration != null) { + serviceRegistration.unregister(); + serviceRegistration = null; + } if (adapterManagerTracker != null) { adapterManagerTracker.close(); adapterManagerTracker = null; } + if (discoveryTracker != null) { + discoveryTracker.close(); + discoveryTracker = null; + } this.context = ctxt; plugin = null; } diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/Messages.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/Messages.java index 4d2ba6590..f2f217aef 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/Messages.java +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/Messages.java @@ -20,6 +20,7 @@ public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.ecf.internal.provider.jmdns.messages"; //$NON-NLS-1$ public static String ContainerInstantiator_EXCEPTION_CONTAINER_CREATE; public static String ContainerInstantiator_EXCEPTION_GETTING_INETADDRESS; + public static String ECFStart_WARNING_COULD_NOT_REGISTER_DISCOVERY; public static String JMDNSDiscoveryContainer_EXCEPTION_ALREADY_CONNECTED; public static String JMDNSDiscoveryContainer_EXCEPTION_CONTAINER_DISPOSED; public static String JMDNSDiscoveryContainer_EXCEPTION_CREATE_JMDNS_INSTANCE; diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/messages.properties b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/messages.properties index e7e61c983..14c40a2a3 100644 --- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/messages.properties +++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/messages.properties @@ -10,6 +10,7 @@ JMDNSDiscoveryContainer_EXCEPTION_REGISTER_SERVICE=registerService JMDNSDiscoveryContainer_EXCEPTION_SERVICEINFO_INVALID=ServiceInfo is invalid. ContainerInstantiator_EXCEPTION_CONTAINER_CREATE=Exception making JMDNS container ContainerInstantiator_EXCEPTION_GETTING_INETADDRESS=Exception getting InetAddress for JMDNS container +ECFStart_WARNING_COULD_NOT_REGISTER_DISCOVERY=Could not register JMDNS discovery JMDNSNamespace_EXCEPTION_TYPE_PARAM_NOT_STRING=First parameter cannot be cast to String JMDNSNamespace_EXCEPTION_ID_PARAM_2_WRONG_TYPE=Second parameter cannot be cast to String JMDNSNamespace_EXCEPTION_ID_CREATE_SERVICE_TYPE_CANNOT_BE_EMPTY=service type cannot be empty |