Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkuppe2007-11-29 12:10:43 +0000
committermkuppe2007-11-29 12:10:43 +0000
commit4416d16984e5e9c9f22548cfd78d4d78ff029f2b (patch)
tree65ddf8a028893956791304514cdae982bcc2c4e9 /providers/bundles/org.eclipse.ecf.provider.jmdns
parent42152aed10d0b009d8ec1778da2e18950d8a2c8b (diff)
downloadorg.eclipse.ecf-4416d16984e5e9c9f22548cfd78d4d78ff029f2b.tar.gz
org.eclipse.ecf-4416d16984e5e9c9f22548cfd78d4d78ff029f2b.tar.xz
org.eclipse.ecf-4416d16984e5e9c9f22548cfd78d4d78ff029f2b.zip
ASSIGNED - bug 209774: Simplify/generalize discovery API (summary bug)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=209774
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.jmdns')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/.classpath4
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/META-INF/MANIFEST.MF10
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSPlugin.java3
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/Messages.java1
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/messages.properties1
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSDiscoveryContainer.java360
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSServiceInfo.java8
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSNamespace.java22
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSServiceTypeID.java1
9 files changed, 226 insertions, 184 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/.classpath b/providers/bundles/org.eclipse.ecf.provider.jmdns/.classpath
index c645d1461..c6469a7d2 100644
--- a/providers/bundles/org.eclipse.ecf.provider.jmdns/.classpath
+++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/.classpath
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
- <classpathentry exported="true" kind="lib" path="lib/jmdns-1.0.3.jar"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry exported="true" kind="lib" path="lib/jmdns-1.0.3.jar" sourcepath="/jmdns-1.0"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/META-INF/MANIFEST.MF b/providers/bundles/org.eclipse.ecf.provider.jmdns/META-INF/MANIFEST.MF
index 82daef9d9..50752cb95 100644
--- a/providers/bundles/org.eclipse.ecf.provider.jmdns/META-INF/MANIFEST.MF
+++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/META-INF/MANIFEST.MF
@@ -2,17 +2,17 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.ecf.provider.jmdns;singleton:=true
-Bundle-Version: 1.2.0.qualifier
+Bundle-Version: 2.0.0.qualifier
Bundle-Activator: org.eclipse.ecf.internal.provider.jmdns.JMDNSPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
-Require-Bundle: org.eclipse.equinox.common,
+Require-Bundle: org.eclipse.ecf.discovery,
org.eclipse.ecf,
- org.eclipse.ecf.discovery
+ org.eclipse.equinox.common
Eclipse-LazyStart: true
Bundle-ClassPath: ., lib/jmdns-1.0.3.jar
-Bundle-RequiredExecutionEnvironment: J2SE-1.4,
- CDC-1.1/Foundation-1.1
+Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
+ J2SE-1.4
Export-Package: org.eclipse.ecf.internal.provider.jmdns;x-internal:=true,
org.eclipse.ecf.provider.jmdns.container,
org.eclipse.ecf.provider.jmdns.identity
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 3bd5d224c..8f1ace805 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
@@ -79,9 +79,6 @@ public class JMDNSPlugin implements BundleActivator {
* Returns the shared instance.
*/
public synchronized static JMDNSPlugin getDefault() {
- if (plugin == null) {
- plugin = new JMDNSPlugin();
- }
return plugin;
}
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 a798eb7ec..39474c61d 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
@@ -21,6 +21,7 @@ public class Messages extends NLS {
public static String ContainerInstantiator_EXCEPTION_CONTAINER_CREATE;
public static String ContainerInstantiator_EXCEPTION_GETTING_INETADDRESS;
public static String JMDNSDiscoveryContainer_EXCEPTION_ALREADY_CONNECTED;
+ public static String JMDNSDiscoveryContainer_EXCEPTION_CONTAINER_DISPOSED;
public static String JMDNSDiscoveryContainer_EXCEPTION_CREATE_JMDNS_INSTANCE;
public static String JMDNSDiscoveryContainer_DISCOVERY_NOT_INITIALIZED;
public static String JMDNSDiscoveryContainer_EXCEPTION_REGISTER_SERVICE;
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 fc91fa832..94196097c 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
@@ -1,4 +1,5 @@
JMDNSDiscoveryContainer_EXCEPTION_ALREADY_CONNECTED=Already connected
+JMDNSDiscoveryContainer_EXCEPTION_CONTAINER_DISPOSED=Container disposed
JMDNSDiscoveryContainer_EXCEPTION_CREATE_JMDNS_INSTANCE=Exception creating JmDNS instance
JMDNSDiscoveryContainer_JMDNS_LOCAL_SUFFIX=.local.
JMDNSDiscoveryContainer_SERVICE_NAME_NOT_NULL=Service name cannot be null
diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSDiscoveryContainer.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSDiscoveryContainer.java
index 13c3892c4..f2e1a03f0 100644
--- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSDiscoveryContainer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSDiscoveryContainer.java
@@ -15,8 +15,8 @@ import java.net.InetAddress;
import java.util.*;
import javax.jmdns.*;
import javax.jmdns.ServiceInfo;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.core.ContainerConnectException;
-import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.events.*;
import org.eclipse.ecf.core.identity.*;
import org.eclipse.ecf.core.security.IConnectContext;
@@ -26,216 +26,283 @@ import org.eclipse.ecf.discovery.*;
import org.eclipse.ecf.discovery.identity.*;
import org.eclipse.ecf.discovery.service.IDiscoveryService;
import org.eclipse.ecf.internal.provider.jmdns.*;
-import org.eclipse.ecf.provider.jmdns.identity.*;
+import org.eclipse.ecf.provider.jmdns.identity.JMDNSNamespace;
-public class JMDNSDiscoveryContainer extends AbstractDiscoveryContainerAdapter implements IContainer, IDiscoveryService, ServiceListener, ServiceTypeListener {
+public class JMDNSDiscoveryContainer extends AbstractDiscoveryContainerAdapter implements IDiscoveryService, ServiceListener, ServiceTypeListener {
public static final int DEFAULT_REQUEST_TIMEOUT = 3000;
private static int instanceCount = 0;
private InetAddress intf = null;
- private JmDNS jmdns = null;
+ JmDNS jmdns = null;
private ID targetID = null;
+ List serviceTypes = null;
+
+ boolean disposed = false;
+ Object lock = new Object();
+
public JMDNSDiscoveryContainer(InetAddress addr) throws IDCreateException {
super(JMDNSNamespace.NAME, new DiscoveryContainerConfig(IDFactory.getDefault().createStringID(JMDNSDiscoveryContainer.class.getName() + ";" + addr.toString() + ";" + instanceCount++))); //$NON-NLS-1$ //$NON-NLS-2$
intf = addr;
+ serviceTypes = Collections.synchronizedList(new ArrayList());
}
+ /****************** IContainer methods **************************/
+
/* (non-Javadoc)
- * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServiceInfo(org.eclipse.ecf.discovery.identity.IServiceID, int)
+ * @see org.eclipse.ecf.core.IContainer#getConnectedID()
*/
- public IServiceInfo getServiceInfo(IServiceID service, int timeout) {
- Trace.entering(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.METHODS_ENTERING, this.getClass(), "getServiceInfo", new Object[] {service, new Integer(timeout)}); //$NON-NLS-1$
- IServiceInfo result = null;
- if (jmdns != null)
- result = createIServiceInfoFromServiceInfo(jmdns.getServiceInfo(service.getServiceTypeID().getName(), service.getServiceName(), timeout));
- Trace.exiting(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.METHODS_ENTERING, this.getClass(), "getServiceInfo", result); //$NON-NLS-1$
- return result;
+ public ID getConnectedID() {
+ return this.targetID;
}
- /**
- * @deprecated
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.AbstractDiscoveryContainerAdapter#dispose()
*/
- public IServiceInfo[] getServices(String type) {
- IServiceInfo svs[] = new IServiceInfo[0];
- if (jmdns != null) {
- final ServiceInfo[] svcs = jmdns.list(type);
- if (svcs != null) {
- svs = new IServiceInfo[svcs.length];
- for (int i = 0; i < svcs.length; i++) {
- svs[i] = createIServiceInfoFromServiceInfo(svcs[i]);
- }
- }
+ public void dispose() {
+ synchronized (lock) {
+ super.dispose();
+ disposed = true;
}
- return svs;
}
/* (non-Javadoc)
* @see org.eclipse.ecf.core.IContainer#connect(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.core.security.IConnectContext)
*/
public void connect(ID targetID1, IConnectContext joinContext) throws ContainerConnectException {
- if (this.targetID != null)
- throw new ContainerConnectException(Messages.JMDNSDiscoveryContainer_EXCEPTION_ALREADY_CONNECTED);
- this.targetID = (targetID1 == null) ? getConfig().getID() : targetID1;
- fireContainerEvent(new ContainerConnectingEvent(this.getID(), this.targetID, joinContext));
- try {
- this.jmdns = new JmDNS(intf);
- jmdns.addServiceTypeListener(this);
- if (targetID1 != null && targetID1 instanceof JMDNSServiceID) {
- final JMDNSServiceID svcid = (JMDNSServiceID) targetID1;
- final JMDNSServiceTypeID serviceTypeID = (JMDNSServiceTypeID) svcid.getServiceTypeID();
- jmdns.addServiceListener(serviceTypeID.getInternal(), this);
+ synchronized (lock) {
+ if (disposed)
+ throw new ContainerConnectException(Messages.JMDNSDiscoveryContainer_EXCEPTION_CONTAINER_DISPOSED);
+ if (this.targetID != null)
+ throw new ContainerConnectException(Messages.JMDNSDiscoveryContainer_EXCEPTION_ALREADY_CONNECTED);
+ this.targetID = (targetID1 == null) ? getConfig().getID() : targetID1;
+ fireContainerEvent(new ContainerConnectingEvent(this.getID(), this.targetID, joinContext));
+ try {
+ this.jmdns = new JmDNS(intf);
+ jmdns.addServiceTypeListener(this);
+ } catch (final IOException e) {
+ if (this.jmdns != null) {
+ jmdns.close();
+ jmdns = null;
+ }
+ throw new ContainerConnectException(Messages.JMDNSDiscoveryContainer_EXCEPTION_CREATE_JMDNS_INSTANCE);
}
- } catch (final IOException e) {
- throw new ContainerConnectException(Messages.JMDNSDiscoveryContainer_EXCEPTION_CREATE_JMDNS_INSTANCE);
+ fireContainerEvent(new ContainerConnectedEvent(this.getID(), this.targetID));
}
- fireContainerEvent(new ContainerConnectedEvent(this.getID(), this.targetID));
}
/* (non-Javadoc)
* @see org.eclipse.ecf.core.IContainer#disconnect()
*/
public void disconnect() {
- final ID connectedID = getConnectedID();
- fireContainerEvent(new ContainerDisconnectingEvent(this.getID(), connectedID));
- if (this.jmdns != null) {
- jmdns.close();
- jmdns = null;
+ synchronized (lock) {
+ if (this.jmdns != null) {
+ ID connectedID = getConnectedID();
+ fireContainerEvent(new ContainerDisconnectingEvent(this.getID(), connectedID));
+ jmdns.close();
+ jmdns = null;
+ this.targetID = null;
+ fireContainerEvent(new ContainerDisconnectedEvent(this.getID(), connectedID));
+ }
}
- this.targetID = null;
- clearListeners();
- fireContainerEvent(new ContainerDisconnectedEvent(this.getID(), connectedID));
}
+ /************************* IDiscoveryContainerAdapter methods *********************/
+
/* (non-Javadoc)
- * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#registerService(org.eclipse.ecf.discovery.IServiceInfo)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServiceInfo(org.eclipse.ecf.discovery.identity.IServiceID)
*/
- public void registerService(IServiceInfo serviceInfo) throws ECFException {
- if (jmdns == null)
- throw new ECFException(Messages.JMDNSDiscoveryContainer_DISCOVERY_NOT_INITIALIZED);
- final ServiceInfo svcInfo = createServiceInfoFromIServiceInfo(serviceInfo);
- checkServiceInfo(svcInfo);
- try {
- jmdns.registerService(svcInfo);
- } catch (final IOException e) {
- throw new ECFException(Messages.JMDNSDiscoveryContainer_EXCEPTION_REGISTER_SERVICE, e);
+ public IServiceInfo getServiceInfo(IServiceID service) {
+ Assert.isNotNull(service);
+ synchronized (lock) {
+ if (jmdns != null) {
+ try {
+ ServiceInfo serviceInfo = jmdns.getServiceInfo(service.getServiceTypeID().getInternal(), service.getServiceName());
+ return (serviceInfo == null) ? null : createIServiceInfoFromServiceInfo(serviceInfo);
+ } catch (Exception e) {
+ Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "getServiceInfo", e); //$NON-NLS-1$
+ return null;
+ }
+ }
}
+ return null;
}
- /**
- * @deprecated
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServices()
*/
- public void registerServiceType(String serviceType) {
- if (jmdns != null && serviceType != null) {
- jmdns.registerServiceType(serviceType);
- jmdns.addServiceListener(serviceType, this);
+ public IServiceInfo[] getServices() {
+ synchronized (lock) {
+ IServiceTypeID[] serviceTypeArray = getServiceTypes();
+ List results = new ArrayList();
+ for (int i = 0; i < serviceTypeArray.length; i++) {
+ results.addAll(Arrays.asList(getServices(serviceTypeArray[i])));
+ }
+ return (IServiceInfo[]) results.toArray(new IServiceInfo[] {});
}
}
- protected void checkServiceInfo(ServiceInfo serviceInfo) throws ECFException {
- final String serviceName = serviceInfo.getName();
- if (serviceName == null)
- throw new ECFException(Messages.JMDNSDiscoveryContainer_SERVICE_NAME_NOT_NULL);
- }
-
/* (non-Javadoc)
- * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#requestServiceInfo(org.eclipse.ecf.discovery.identity.IServiceID, int)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServices(org.eclipse.ecf.discovery.identity.IServiceTypeID)
*/
- public void requestServiceInfo(IServiceID service, int timeout) {
- if (jmdns != null) {
- if (service instanceof JMDNSServiceID) {
- final JMDNSServiceID svcID = (JMDNSServiceID) service;
- final JMDNSServiceTypeID typeID = (JMDNSServiceTypeID) svcID.getServiceTypeID();
- jmdns.requestServiceInfo(typeID.getInternal(), service.getServiceName(), timeout);
+ public IServiceInfo[] getServices(IServiceTypeID type) {
+ Assert.isNotNull(type);
+ List serviceInfos = new ArrayList();
+ synchronized (lock) {
+ if (serviceTypes.contains(type)) {
+ ServiceInfo[] infos = jmdns.list(type.getInternal());
+ for (int i = 0; i < infos.length; i++) {
+ try {
+ serviceInfos.add(createIServiceInfoFromServiceInfo(infos[i]));
+ } catch (Exception e) {
+ Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "getServices", e); //$NON-NLS-1$
+ }
+ }
}
+ return (IServiceInfo[]) serviceInfos.toArray(new IServiceInfo[] {});
}
}
- public void serviceAdded(ServiceEvent arg0) {
- if (jmdns != null) {
- try {
- fireServiceAdded(new ServiceContainerEvent(createIServiceInfoFromServiceEvent(arg0), getID()));
- } catch (final Exception e) {
- Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "serviceAdded", e); //$NON-NLS-1$
- }
- }
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServiceTypes()
+ */
+ public IServiceTypeID[] getServiceTypes() {
+ return (IServiceTypeID[]) serviceTypes.toArray(new IServiceTypeID[] {});
}
- public void serviceRemoved(ServiceEvent arg0) {
- if (jmdns != null) {
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#registerService(org.eclipse.ecf.discovery.IServiceInfo)
+ */
+ public void registerService(IServiceInfo serviceInfo) throws ECFException {
+ Assert.isNotNull(serviceInfo);
+ synchronized (lock) {
+ if (jmdns == null)
+ throw new ECFException(Messages.JMDNSDiscoveryContainer_DISCOVERY_NOT_INITIALIZED);
+ final ServiceInfo svcInfo = createServiceInfoFromIServiceInfo(serviceInfo);
+ checkServiceInfo(svcInfo);
try {
- fireServiceRemoved(new ServiceContainerEvent(createIServiceInfoFromServiceEvent(arg0), getID()));
- } catch (final Exception e) {
- Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "serviceRemoved", e); //$NON-NLS-1$
+ jmdns.registerService(svcInfo);
+ } catch (final IOException e) {
+ throw new ECFException(Messages.JMDNSDiscoveryContainer_EXCEPTION_REGISTER_SERVICE, e);
}
}
}
- public void serviceResolved(ServiceEvent arg0) {
- if (jmdns != null) {
- try {
- fireServiceResolved(new ServiceContainerEvent(createIServiceInfoFromServiceEvent(arg0), getID()));
- } catch (final Exception e) {
- Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "serviceResolved", e); //$NON-NLS-1$
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#unregisterService(org.eclipse.ecf.discovery.IServiceInfo)
+ */
+ public void unregisterService(IServiceInfo serviceInfo) {
+ Assert.isNotNull(serviceInfo);
+ synchronized (lock) {
+ if (jmdns != null) {
+ jmdns.unregisterService(createServiceInfoFromIServiceInfo(serviceInfo));
}
}
}
- public void serviceTypeAdded(ServiceEvent arg0) {
- if (jmdns != null) {
- try {
- fireServiceTypeAdded(new ServiceContainerEvent(createIServiceInfoFromServiceEvent(arg0), getID()));
- } catch (final Exception e) {
- Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "serviceTypeAdded", e); //$NON-NLS-1$
- }
- }
+ /**************************** JMDNS listeners ***********************************/
+
+ private void runInThread(Runnable runnable) {
+ new Thread(runnable).start();
}
/* (non-Javadoc)
- * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#unregisterService(org.eclipse.ecf.discovery.IServiceInfo)
+ * @see javax.jmdns.ServiceTypeListener#serviceTypeAdded(javax.jmdns.ServiceEvent)
*/
- public void unregisterService(IServiceInfo serviceInfo) {
- if (jmdns != null) {
- jmdns.unregisterService(createServiceInfoFromIServiceInfo(serviceInfo));
- }
+ public void serviceTypeAdded(final ServiceEvent arg0) {
+ Trace.trace(JMDNSPlugin.PLUGIN_ID, "serviceTypeAdded(" + arg0 + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ final IServiceTypeID serviceType = createServiceTypeID(arg0.getType());
+ runInThread(new Runnable() {
+ public void run() {
+ if (jmdns != null) {
+ try {
+ serviceTypes.add(serviceType);
+ jmdns.addServiceListener(arg0.getType(), JMDNSDiscoveryContainer.this);
+ fireTypeDiscovered(serviceType);
+ } catch (final Exception e) {
+ Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "serviceTypeAdded", e); //$NON-NLS-1$
+ }
+ }
+ }
+ });
+
+ }
+
+ void fireTypeDiscovered(final IServiceTypeID serviceType) {
+ fireServiceTypeDiscovered(new ServiceTypeContainerEvent(serviceType, getID()));
}
/* (non-Javadoc)
- * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServices(org.eclipse.ecf.discovery.identity.IServiceTypeID)
+ * @see javax.jmdns.ServiceListener#serviceAdded(javax.jmdns.ServiceEvent)
*/
- public IServiceInfo[] getServices(IServiceTypeID type) {
- return getServices(type.getName());
+ public void serviceAdded(final ServiceEvent arg0) {
+ Trace.trace(JMDNSPlugin.PLUGIN_ID, "serviceAdded(" + arg0 + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ runInThread(new Runnable() {
+ public void run() {
+ if (jmdns != null) {
+ jmdns.requestServiceInfo(arg0.getType(), arg0.getName(), DEFAULT_REQUEST_TIMEOUT);
+ }
+ }
+ });
}
/* (non-Javadoc)
- * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#registerServiceType(org.eclipse.ecf.discovery.identity.IServiceTypeID)
+ * @see javax.jmdns.ServiceListener#serviceRemoved(javax.jmdns.ServiceEvent)
*/
- public void registerServiceType(IServiceTypeID type) {
- if (type instanceof JMDNSServiceTypeID) {
- final JMDNSServiceTypeID typeID = (JMDNSServiceTypeID) type;
- registerServiceType(typeID.getInternal());
- }
+ public void serviceRemoved(final ServiceEvent arg0) {
+ Trace.trace(JMDNSPlugin.PLUGIN_ID, "serviceRemoved(" + arg0 + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ runInThread(new Runnable() {
+ public void run() {
+ if (jmdns != null) {
+ try {
+ fireUndiscovered(createIServiceInfoFromServiceInfo(arg0.getInfo()));
+ } catch (final Exception e) {
+ Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "serviceRemoved", e); //$NON-NLS-1$
+ }
+ }
+ }
+ });
+ }
+
+ void fireUndiscovered(IServiceInfo serviceInfo) {
+ fireServiceUndiscovered(new ServiceContainerEvent(serviceInfo, getID()));
}
/* (non-Javadoc)
- * @see org.eclipse.ecf.core.IContainer#getConnectedID()
+ * @see javax.jmdns.ServiceListener#serviceResolved(javax.jmdns.ServiceEvent)
*/
- public ID getConnectedID() {
- return this.targetID;
+ public void serviceResolved(final ServiceEvent arg0) {
+ Trace.trace(JMDNSPlugin.PLUGIN_ID, "serviceResolved(" + arg0 + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ runInThread(new Runnable() {
+ public void run() {
+ if (jmdns != null) {
+ try {
+ fireDiscovered(createIServiceInfoFromServiceInfo(arg0.getInfo()));
+ } catch (final Exception e) {
+ Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "serviceResolved", e); //$NON-NLS-1$
+ }
+ }
+ }
+ });
}
- private IServiceInfo createIServiceInfoFromServiceEvent(ServiceEvent event) {
- final ServiceID sID = createServiceID(event.getType(), event.getName());
- final ServiceInfo sinfo = event.getInfo();
- if (sinfo != null) {
- return createIServiceInfoFromServiceInfo(sinfo);
- }
- final IServiceInfo newInfo = new JMDNSServiceInfo(null, sID, -1, -1, -1, new ServiceProperties());
- return newInfo;
+ void fireDiscovered(IServiceInfo serviceInfo) {
+ fireServiceDiscovered(new ServiceContainerEvent(serviceInfo, getID()));
}
- private IServiceInfo createIServiceInfoFromServiceInfo(final ServiceInfo serviceInfo) {
+ /*******************************************/
+ private void checkServiceInfo(ServiceInfo serviceInfo) throws ECFException {
+ final String serviceName = serviceInfo.getName();
+ if (serviceName == null)
+ throw new ECFException(Messages.JMDNSDiscoveryContainer_SERVICE_NAME_NOT_NULL);
+ }
+
+ private IServiceTypeID createServiceTypeID(String type) {
+ return createServiceID(type, null).getServiceTypeID();
+ }
+
+ IServiceInfo createIServiceInfoFromServiceInfo(final ServiceInfo serviceInfo) throws Exception {
if (serviceInfo == null)
return null;
final ServiceID sID = createServiceID(serviceInfo.getType(), serviceInfo.getName());
@@ -253,43 +320,14 @@ public class JMDNSDiscoveryContainer extends AbstractDiscoveryContainerAdapter i
props.put(name, value);
}
final ServiceProperties svcProperties = new ServiceProperties(props);
- final IServiceProperties newProps = new IServiceProperties() {
- public Enumeration getPropertyNames() {
- return svcProperties.getPropertyNames();
- }
-
- public String getPropertyString(String name) {
- return svcProperties.getPropertyString(name);
- }
-
- public byte[] getPropertyBytes(String name) {
- return svcProperties.getPropertyBytes(name);
- }
-
- public Object getProperty(String name) {
- return svcProperties.getProperty(name);
- }
-
- public Object setProperty(String name, Object value) {
- return svcProperties.setProperty(name, value);
- }
-
- public Object setPropertyBytes(String name, byte[] value) {
- return svcProperties.setPropertyBytes(name, value);
- }
-
- public Object setPropertyString(String name, String value) {
- return svcProperties.setPropertyString(name, value);
- }
- };
- final IServiceInfo newInfo = new JMDNSServiceInfo(addr, sID, port, priority, weight, newProps);
+ final IServiceInfo newInfo = new JMDNSServiceInfo(addr, sID, port, priority, weight, svcProperties);
return newInfo;
}
private ServiceID createServiceID(String type, String name) {
ServiceID id = null;
try {
- id = (ServiceID) IDFactory.getDefault().createID(JMDNSNamespace.NAME, new Object[] {type, name});
+ id = (ServiceID) ServiceIDFactory.getDefault().createServiceID(getServicesNamespace(), type, name);
} catch (final IDCreateException e) {
// Should never happen
Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "createServiceID", e); //$NON-NLS-1$
@@ -312,7 +350,7 @@ public class JMDNSDiscoveryContainer extends AbstractDiscoveryContainerAdapter i
}
}
}
- final ServiceInfo si = new ServiceInfo(sID.getServiceTypeID().getName(), sID.getServiceName(), serviceInfo.getPort(), serviceInfo.getPriority(), serviceInfo.getWeight(), props);
+ final ServiceInfo si = new ServiceInfo(sID.getServiceTypeID().getInternal(), sID.getServiceName(), serviceInfo.getLocation().getPort(), serviceInfo.getPriority(), serviceInfo.getWeight(), props);
return si;
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSServiceInfo.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSServiceInfo.java
index ae1157f38..d970b13d8 100644
--- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSServiceInfo.java
+++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSServiceInfo.java
@@ -10,11 +10,11 @@
*****************************************************************************/
package org.eclipse.ecf.provider.jmdns.container;
-import java.net.InetAddress;
-
+import java.net.*;
import org.eclipse.ecf.discovery.IServiceProperties;
import org.eclipse.ecf.discovery.ServiceInfo;
import org.eclipse.ecf.discovery.identity.ServiceID;
+import org.eclipse.ecf.provider.jmdns.identity.JMDNSNamespace;
public class JMDNSServiceInfo extends ServiceInfo {
@@ -23,8 +23,8 @@ public class JMDNSServiceInfo extends ServiceInfo {
public static final String PROP_PATH_NAME = "path"; //$NON-NLS-1$
public static final String SLASH = "/"; //$NON-NLS-1$
- public JMDNSServiceInfo(InetAddress address, ServiceID id, int port, int priority, int weight, IServiceProperties props) {
- super(address, id, port, priority, weight, props);
+ public JMDNSServiceInfo(InetAddress address, ServiceID id, int port, int priority, int weight, IServiceProperties props) throws URISyntaxException {
+ super(new URI(JMDNSNamespace.JMDNS_SCHEME, null, address.getHostAddress(), port, null, null, null), id, priority, weight, props);
}
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSNamespace.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSNamespace.java
index 1f95c75ed..0f4aa9378 100644
--- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSNamespace.java
+++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSNamespace.java
@@ -10,19 +10,24 @@
*****************************************************************************/
package org.eclipse.ecf.provider.jmdns.identity;
-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.identity.*;
import org.eclipse.ecf.internal.provider.jmdns.Messages;
public class JMDNSNamespace extends Namespace {
private static final long serialVersionUID = -7220857203720337921L;
- private static final String JMDNS_SCHEME = "jmdns"; //$NON-NLS-1$
+ public static final String JMDNS_SCHEME = "jmdns"; //$NON-NLS-1$
public static final String NAME = "ecf.namespace.jmdns"; //$NON-NLS-1$
+ /**
+ *
+ */
+ public JMDNSNamespace() {
+ super();
+ }
+
/* (non-Javadoc)
* @see org.eclipse.ecf.core.identity.Namespace#createInstance(java.lang.Object[])
*/
@@ -31,13 +36,12 @@ public class JMDNSNamespace extends Namespace {
throw new IDCreateException(Messages.JMDNSNamespace_EXCEPTION_ID_WRONG_PARAM_COUNT);
}
String type = null;
- try {
+ if (parameters[0] instanceof JMDNSServiceTypeID) {
+ type = ((JMDNSServiceTypeID) parameters[0]).getInternal();
+ } else if (parameters[0] instanceof String) {
type = (String) parameters[0];
- if (type == null || type.equals("")) //$NON-NLS-1$
- throw new IDCreateException(Messages.JMDNSNamespace_EXCEPTION_ID_CREATE_SERVICE_TYPE_CANNOT_BE_EMPTY);
- } catch (final ClassCastException e) {
+ } else
throw new IDCreateException(Messages.JMDNSNamespace_EXCEPTION_TYPE_PARAM_NOT_STRING);
- }
final JMDNSServiceTypeID stid = new JMDNSServiceTypeID(this, type);
String name = null;
diff --git a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSServiceTypeID.java b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSServiceTypeID.java
index c7d1333dd..e4d532942 100644
--- a/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSServiceTypeID.java
+++ b/providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/identity/JMDNSServiceTypeID.java
@@ -29,6 +29,7 @@ public class JMDNSServiceTypeID extends ServiceTypeID {
super(namespace);
try {
parse(type);
+ createType();
} catch (final Exception e) {
throw new IDCreateException(NLS.bind(Messages.JMDNSServiceTypeID_EXCEPTION_INVALID_TYPE_ID, type));
}

Back to the top