Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Alexander Kuppe2010-08-06 07:56:26 +0000
committerMarkus Alexander Kuppe2010-08-06 07:56:26 +0000
commitbae0f51143a696ddba584250e813289d89324458 (patch)
tree6553914e0a26d352c983fad913e75e26587325c2
parent560f68196e60e4c1391eb45f4446afb613b40886 (diff)
downloadorg.eclipse.ecf-bae0f51143a696ddba584250e813289d89324458.tar.gz
org.eclipse.ecf-bae0f51143a696ddba584250e813289d89324458.tar.xz
org.eclipse.ecf-bae0f51143a696ddba584250e813289d89324458.zip
RESOLVED - bug 317920: [Discovery][DNS-SD] Add tracing capabilities to provider
https://bugs.eclipse.org/bugs/show_bug.cgi?id=317920
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.dnssd/.options19
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/Activator.java23
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/DnsSdDebugOptions.java27
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/DnsSdDiscoveryAdvertiser.java71
4 files changed, 100 insertions, 40 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.dnssd/.options b/providers/bundles/org.eclipse.ecf.provider.dnssd/.options
new file mode 100644
index 000000000..c82ad693a
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.dnssd/.options
@@ -0,0 +1,19 @@
+# Debugging options for the org.eclipse.ecf.provider.dnssd plug-in
+
+# Turn on general debugging for the org.eclipse.ecf.provider.dnssd plug-in
+org.eclipse.ecf.provider.dnssd/debug=false
+org.eclipse.ecf.provider.dnssd/debug/filter = *
+org.eclipse.ecf.provider.dnssd/debug/flag = false
+
+# Trace when exceptions are caught
+org.eclipse.ecf.provider.dnssd/debug/exceptions/catching=false
+# Trace when exceptions are thrown
+org.eclipse.ecf.provider.dnssd/debug/exceptions/throwing=false
+
+# Trace when methods are entered
+org.eclipse.ecf.provider.dnssd/debug/methods/entering=false
+# Trace when methods are exited
+org.eclipse.ecf.provider.dnssd/debug/methods/exiting=false
+
+org.eclipse.ecf.provider.dnssd/debug/methods/tracing=false
+org.eclipse.ecf.provider.dnssd/debug/methods/changing=false
diff --git a/providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/Activator.java b/providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/Activator.java
index 502e0a883..224314a68 100644
--- a/providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/Activator.java
+++ b/providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/Activator.java
@@ -32,6 +32,8 @@ import org.osgi.service.cm.ManagedServiceFactory;
public class Activator implements BundleActivator {
+ public static final String PLUGIN_ID = "org.eclipse.ecf.provider.dnssd";
+
private final Map serviceRegistrations = new HashMap();
private volatile BundleContext context;
private static final String NAME = "ecf.discovery.dnssd";
@@ -72,8 +74,8 @@ public class Activator implements BundleActivator {
*/
public void stop(BundleContext context) throws Exception {
if (serviceRegistrations != null) {
- for (Iterator itr = serviceRegistrations.values().iterator(); itr.hasNext();) {
- ServiceRegistration serviceRegistration = (ServiceRegistration) itr.next();
+ for (final Iterator itr = serviceRegistrations.values().iterator(); itr.hasNext();) {
+ final ServiceRegistration serviceRegistration = (ServiceRegistration) itr.next();
disposeServiceRegistration(serviceRegistration);
}
}
@@ -84,11 +86,11 @@ public class Activator implements BundleActivator {
* @param serviceRegistration disconnects the underlying IContainer and unregisters the service
*/
private void disposeServiceRegistration(ServiceRegistration serviceRegistration) {
- ServiceReference reference = serviceRegistration.getReference();
- IContainer aContainer = (DnsSdDiscoveryContainerAdapter) context.getService(reference);
+ final ServiceReference reference = serviceRegistration.getReference();
+ final IContainer aContainer = (DnsSdDiscoveryContainerAdapter) context.getService(reference);
serviceRegistration.unregister();
- IContainer container = (IContainer) aContainer.getAdapter(IContainer.class);
+ final IContainer container = (IContainer) aContainer.getAdapter(IContainer.class);
container.dispose();
container.disconnect();
}
@@ -154,15 +156,15 @@ public class Activator implements BundleActivator {
serviceRegistrations.put(pid, context.registerService(IDiscoveryLocator.class.getName(), adapter, props));
}
} catch (ContainerConnectException e) {
- throw new ConfigurationException("IDnsSdDiscoveryConstants properties", e.getLocalizedMessage(), e);
+ throw new ConfigurationException("IDnsSdDiscoveryConstants properties", e.getLocalizedMessage(), e); //$NON-NLS-1$
} catch (ClassCastException cce) {
- throw new ConfigurationException("IDnsSdDiscoveryConstants properties", cce.getLocalizedMessage(), cce);
+ throw new ConfigurationException("IDnsSdDiscoveryConstants properties", cce.getLocalizedMessage(), cce); //$NON-NLS-1$
} catch (InstantiationException e) {
// may never happen
- throw new ConfigurationException("InstantiationException", e.getLocalizedMessage(), e);
+ throw new ConfigurationException("InstantiationException", e.getLocalizedMessage(), e); //$NON-NLS-1$
} catch (IllegalAccessException e) {
// may never happen
- throw new ConfigurationException("IllegalAccessException", e.getLocalizedMessage(), e);
+ throw new ConfigurationException("IllegalAccessException", e.getLocalizedMessage(), e); //$NON-NLS-1$
}
}
}
@@ -171,7 +173,7 @@ public class Activator implements BundleActivator {
* @see org.osgi.service.cm.ManagedServiceFactory#deleted(java.lang.String)
*/
public void deleted(String pid) {
- ServiceRegistration serviceRegistration = (ServiceRegistration) serviceRegistrations.get(pid);
+ final ServiceRegistration serviceRegistration = (ServiceRegistration) serviceRegistrations.get(pid);
disposeServiceRegistration(serviceRegistration);
}
}
@@ -217,6 +219,7 @@ public class Activator implements BundleActivator {
*/
public void ungetService(Bundle bundle,
ServiceRegistration registration, Object service) {
+ // nop
}
}
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/DnsSdDebugOptions.java b/providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/DnsSdDebugOptions.java
new file mode 100644
index 000000000..06ad2866b
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/DnsSdDebugOptions.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Markus Alexander Kuppe.
+ * 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:
+ * Markus Alexander Kuppe (ecf-dev_eclipse.org <at> lemmster <dot> de) - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.dnssd;
+
+public interface DnsSdDebugOptions {
+
+ public static final String DEBUG = Activator.PLUGIN_ID + "/debug"; //$NON-NLS-1$
+
+ public static final String EXCEPTIONS_CATCHING = DEBUG + "/exceptions/catching"; //$NON-NLS-1$
+
+ public static final String EXCEPTIONS_THROWING = DEBUG + "/exceptions/throwing"; //$NON-NLS-1$
+
+ public static final String METHODS_ENTERING = DEBUG + "/methods/entering"; //$NON-NLS-1$
+
+ public static final String METHODS_EXITING = DEBUG + "/methods/exiting"; //$NON-NLS-1$
+
+ public static final String METHODS_TRACING = DEBUG + "/methods/tracing"; //$NON-NLS-1$
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/DnsSdDiscoveryAdvertiser.java b/providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/DnsSdDiscoveryAdvertiser.java
index 9e0702a82..d36dfe6ba 100644
--- a/providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/DnsSdDiscoveryAdvertiser.java
+++ b/providers/bundles/org.eclipse.ecf.provider.dnssd/src/org/eclipse/ecf/provider/dnssd/DnsSdDiscoveryAdvertiser.java
@@ -26,6 +26,7 @@ import org.eclipse.ecf.core.events.ContainerConnectingEvent;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.security.IConnectContext;
+import org.eclipse.ecf.core.util.Trace;
import org.eclipse.ecf.discovery.DiscoveryContainerConfig;
import org.eclipse.ecf.discovery.IServiceInfo;
import org.eclipse.ecf.discovery.identity.IServiceTypeID;
@@ -45,7 +46,7 @@ import org.xbill.DNS.Update;
public class DnsSdDiscoveryAdvertiser extends DnsSdDiscoveryContainerAdapter {
- private static final String _DNS_UPDATE = "_dns-update._udp.";
+ private static final String _DNS_UPDATE = "_dns-update._udp."; //$NON-NLS-1$
private static final boolean ADD = true;
private static final boolean REMOVE = false;
@@ -58,14 +59,16 @@ public class DnsSdDiscoveryAdvertiser extends DnsSdDiscoveryContainerAdapter {
/* (non-Javadoc)
* @see org.eclipse.ecf.provider.dnssd.DnsSdDiscoveryLocator#registerService(org.eclipse.ecf.discovery.IServiceInfo)
*/
- public void registerService(IServiceInfo serviceInfo) {
+ public void registerService(final IServiceInfo serviceInfo) {
+ Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "registerService(IServiceInfo serviceInfo)", "Registering service"); //$NON-NLS-1$ //$NON-NLS-2$
sendToServer(serviceInfo, ADD);
}
/* (non-Javadoc)
* @see org.eclipse.ecf.provider.dnssd.DnsSdDiscoveryLocator#unregisterService(org.eclipse.ecf.discovery.IServiceInfo)
*/
- public void unregisterService(IServiceInfo serviceInfo) {
+ public void unregisterService(final IServiceInfo serviceInfo) {
+ Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "unregisterService(IServiceInfo serviceInfo)", "Unregistering service"); //$NON-NLS-1$ //$NON-NLS-2$
sendToServer(serviceInfo, REMOVE);
}
@@ -73,7 +76,8 @@ public class DnsSdDiscoveryAdvertiser extends DnsSdDiscoveryContainerAdapter {
* @see org.eclipse.ecf.discovery.AbstractDiscoveryContainerAdapter#unregisterAllServices()
*/
public void unregisterAllServices() {
- throw new UnsupportedOperationException("Not yet implemented");
+ Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "unregisterAllServices()", "Unregistering all services"); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new UnsupportedOperationException("Not yet implemented"); //$NON-NLS-1$
}
/* (non-Javadoc)
@@ -81,45 +85,48 @@ public class DnsSdDiscoveryAdvertiser extends DnsSdDiscoveryContainerAdapter {
*/
public IServiceInfo[] purgeCache() {
// purge cache means renew resolver?
- throw new UnsupportedOperationException("Not yet implemented");
+ throw new UnsupportedOperationException("Not yet implemented"); //$NON-NLS-1$
}
/* (non-Javadoc)
* @see org.eclipse.ecf.provider.dnssd.DnsSdDiscoveryLocator#connect(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.core.security.IConnectContext)
*/
- public void connect(ID aTargetID, IConnectContext connectContext)
+ public void connect(final ID aTargetID, final IConnectContext connectContext)
throws ContainerConnectException {
- // connect can only be called once
- if (targetID != null || getConfig() == null) {
- throw new ContainerConnectException("Already connected");
- }
+ Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "connect(ID aTargetID, IConnectContext connectContext)", "connecting container"); //$NON-NLS-1$ //$NON-NLS-2$
- //TODO convert non DnsSdServiceTypeIDs into DSTIDs
- if(aTargetID == null) {
- targetID = new DnsSdServiceTypeID();
- } else {
- targetID = (DnsSdServiceTypeID) aTargetID;
- }
-
- // instantiate a default resolver
- if(resolver == null) {
- try {
- resolver = new SimpleResolver();
- resolver.setTCP(true);
- } catch (UnknownHostException e) {
- throw new ContainerConnectException(e);
- }
+ // connect can only be called once
+ if (targetID != null || getConfig() == null) {
+ throw new ContainerConnectException("Already connected");
+ }
+
+ //TODO convert non DnsSdServiceTypeIDs into DSTIDs
+ if(aTargetID == null) {
+ targetID = new DnsSdServiceTypeID();
+ } else {
+ targetID = (DnsSdServiceTypeID) aTargetID;
+ }
+
+ // instantiate a default resolver
+ if(resolver == null) {
+ try {
+ resolver = new SimpleResolver();
+ resolver.setTCP(true);
+ } catch (UnknownHostException e) {
+ throw new ContainerConnectException(e);
}
+ }
- // done setting up this provider, send event
- fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetID,
- connectContext));
- fireContainerEvent(new ContainerConnectedEvent(this.getID(), targetID));
+ // done setting up this provider, send event
+ fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetID,
+ connectContext));
+ fireContainerEvent(new ContainerConnectedEvent(this.getID(), targetID));
}
protected void sendToServer(final IServiceInfo serviceInfo, final boolean mode) {
Assert.isNotNull(serviceInfo);
+ Assert.isLegal(serviceInfo.getServiceID() instanceof DnsSdServiceTypeID);
final DnsSdServiceID serviceID = (DnsSdServiceID) serviceInfo.getServiceID();
try {
final Record srvRecord = serviceID.toSRVRecord(); // TYPE.SRV
@@ -199,6 +206,7 @@ public class DnsSdDiscoveryAdvertiser extends DnsSdDiscoveryContainerAdapter {
}
protected Collection getUpdateDomain(final Name zone) throws TextParseException {
+ Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "getUpdateDomain(Name zone)", "Getting update domain"); //$NON-NLS-1$ //$NON-NLS-2$
// query for special "_dns-update" SRV records which mark the server to use for dyndns
final Lookup query = new Lookup(_DNS_UPDATE + zone, Type.SRV);
// use the SRV record with the lowest priority/weight first
@@ -206,12 +214,14 @@ public class DnsSdDiscoveryAdvertiser extends DnsSdDiscoveryContainerAdapter {
// if no dedicated "_dns-update" server is configured, fall back to regular authoritative server
if(srvRecords.size() == 0) {
+ Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "getUpdateDomain(Name zone)", "Found no _dns-update SRV records in zone"); //$NON-NLS-1$ //$NON-NLS-2$
return getAuthoritativeNameServer(zone);
}
return srvRecords;
}
protected Collection getAuthoritativeNameServer(final Name zone) throws TextParseException {
+ Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "getAuthoritativeNameServer(Name zone)", "Trying to find authoritative name server"); //$NON-NLS-1$ //$NON-NLS-2$
final Set result = new HashSet();
final Name name = new Name(_DNS_UPDATE + zone);
@@ -246,7 +256,8 @@ public class DnsSdDiscoveryAdvertiser extends DnsSdDiscoveryContainerAdapter {
return result;
}
- protected String[] getRegistrationDomains(IServiceTypeID aServiceTypeId) {
+ protected String[] getRegistrationDomains(final IServiceTypeID aServiceTypeId) {
+ Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "getRegistrationDomains(IServiceTypeID aServiceTypeId)", "Getting registration domains"); //$NON-NLS-1$ //$NON-NLS-2$
final String[] rrs = new String[] {BnRDnsSdServiceTypeID.REG_DOMAINS, BnRDnsSdServiceTypeID.DEFAULT_REG_DOMAIN};
final Collection registrationDomains = getBrowsingOrRegistrationDomains(aServiceTypeId, rrs);
final String[] scopes = aServiceTypeId.getScopes();

Back to the top