guava icon indicating copy to clipboard operation
guava copied to clipboard

EventBus: Add extention to enable tracing

Open guaiziguo opened this issue 4 years ago • 2 comments

I'm using EventBus in in distributed system. I found that com.google.common.eventbus.Subscriber lost tracting infomation. Because com.google.common.eventbus.Subscriber#dispatchEvent is a final method, I can't extend it.

  /** Dispatches {@code event} to this subscriber using the proper executor. */
  final void dispatchEvent(final Object event) {
    executor.execute(
        new Runnable() {
          @Override
          public void run() {
            try {
              invokeSubscriberMethod(event);
            } catch (InvocationTargetException e) {
              bus.handleSubscriberException(e.getCause(), context(event));
            }
          }
        });
  }

I advice to add the TracerRunnable instead of Runnable, like this:

public abstract class TracerRunnable implements Runnable {

public abstract void doRun();

public abstract void before();

public abstract void after();

public void run() {

        before();
        try {
            doRun();
        }  finally {
           after();
        }
}

guaiziguo avatar Sep 09 '21 09:09 guaiziguo

@amalloy I would like to start working on this. If possible, please assign this to me.

bharathk005 avatar Sep 20 '21 22:09 bharathk005

@bharathk005 @amalloy how does the issue process?

guaiziguo avatar May 07 '22 02:05 guaiziguo