summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-10-30 03:19:33 (EST)
committerEike Stepper2006-10-30 03:19:33 (EST)
commit83a95492d09d812d39fd2b578a7814615a0a57ee (patch)
tree2839bc8586833a4f7a8364cfbbd596ccb5451a68
parenteb098fcb074b0e34826d861db793df6b3cbe2d10 (diff)
downloadcdo-83a95492d09d812d39fd2b578a7814615a0a57ee.zip
cdo-83a95492d09d812d39fd2b578a7814615a0a57ee.tar.gz
cdo-83a95492d09d812d39fd2b578a7814615a0a57ee.tar.bz2
Operations & Maintenance
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMPlatform.java6
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMTraceHandlerEventImpl.java87
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMTracerImpl.java48
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTraceHandler.java20
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTracer.java25
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java9
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/RemoteTraceHandler.java30
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/RemoteTraceServer.java73
8 files changed, 228 insertions, 70 deletions
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMPlatform.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMPlatform.java
index 7b43fd0..c32801d 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMPlatform.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMPlatform.java
@@ -15,8 +15,8 @@ import org.eclipse.net4j.util.om.OMLogHandler;
import org.eclipse.net4j.util.om.OMLogger;
import org.eclipse.net4j.util.om.OMPlatform;
import org.eclipse.net4j.util.om.OMTraceHandler;
-import org.eclipse.net4j.util.om.OMTracer;
import org.eclipse.net4j.util.om.OMLogger.Level;
+import org.eclipse.net4j.util.om.OMTraceHandler.Event;
import org.eclipse.net4j.util.om.trace.ContextTracer;
import java.util.Map;
@@ -111,13 +111,13 @@ public abstract class AbstractOMPlatform implements OMPlatform
}
}
- protected void trace(OMTracer tracer, Class context, Object instance, String msg, Throwable t)
+ protected void trace(Event event)
{
for (OMTraceHandler traceHandler : traceHandlers)
{
try
{
- traceHandler.traced(tracer, context, instance, msg, t);
+ traceHandler.traced(event);
}
catch (Exception ex)
{
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMTraceHandlerEventImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMTraceHandlerEventImpl.java
new file mode 100644
index 0000000..330deba
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMTraceHandlerEventImpl.java
@@ -0,0 +1,87 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.internal.net4j.bundle;
+
+import org.eclipse.net4j.util.om.OMTraceHandler;
+import org.eclipse.net4j.util.om.OMTracer;
+
+import java.io.Serializable;
+
+/**
+ * @author Eike Stepper
+ */
+public class OMTraceHandlerEventImpl implements OMTraceHandler.Event, Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ protected long timeStamp;
+
+ protected OMTracer tracer;
+
+ protected Class context;
+
+ protected Object instance;
+
+ protected String message;
+
+ protected Throwable throwable;
+
+ public OMTraceHandlerEventImpl(OMTracer tracer, Class context, Object instance, String message,
+ Throwable throwable)
+ {
+ if (tracer == null)
+ {
+ throw new IllegalArgumentException("tracer == null");
+ }
+
+ if (context == null)
+ {
+ throw new IllegalArgumentException("context == null");
+ }
+
+ timeStamp = System.currentTimeMillis();
+ this.tracer = tracer;
+ this.context = context;
+ this.instance = instance;
+ this.message = message;
+ this.throwable = throwable;
+ }
+
+ public long getTimeStamp()
+ {
+ return timeStamp;
+ }
+
+ public OMTracer getTracer()
+ {
+ return tracer;
+ }
+
+ public Class getContext()
+ {
+ return context;
+ }
+
+ public Object getInstance()
+ {
+ return instance;
+ }
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ public Throwable getThrowable()
+ {
+ return throwable;
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMTracerImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMTracerImpl.java
index bd43e09..d36bfe7 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMTracerImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OMTracerImpl.java
@@ -12,6 +12,7 @@ package org.eclipse.internal.net4j.bundle;
import org.eclipse.net4j.util.om.OMBundle;
import org.eclipse.net4j.util.om.OMTracer;
+import org.eclipse.net4j.util.om.OMTraceHandler.Event;
import java.text.MessageFormat;
@@ -73,55 +74,62 @@ public class OMTracerImpl implements OMTracer
bundle.setDebugOption(fullName, enabled);
}
- public void trace(Class context, Object instance, String msg, Throwable t)
+ public void trace(Event event)
{
- ((AbstractOMPlatform)bundle.getPlatform()).trace(this, context, instance, msg, t);
+ ((AbstractOMPlatform)bundle.getPlatform()).trace(event);
}
- public void trace(Class context, Object instance, String msg)
+ public Event trace(Class context, Object instance, String msg, Throwable t)
{
- trace(context, instance, msg, (Throwable)null);
+ Event event = new OMTraceHandlerEventImpl(this, context, instance, msg, t);
+ trace(event);
+ return event;
}
- public void trace(Class context, Object instance, Throwable t)
+ public Event trace(Class context, Object instance, String msg)
{
- trace(context, instance, t.getLocalizedMessage(), t);
+ return trace(context, instance, msg, (Throwable)null);
}
- public void trace(Class context, Object instance, String pattern, Object... args)
+ public Event trace(Class context, Object instance, Throwable t)
{
- trace(context, instance, pattern, (Throwable)null, args);
+ return trace(context, instance, t.getLocalizedMessage(), t);
}
- public void trace(Class context, Object instance, String pattern, Throwable t, Object... args)
+ public Event trace(Class context, Object instance, String pattern, Object... args)
+ {
+ return trace(context, instance, pattern, (Throwable)null, args);
+ }
+
+ public Event trace(Class context, Object instance, String pattern, Throwable t, Object... args)
{
String msg = MessageFormat.format(pattern, args);
- trace(context, instance, msg, t);
+ return trace(context, instance, msg, t);
}
- public void trace(Class context, String pattern, Object... args)
+ public Event trace(Class context, String pattern, Object... args)
{
- trace(context, NO_INSTANCE, pattern, (Throwable)null, args);
+ return trace(context, NO_INSTANCE, pattern, (Throwable)null, args);
}
- public void trace(Class context, String pattern, Throwable t, Object... args)
+ public Event trace(Class context, String pattern, Throwable t, Object... args)
{
- trace(context, NO_INSTANCE, pattern, t, args);
+ return trace(context, NO_INSTANCE, pattern, t, args);
}
- public void trace(Class context, String msg, Throwable t)
+ public Event trace(Class context, String msg, Throwable t)
{
- trace(context, NO_INSTANCE, msg, t);
+ return trace(context, NO_INSTANCE, msg, t);
}
- public void trace(Class context, String msg)
+ public Event trace(Class context, String msg)
{
- trace(context, NO_INSTANCE, msg);
+ return trace(context, NO_INSTANCE, msg);
}
- public void trace(Class context, Throwable t)
+ public Event trace(Class context, Throwable t)
{
- trace(context, NO_INSTANCE, t);
+ return trace(context, NO_INSTANCE, t);
}
public OMTracer tracer(String name)
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTraceHandler.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTraceHandler.java
index bb69330..d18a7e3 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTraceHandler.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTraceHandler.java
@@ -15,5 +15,23 @@ package org.eclipse.net4j.util.om;
*/
public interface OMTraceHandler
{
- public void traced(OMTracer tracer, Class context, Object instance, String msg, Throwable t);
+ public void traced(Event event);
+
+ /**
+ * @author Eike Stepper
+ */
+ public interface Event
+ {
+ public long getTimeStamp();
+
+ public OMTracer getTracer();
+
+ public Class getContext();
+
+ public Object getInstance();
+
+ public String getMessage();
+
+ public Throwable getThrowable();
+ }
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTracer.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTracer.java
index bd6ddb4..b75f737 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTracer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/OMTracer.java
@@ -10,6 +10,8 @@
**************************************************************************/
package org.eclipse.net4j.util.om;
+import org.eclipse.net4j.util.om.OMTraceHandler.Event;
+
/**
* @author Eike Stepper
*/
@@ -29,26 +31,27 @@ public interface OMTracer
public void setEnabled(boolean enabled);
- public void trace(Class context, Object instance, String pattern, Object... args);
+ public void trace(Event traceRecord);
- public void trace(Class context, Object instance, String pattern, Throwable t, Object... args);
+ public Event trace(Class context, Object instance, String pattern, Object... args);
- public void trace(Class context, Object instance, String msg, Throwable t);
+ public Event trace(Class context, Object instance, String pattern, Throwable t, Object... args);
- public void trace(Class context, Object instance, String msg);
+ public Event trace(Class context, Object instance, String msg, Throwable t);
- public void trace(Class context, Object instance, Throwable t);
+ public Event trace(Class context, Object instance, String msg);
- public void trace(Class context, String pattern, Object... args);
+ public Event trace(Class context, Object instance, Throwable t);
- public void trace(Class context, String pattern, Throwable t, Object... args);
+ public Event trace(Class context, String pattern, Object... args);
- public void trace(Class context, String msg, Throwable t);
+ public Event trace(Class context, String pattern, Throwable t, Object... args);
- public void trace(Class context, String msg);
+ public Event trace(Class context, String msg, Throwable t);
- public void trace(Class context, Throwable t);
+ public Event trace(Class context, String msg);
- public OMTracer tracer(String name);
+ public Event trace(Class context, Throwable t);
+ public OMTracer tracer(String name);
} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java
index ea0feac..6bcc19e 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java
@@ -12,7 +12,6 @@ package org.eclipse.net4j.util.om.trace;
import org.eclipse.net4j.util.IOUtil;
import org.eclipse.net4j.util.om.OMTraceHandler;
-import org.eclipse.net4j.util.om.OMTracer;
import java.io.PrintStream;
@@ -35,12 +34,12 @@ public class PrintTraceHandler implements OMTraceHandler
this(IOUtil.OUT());
}
- public void traced(OMTracer tracer, Class context, Object instance, String msg, Throwable t)
+ public void traced(Event event)
{
- stream.println("[TRACE] " + msg); //$NON-NLS-1$
- if (t != null)
+ stream.println("[TRACE] " + event.getMessage()); //$NON-NLS-1$
+ if (event.getThrowable() != null)
{
- IOUtil.print(t, stream);
+ IOUtil.print(event.getThrowable(), stream);
}
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/RemoteTraceHandler.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/RemoteTraceHandler.java
index 06617ed..eef8d7a 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/RemoteTraceHandler.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/RemoteTraceHandler.java
@@ -13,7 +13,6 @@ package org.eclipse.net4j.util.om.trace;
import org.eclipse.net4j.util.IOUtil;
import org.eclipse.net4j.util.ReflectUtil;
import org.eclipse.net4j.util.om.OMTraceHandler;
-import org.eclipse.net4j.util.om.OMTracer;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -77,30 +76,31 @@ public class RemoteTraceHandler implements OMTraceHandler
}
}
- public void traced(OMTracer tracer, Class context, Object instance, String msg, Throwable t)
+ public void traced(Event event)
{
try
{
OutputStream outputStream = socket.getOutputStream();
DataOutputStream out = new DataOutputStream(outputStream);
+ out.writeLong(event.getTimeStamp());
writeUTF(out, agentID);
- writeUTF(out, tracer.getBundle().getBundleID());
- writeUTF(out, tracer.getFullName());
- writeUTF(out, context);
- writeUTF(out, ReflectUtil.getLabel(instance));
- writeUTF(out, msg);
- if (t == null)
+ writeUTF(out, event.getTracer().getBundle().getBundleID());
+ writeUTF(out, event.getTracer().getFullName());
+ writeUTF(out, event.getContext() == null ? "" : event.getContext().getName());
+ writeUTF(out, ReflectUtil.getLabel(event.getInstance()));
+ writeUTF(out, event.getMessage());
+ if (event.getThrowable() == null)
{
out.writeBoolean(false);
}
else
{
out.writeBoolean(true);
- String message = t.getMessage();
+ String message = event.getThrowable().getMessage();
writeUTF(out, message);
- StackTraceElement[] stackTrace = t.getStackTrace();
+ StackTraceElement[] stackTrace = event.getThrowable().getStackTrace();
int size = stackTrace == null ? 0 : stackTrace.length;
out.writeInt(size);
@@ -132,16 +132,6 @@ public class RemoteTraceHandler implements OMTraceHandler
out.writeUTF(str == null ? "" : str);
}
- private void writeUTF(DataOutputStream out, Object object) throws IOException
- {
- writeUTF(out, object == null ? "" : object.toString());
- }
-
- private void writeUTF(DataOutputStream out, Class clazz) throws IOException
- {
- writeUTF(out, clazz == null ? "" : clazz.getName());
- }
-
public static String uniqueAgentID()
{
try
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/RemoteTraceServer.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/RemoteTraceServer.java
index 2d0633f..66ee0fb 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/RemoteTraceServer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/RemoteTraceServer.java
@@ -19,6 +19,7 @@ import java.io.PrintStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
+import java.util.Date;
import java.util.EventObject;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -34,6 +35,8 @@ public class RemoteTraceServer
public static final int ANY_PORT = 0;
+ private static long lastEventID = 0;
+
private int port;
private String address;
@@ -142,13 +145,14 @@ public class RemoteTraceServer
protected void handleTrace(DataInputStream in) throws IOException
{
- Event event = new Event(this);
+ Event event = new Event();
+ event.timeStamp = in.readLong();
event.agentID = in.readUTF();
event.bundleID = in.readUTF();
event.tracerName = in.readUTF();
event.context = in.readUTF();
event.instance = in.readUTF();
- event.msg = in.readUTF();
+ event.message = in.readUTF();
if (in.readBoolean())
{
event.throwable = in.readUTF();
@@ -189,6 +193,10 @@ public class RemoteTraceServer
{
private static final long serialVersionUID = 1L;
+ private long id;
+
+ long timeStamp;
+
String agentID;
String bundleID;
@@ -199,15 +207,16 @@ public class RemoteTraceServer
String instance;
- String msg;
+ String message;
String throwable;
StackTraceElement[] stackTrace;
- Event(RemoteTraceServer source)
+ Event()
{
- super(source);
+ super(RemoteTraceServer.this);
+ id = ++lastEventID;
}
public RemoteTraceServer getRemoteTraceServer()
@@ -215,6 +224,16 @@ public class RemoteTraceServer
return (RemoteTraceServer)source;
}
+ public long getID()
+ {
+ return id;
+ }
+
+ public long getTimeStamp()
+ {
+ return timeStamp;
+ }
+
public String getAgentID()
{
return agentID;
@@ -235,9 +254,9 @@ public class RemoteTraceServer
return instance;
}
- public String getMsg()
+ public String getMessage()
{
- return msg;
+ return message;
}
public StackTraceElement[] getStackTrace()
@@ -274,8 +293,8 @@ public class RemoteTraceServer
builder.append(", instance=");
builder.append(instance);
- builder.append(", msg=");
- builder.append(msg);
+ builder.append(", message=");
+ builder.append(message);
builder.append(", throwable=");
builder.append(throwable);
@@ -286,6 +305,40 @@ public class RemoteTraceServer
builder.append("]");
return builder.toString();
}
+
+ public String getText(int index)
+ {
+ switch (index)
+ {
+ case 0:
+ return Long.toString(id);
+ case 1:
+ return new Date(timeStamp).toString();
+ case 2:
+ return agentID;
+ case 3:
+ return bundleID;
+ case 4:
+ return tracerName;
+ case 5:
+ return context;
+ case 6:
+ return instance;
+ case 7:
+ return message;
+ case 8:
+ return throwable;
+ }
+
+ throw new IllegalArgumentException("Invalid index: " + index);
+ }
+
+ public boolean hasError()
+ {
+ return throwable != null && throwable.length() != 0 //
+ || stackTrace != null && stackTrace.length != 0;
+ }
+
}
/**
@@ -319,7 +372,7 @@ public class RemoteTraceServer
stream.println(event.getTracerName());
stream.println(event.getContext());
stream.println(event.getInstance());
- stream.println(event.getMsg());
+ stream.println(event.getMessage());
String throwable = event.getThrowable();
if (throwable != null && throwable.length() != 0)