Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2015-04-09 23:08:34 +0000
committerslewis2015-04-09 23:08:34 +0000
commit231a2d3ccbc2652a0a2265f4f698f65972c66635 (patch)
tree25fcf4ded7274e775e69b709ba0aaa9882bbad2a
parentcb72e77c437ab84550cb78bd720a32d945a9974b (diff)
downloadorg.eclipse.ecf-231a2d3ccbc2652a0a2265f4f698f65972c66635.tar.gz
org.eclipse.ecf-231a2d3ccbc2652a0a2265f4f698f65972c66635.tar.xz
org.eclipse.ecf-231a2d3ccbc2652a0a2265f4f698f65972c66635.zip
Added DebugRemoteServiceAdminListener to simplify testing and debugging.
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/.settings/.api_filters15
-rw-r--r--osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DebugRemoteServiceAdminListener.java165
2 files changed, 180 insertions, 0 deletions
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/.settings/.api_filters b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/.settings/.api_filters
index 4c2802ce9..7f563fe40 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/.settings/.api_filters
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/.settings/.api_filters
@@ -123,6 +123,21 @@
</message_arguments>
</filter>
</resource>
+ <resource path="src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DebugRemoteServiceAdminListener.java" type="org.eclipse.ecf.osgi.services.remoteserviceadmin.DebugRemoteServiceAdminListener">
+ <filter id="576725006">
+ <message_arguments>
+ <message_argument value="RemoteServiceAdminListener"/>
+ <message_argument value="DebugRemoteServiceAdminListener"/>
+ </message_arguments>
+ </filter>
+ <filter id="643846161">
+ <message_arguments>
+ <message_argument value="RemoteServiceAdminEvent"/>
+ <message_argument value="DebugRemoteServiceAdminListener"/>
+ <message_argument value="remoteAdminEvent(RemoteServiceAdminEvent)"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DiscoveredEndpointDescription.java" type="org.eclipse.ecf.osgi.services.remoteserviceadmin.DiscoveredEndpointDescription">
<filter id="643842064">
<message_arguments>
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DebugRemoteServiceAdminListener.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DebugRemoteServiceAdminListener.java
new file mode 100644
index 000000000..103323f76
--- /dev/null
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/DebugRemoteServiceAdminListener.java
@@ -0,0 +1,165 @@
+package org.eclipse.ecf.osgi.services.remoteserviceadmin;
+
+import java.io.PrintWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.DebugOptions;
+import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.LogUtility;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener;
+
+/**
+ * @since 4.3
+ */
+public class DebugRemoteServiceAdminListener implements
+ RemoteServiceAdminListener {
+
+ public static final SimpleDateFormat sdf = new SimpleDateFormat(
+ "HH:mm:ss.SSS"); //$NON-NLS-1$
+
+ public static final int EXPORT_MASK = RemoteServiceAdminEvent.EXPORT_ERROR
+ | RemoteServiceAdminEvent.EXPORT_REGISTRATION
+ | RemoteServiceAdminEvent.EXPORT_UNREGISTRATION
+ | RemoteServiceAdminEvent.EXPORT_WARNING;
+ public static final int IMPORT_MASK = RemoteServiceAdminEvent.IMPORT_ERROR
+ | RemoteServiceAdminEvent.IMPORT_REGISTRATION
+ | RemoteServiceAdminEvent.IMPORT_UNREGISTRATION
+ | RemoteServiceAdminEvent.IMPORT_WARNING;
+
+ public static final int ALL_MASK = EXPORT_MASK | IMPORT_MASK;
+
+ //
+ private final PrintWriter writer;
+ // default is all events
+ private int eventMask = ALL_MASK;
+ private boolean writeEndpoint;
+ private EndpointDescriptionWriter edWriter;
+
+ public DebugRemoteServiceAdminListener(PrintWriter writer, int eventMask,
+ boolean writeEndpoint) {
+ Assert.isNotNull(writer);
+ this.writer = writer;
+ this.eventMask = eventMask;
+ this.writeEndpoint = writeEndpoint;
+ if (this.writeEndpoint)
+ edWriter = new EndpointDescriptionWriter();
+ }
+
+ public DebugRemoteServiceAdminListener(PrintWriter writer, int mask) {
+ this(writer, mask, true);
+ }
+
+ public DebugRemoteServiceAdminListener(PrintWriter writer) {
+ this(writer, ALL_MASK);
+ }
+
+ public DebugRemoteServiceAdminListener(int mask, boolean writeEndpoint) {
+ this(new PrintWriter(System.out), mask, writeEndpoint);
+ }
+
+ public DebugRemoteServiceAdminListener(int mask) {
+ this(mask, true);
+ }
+
+ public DebugRemoteServiceAdminListener() {
+ this(ALL_MASK);
+ }
+
+ public int getEventMask() {
+ return this.eventMask;
+ }
+
+ public void setEventMask(int eventMask) {
+ this.eventMask = eventMask;
+ }
+
+ protected boolean allow(int type, int mask) {
+ return (type & mask) > 0;
+ }
+
+ public void remoteAdminEvent(RemoteServiceAdminEvent event) {
+ if (!(event instanceof RemoteServiceAdmin.RemoteServiceAdminEvent))
+ return;
+ if (allow(event.getType(), this.eventMask))
+ printEvent((RemoteServiceAdmin.RemoteServiceAdminEvent) event);
+ }
+
+ private String eventTypeToString(int type) {
+ switch (type) {
+ case RemoteServiceAdminEvent.EXPORT_ERROR:
+ return "EXPORT_ERROR"; //$NON-NLS-1$
+ case RemoteServiceAdminEvent.EXPORT_REGISTRATION:
+ return "EXPORT_REGISTRATION"; //$NON-NLS-1$
+ case RemoteServiceAdminEvent.EXPORT_UNREGISTRATION:
+ return "EXPORT_UNREGISTRATION"; //$NON-NLS-1$
+ case RemoteServiceAdminEvent.EXPORT_UPDATE:
+ return "EXPORT_UPDATE"; //$NON-NLS-1$
+ case RemoteServiceAdminEvent.EXPORT_WARNING:
+ return "EXPORT_WARNING"; //$NON-NLS-1$
+ case RemoteServiceAdminEvent.IMPORT_ERROR:
+ return "IMPORT_ERROR"; //$NON-NLS-1$
+ case RemoteServiceAdminEvent.IMPORT_REGISTRATION:
+ return "IMPORT_REGISTRATION"; //$NON-NLS-1$
+ case RemoteServiceAdminEvent.IMPORT_UNREGISTRATION:
+ return "IMPORT_UNREGISTRATION"; //$NON-NLS-1$
+ case RemoteServiceAdminEvent.IMPORT_UPDATE:
+ return "IMPORT_UPDATE"; //$NON-NLS-1$
+ case RemoteServiceAdminEvent.IMPORT_WARNING:
+ return "IMPORT_WARNING"; //$NON-NLS-1$
+ default:
+ return "UNKNOWN"; //$NON-NLS-1$
+ }
+ }
+
+ protected void printEvent(RemoteServiceAdmin.RemoteServiceAdminEvent event) {
+ ID cID = event.getContainerID();
+ StringBuffer buf = new StringBuffer(sdf.format(new Date())).append(";") //$NON-NLS-1$
+ .append(eventTypeToString(event.getType()));
+ switch (event.getType()) {
+ case RemoteServiceAdminEvent.EXPORT_REGISTRATION:
+ case RemoteServiceAdminEvent.EXPORT_UNREGISTRATION:
+ case RemoteServiceAdminEvent.EXPORT_UPDATE:
+ case RemoteServiceAdminEvent.EXPORT_WARNING:
+ writer.println(buf
+ .append(";exportedSR=").append(event.getExportReference().getExportedService()).append(";cID=").append(cID).toString()); //$NON-NLS-1$ //$NON-NLS-2$
+ writeEndpoint(event.getEndpointDescription());
+ break;
+ case RemoteServiceAdminEvent.IMPORT_REGISTRATION:
+ case RemoteServiceAdminEvent.IMPORT_UNREGISTRATION:
+ case RemoteServiceAdminEvent.IMPORT_UPDATE:
+ case RemoteServiceAdminEvent.IMPORT_WARNING:
+ writer.println(buf
+ .append(";importedSR=").append(event.getImportReference().getImportedService()).append(";cID=").append(cID).toString()); //$NON-NLS-1$ //$NON-NLS-2$
+ writeEndpoint(event.getEndpointDescription());
+ break;
+ case RemoteServiceAdminEvent.EXPORT_ERROR:
+ case RemoteServiceAdminEvent.IMPORT_ERROR:
+ writer.println(buf.toString());
+ Throwable t = event.getException();
+ if (t != null)
+ t.printStackTrace(this.writer);
+ break;
+
+ }
+ writer.flush();
+ }
+
+ protected void writeEndpoint(EndpointDescription endpointDescription) {
+ try {
+ if (this.writeEndpoint) {
+ this.writer.println("--Endpoint Description---"); //$NON-NLS-1$
+ this.edWriter.writeEndpointDescription(this.writer,
+ endpointDescription);
+ this.writer.println("---End Endpoint Description"); //$NON-NLS-1$
+ }
+ } catch (Exception e) {
+ LogUtility
+ .logError(
+ "writeEndpoint", DebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "Could not write endpoint description", e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+}

Back to the top