Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-11-18 04:05:19 -0500
committerEike Stepper2012-11-18 04:05:19 -0500
commit971f6d3a263c9bf5af11d4e3f69b12a6b898d480 (patch)
treeb5f8ea2e5f960ef4f6971d8c130efb46de93226b
parent1d8be84210fe0f56af7663e34d3b5bfb165d385b (diff)
downloadcdo-971f6d3a263c9bf5af11d4e3f69b12a6b898d480.tar.gz
cdo-971f6d3a263c9bf5af11d4e3f69b12a6b898d480.tar.xz
cdo-971f6d3a263c9bf5af11d4e3f69b12a6b898d480.zip
Add ThrowableEventAdapter
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/Notifier.java8
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/ThrowableEventAdapter.java83
2 files changed, 91 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/Notifier.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/Notifier.java
index 06057d4597..531771ad13 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/Notifier.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/Notifier.java
@@ -13,6 +13,7 @@ package org.eclipse.net4j.util.event;
import org.eclipse.net4j.internal.util.bundle.OM;
import org.eclipse.net4j.util.CheckUtil;
import org.eclipse.net4j.util.collection.ConcurrentArray;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
import java.util.concurrent.ExecutorService;
@@ -24,6 +25,8 @@ import java.util.concurrent.ExecutorService;
*/
public class Notifier implements INotifier
{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, Notifier.class);
+
private ConcurrentArray<IListener> listeners = new ConcurrentArray<IListener>()
{
@Override
@@ -117,6 +120,11 @@ public class Notifier implements INotifier
*/
protected void fireThrowable(Throwable throwable)
{
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(throwable);
+ }
+
IListener[] listeners = getListeners();
if (listeners.length != 0)
{
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/ThrowableEventAdapter.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/ThrowableEventAdapter.java
new file mode 100644
index 0000000000..9b67f4c0aa
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/ThrowableEventAdapter.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * 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.net4j.util.event;
+
+import java.io.PrintStream;
+
+/**
+ * A {@link IListener listener} that dispatches throwable {@link ThrowableEvent events} to methods that can be
+ * overridden by extenders.
+ *
+ * @author Eike Stepper
+ * @apiviz.exclude
+ * @since 3.3
+ */
+public class ThrowableEventAdapter implements IListener
+{
+ public ThrowableEventAdapter()
+ {
+ }
+
+ public final void notifyEvent(IEvent event)
+ {
+ if (event instanceof ThrowableEvent)
+ {
+ ThrowableEvent e = (ThrowableEvent)event;
+ notifyLifecycleEvent(e);
+ }
+ else
+ {
+ notifyOtherEvent(event);
+ }
+ }
+
+ protected void notifyLifecycleEvent(ThrowableEvent event)
+ {
+ onThrowable(event.getSource(), event.getThrowable());
+ }
+
+ protected void notifyOtherEvent(IEvent event)
+ {
+ }
+
+ protected void onThrowable(INotifier source, Throwable t)
+ {
+ }
+
+ /**
+ * Prints the stack traces of throwable {@link ThrowableEvent events} to a {@link PrintStream}.
+ *
+ * @author Eike Stepper
+ * @apiviz.exclude
+ */
+ public static class ToPrintStream extends ThrowableEventAdapter
+ {
+ public static final ToPrintStream CONSOLE = new ToPrintStream(System.out);
+
+ private final PrintStream out;
+
+ public ToPrintStream(PrintStream out)
+ {
+ this.out = out;
+ }
+
+ public final PrintStream getOut()
+ {
+ return out;
+ }
+
+ @Override
+ protected void onThrowable(INotifier source, Throwable t)
+ {
+ t.printStackTrace(out);
+ }
+ }
+}

Back to the top