File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
src/main/java/org/scijava/event Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -91,12 +91,14 @@ public class DefaultEventService extends AbstractService implements
9191 @ Override
9292 public <E extends SciJavaEvent > void publish (final E e ) {
9393 e .setContext (getContext ());
94+ e .setCallingThread (Thread .currentThread ());
9495 eventBus .publishNow (e );
9596 }
9697
9798 @ Override
9899 public <E extends SciJavaEvent > void publishLater (final E e ) {
99100 e .setContext (getContext ());
101+ e .setCallingThread (Thread .currentThread ());
100102 eventBus .publishLater (e );
101103 }
102104
Original file line number Diff line number Diff line change 4040 */
4141public abstract class SciJavaEvent extends AbstractContextual {
4242
43+ /** Whether the event has been handled already. */
4344 private boolean consumed ;
4445
46+ /** The thread which published this event. */
47+ private Thread callingThread ;
48+
49+ /** The stack trace of the calling thread when the event was published. */
50+ private StackTraceElement [] stackTrace ;
51+
4552 // -- SciJavaEvent methods --
4653
4754 public boolean isConsumed () {
@@ -56,6 +63,25 @@ public void consume() {
5663 setConsumed (true );
5764 }
5865
66+ /** Gets the thread that published the event. */
67+ public Thread getCallingThread () {
68+ return callingThread ;
69+ }
70+
71+ /** Sets the thread that published the event. */
72+ public void setCallingThread (final Thread callingThread ) {
73+ this .callingThread = callingThread ;
74+ stackTrace = callingThread .getStackTrace ();
75+ }
76+
77+ /**
78+ * Gets the stack trace of the calling thread when the event was published.
79+ * This method is useful for debugging what triggered an event.
80+ */
81+ public StackTraceElement [] getStackTrace () {
82+ return stackTrace ;
83+ }
84+
5985 // Object methods --
6086
6187 @ Override
You can’t perform that action at this time.
0 commit comments