Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-03-27 07:20:34 +0000
committerslewis2008-03-27 07:20:34 +0000
commit2809c9f87622bc2956bb26483c4cee2c0559f343 (patch)
treeb0cf2a18e1a89db6a225b2a7f382c7dff2358abf /providers/bundles/org.eclipse.ecf.provider.jmdns
parenta85575c766acd92c4a84bd7f90e44c7759958dff (diff)
downloadorg.eclipse.ecf-2809c9f87622bc2956bb26483c4cee2c0559f343.tar.gz
org.eclipse.ecf-2809c9f87622bc2956bb26483c4cee2c0559f343.tar.xz
org.eclipse.ecf-2809c9f87622bc2956bb26483c4cee2c0559f343.zip
Fixes for jmdns synchronization issues.
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.jmdns')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/META-INF/MANIFEST.MF1
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/JMDNSPlugin.java41
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/Messages.java2
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/internal/provider/jmdns/messages.properties2
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.jmdns/src/org/eclipse/ecf/provider/jmdns/container/JMDNSDiscoveryContainer.java62
5 files changed, 93 insertions, 15 deletions
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 2a6ef21b1..47b4d2b8e 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
@@ -18,5 +18,6 @@ Export-Package: org.eclipse.ecf.internal.provider.jmdns;x-internal:=true,
org.eclipse.ecf.provider.jmdns.identity
Import-Package: org.eclipse.osgi.util;version="1.1.0",
org.osgi.framework;version="1.3.0",
+ org.osgi.service.log;version="1.3.0",
org.osgi.util.tracker;version="1.3.2"
Bundle-ActivationPolicy: lazy
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 277fdfe8c..36b2fce2b 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,8 +12,10 @@ package org.eclipse.ecf.internal.provider.jmdns;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.ecf.core.util.PlatformHelper;
+import org.eclipse.ecf.core.util.SystemLogService;
import org.eclipse.ecf.discovery.service.IDiscoveryService;
import org.osgi.framework.*;
+import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
/**
@@ -41,6 +43,10 @@ public class JMDNSPlugin implements BundleActivator {
private ServiceRegistration serviceRegistration;
+ private ServiceTracker logServiceTracker = null;
+
+ private LogService logService = null;
+
public IAdapterManager getAdapterManager() {
// First, try to get the adapter manager via
if (adapterManagerTracker == null) {
@@ -96,6 +102,11 @@ public class JMDNSPlugin implements BundleActivator {
discoveryTracker.close();
discoveryTracker = null;
}
+ if (logServiceTracker != null) {
+ logServiceTracker.close();
+ logServiceTracker = null;
+ logService = null;
+ }
this.context = ctxt;
plugin = null;
}
@@ -107,4 +118,34 @@ public class JMDNSPlugin implements BundleActivator {
return plugin;
}
+ /**
+ * @param string
+ * @param t
+ */
+ public void logException(String string, Throwable t) {
+ getLogService();
+ if (logService != null)
+ logService.log(LogService.LOG_ERROR, string, t);
+ }
+
+ protected LogService getLogService() {
+ if (logServiceTracker == null) {
+ logServiceTracker = new ServiceTracker(this.context, LogService.class.getName(), null);
+ logServiceTracker.open();
+ }
+ logService = (LogService) logServiceTracker.getService();
+ if (logService == null)
+ logService = new SystemLogService(PLUGIN_ID);
+ return logService;
+ }
+
+ /**
+ * @param errorString
+ */
+ public void logError(String errorString) {
+ getLogService();
+ if (logService != null)
+ logService.log(LogService.LOG_ERROR, errorString);
+ }
+
}
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 f2f217aef..fd92121a0 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
@@ -28,6 +28,8 @@ public class Messages extends NLS {
public static String JMDNSDiscoveryContainer_EXCEPTION_REGISTER_SERVICE;
public static String JMDNSDiscoveryContainer_EXCEPTION_SERVICEINFO_INVALID;
public static String JMDNSDiscoveryContainer_JMDNS_LOCAL_SUFFIX;
+ public static String JMDNSDiscoveryContainer_NO_JMDNS_SERVICE_TYPE;
+ public static String JMDNSDiscoveryContainer_NO_SERVICE_TYPE;
public static String JMDNSDiscoveryContainer_SERVICE_NAME_NOT_NULL;
public static String JMDNSNamespace_EXCEPTION_ID_CREATE_SERVICE_TYPE_CANNOT_BE_EMPTY;
public static String JMDNSNamespace_EXCEPTION_ID_PARAM_2_WRONG_TYPE;
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 14c40a2a3..7954bd90a 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
@@ -8,6 +8,8 @@ JMDNSServiceTypeID_EXCEPTION_INVALID_TYPE_ID={0} is not a valid JMDNSServiceType
JMDNSDiscoveryContainer_DISCOVERY_NOT_INITIALIZED=Discovery not initialized. May need to connect.
JMDNSDiscoveryContainer_EXCEPTION_REGISTER_SERVICE=registerService
JMDNSDiscoveryContainer_EXCEPTION_SERVICEINFO_INVALID=ServiceInfo is invalid.
+JMDNSDiscoveryContainer_NO_JMDNS_SERVICE_TYPE=No JMDNS service type for event {0}
+JMDNSDiscoveryContainer_NO_SERVICE_TYPE=No service type for event {0} and JMDNS service type {1}
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
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 a89136937..f3c42233b 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
@@ -29,6 +29,7 @@ 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.JMDNSNamespace;
+import org.eclipse.osgi.util.NLS;
public class JMDNSDiscoveryContainer extends AbstractDiscoveryContainerAdapter implements IDiscoveryService, ServiceListener, ServiceTypeListener {
@@ -52,8 +53,9 @@ public class JMDNSDiscoveryContainer extends AbstractDiscoveryContainerAdapter i
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$
+ Assert.isNotNull(addr);
intf = addr;
- serviceTypes = Collections.synchronizedList(new ArrayList());
+ serviceTypes = new ArrayList();
}
/****************** IContainer methods **************************/
@@ -124,6 +126,7 @@ public class JMDNSDiscoveryContainer extends AbstractDiscoveryContainerAdapter i
protected void handleRuntimeException(Throwable t) {
// Nothing to do except log
+ JMDNSPlugin.getDefault().logException("handleRuntimeException", t); //$NON-NLS-1$
}
/* (non-Javadoc)
@@ -139,6 +142,7 @@ public class JMDNSDiscoveryContainer extends AbstractDiscoveryContainerAdapter i
queue.close();
notificationThread = null;
this.targetID = null;
+ serviceTypes.clear();
fireContainerEvent(new ContainerDisconnectedEvent(this.getID(), connectedID));
}
}
@@ -173,7 +177,9 @@ public class JMDNSDiscoveryContainer extends AbstractDiscoveryContainerAdapter i
IServiceTypeID[] serviceTypeArray = getServiceTypes();
List results = new ArrayList();
for (int i = 0; i < serviceTypeArray.length; i++) {
- results.addAll(Arrays.asList(getServices(serviceTypeArray[i])));
+ IServiceTypeID stid = serviceTypeArray[i];
+ if (stid != null)
+ results.addAll(Arrays.asList(getServices(stid)));
}
return (IServiceInfo[]) results.toArray(new IServiceInfo[] {});
}
@@ -204,7 +210,9 @@ public class JMDNSDiscoveryContainer extends AbstractDiscoveryContainerAdapter i
* @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServiceTypes()
*/
public IServiceTypeID[] getServiceTypes() {
- return (IServiceTypeID[]) serviceTypes.toArray(new IServiceTypeID[] {});
+ synchronized (lock) {
+ return (IServiceTypeID[]) serviceTypes.toArray(new IServiceTypeID[] {});
+ }
}
/* (non-Javadoc)
@@ -212,13 +220,17 @@ public class JMDNSDiscoveryContainer extends AbstractDiscoveryContainerAdapter i
*/
public void registerService(IServiceInfo serviceInfo) throws ECFException {
Assert.isNotNull(serviceInfo);
+ final ServiceInfo svcInfo = createServiceInfoFromIServiceInfo(serviceInfo);
+ checkServiceInfo(svcInfo);
+ JmDNS localJmDNS = null;
synchronized (lock) {
if (jmdns == null)
throw new ECFException(Messages.JMDNSDiscoveryContainer_DISCOVERY_NOT_INITIALIZED);
- final ServiceInfo svcInfo = createServiceInfoFromIServiceInfo(serviceInfo);
- checkServiceInfo(svcInfo);
+ localJmDNS = jmdns;
+ }
+ if (localJmDNS != null) {
try {
- jmdns.registerService(svcInfo);
+ localJmDNS.registerService(svcInfo);
} catch (final IOException e) {
throw new ECFException(Messages.JMDNSDiscoveryContainer_EXCEPTION_REGISTER_SERVICE, e);
}
@@ -230,10 +242,13 @@ public class JMDNSDiscoveryContainer extends AbstractDiscoveryContainerAdapter i
*/
public void unregisterService(IServiceInfo serviceInfo) {
Assert.isNotNull(serviceInfo);
+ final ServiceInfo si = createServiceInfoFromIServiceInfo(serviceInfo);
+ JmDNS localJmDNS = null;
synchronized (lock) {
- if (jmdns != null) {
- jmdns.unregisterService(createServiceInfoFromIServiceInfo(serviceInfo));
- }
+ localJmDNS = jmdns;
+ }
+ if (localJmDNS != null) {
+ localJmDNS.unregisterService(si);
}
}
@@ -248,21 +263,38 @@ public class JMDNSDiscoveryContainer extends AbstractDiscoveryContainerAdapter i
localQueue.enqueue(runnable);
}
+ private void logError(String errorString) {
+ JMDNSPlugin.getDefault().logError(errorString);
+ }
+
/* (non-Javadoc)
* @see javax.jmdns.ServiceTypeListener#serviceTypeAdded(javax.jmdns.ServiceEvent)
*/
public void serviceTypeAdded(final ServiceEvent arg0) {
- Trace.trace(JMDNSPlugin.PLUGIN_ID, "serviceTypeAdded(" + arg0 + ")"); //$NON-NLS-1$ //$NON-NLS-2$
- String st = arg0.getType();
- if (st == null)
+ final String st = arg0.getType();
+ if (st == null) {
+ logError(NLS.bind(Messages.JMDNSDiscoveryContainer_NO_JMDNS_SERVICE_TYPE, arg0));
return;
+ }
final IServiceTypeID serviceType = createServiceTypeID(st);
+ if (serviceType == null) {
+ logError(NLS.bind(Messages.JMDNSDiscoveryContainer_NO_SERVICE_TYPE, arg0, st));
+ return;
+ }
+ // Else run in thread
runInThread(new Runnable() {
public void run() {
- if (jmdns != null) {
- try {
+ boolean added = false;
+ // No accesses to serviceTypes while we're adding a discovered service type
+ synchronized (lock) {
+ if (jmdns != null) {
serviceTypes.add(serviceType);
- jmdns.addServiceListener(arg0.getType(), JMDNSDiscoveryContainer.this);
+ jmdns.addServiceListener(st, JMDNSDiscoveryContainer.this);
+ added = true;
+ }
+ }
+ if (added) {
+ try {
fireTypeDiscovered(serviceType);
} catch (final Exception e) {
Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "serviceTypeAdded", e); //$NON-NLS-1$

Back to the top