com.google.common.eventbus.SubscriberExceptionContext Java Examples

The following examples show how to use com.google.common.eventbus.SubscriberExceptionContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultAsyncEventBus.java    From j360-dubbo-app-all with Apache License 2.0 6 votes vote down vote up
public DefaultAsyncEventBus() {
    this.blockingQueue = new LinkedBlockingQueue<>(1000);
    this.executor = new ThreadPoolExecutor(30, 100, 3, TimeUnit.SECONDS, blockingQueue, ThreadPoolUtil.buildThreadFactory("DefaultAsyncEventBus", true), new ThreadPoolExecutor.AbortPolicy());

    this.eventBus = new AsyncEventBus(executor, new SubscriberExceptionHandler() {
        @Override
        public void handleException(Throwable exception, SubscriberExceptionContext context) {
            log.error("异步消息队列异常: [subscribeMethod={}, event={} ]",context.getSubscriberMethod(), context.getEvent().toString(),exception);
        }
    });

}
 
Example #2
Source File: TekuDefaultExceptionHandler.java    From teku with Apache License 2.0 5 votes vote down vote up
@Override
public void handleException(final Throwable exception, final SubscriberExceptionContext context) {
  handleException(
      exception,
      "event '"
          + context.getEvent().getClass().getName()
          + "'"
          + " in handler '"
          + context.getSubscriber().getClass().getName()
          + "'"
          + " (method  '"
          + context.getSubscriberMethod().getName()
          + "')");
}
 
Example #3
Source File: TekuDefaultExceptionHandlerTest.java    From teku with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setupBus() {
  lenient()
      .doAnswer(
          invocation -> {
            handledException.complete(invocation.getArgument(1));
            logLevelFuture.complete(Level.WARN);
            return null;
          })
      .when(log)
      .specificationFailure(anyString(), any(Exception.class));
  lenient()
      .doAnswer(
          invocation -> {
            handledException.complete(invocation.getArgument(1));
            logLevelFuture.complete(Level.FATAL);
            return null;
          })
      .when(log)
      .unexpectedFailure(anyString(), any(Exception.class));

  final var exceptionHandlerRecordingWrapper =
      new SubscriberExceptionHandler() {
        private final SubscriberExceptionHandler delegate = new TekuDefaultExceptionHandler(log);

        @Override
        public void handleException(
            final Throwable exception, final SubscriberExceptionContext context) {
          try {
            delegate.handleException(exception, context);
          } catch (final RuntimeException thrown) {
            unhandledExceptionFuture.complete(thrown);
            throw thrown;
          }
        }
      };

  bus = new AsyncEventBus(executor, exceptionHandlerRecordingWrapper);
}
 
Example #4
Source File: EventExceptionHandler.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void handleException(Throwable exception, SubscriberExceptionContext context) {
    loggers.get(context.getSubscriber().getClass()).log(
        Level.SEVERE,
        "Exception dispatching " + context.getEvent().getClass().getName() +
        " to " + context.getSubscriber().getClass().getName() +
        "#" + context.getSubscriberMethod().getName(),
        exception
    );
}
 
Example #5
Source File: DefaultEventBus.java    From j360-dubbo-app-all with Apache License 2.0 5 votes vote down vote up
public DefaultEventBus() {
    this.eventBus = new EventBus(new SubscriberExceptionHandler() {
        @Override
        public void handleException(Throwable exception, SubscriberExceptionContext context) {
            log.error("同步消息总线异常: [subscribeMethod={}, event={} ]",context.getSubscriberMethod(),context.getEvent().toString(),exception);
            throw new ServiceException(ErrorCode.BUS_ERROR.getErrorCode(), ErrorCode.BUS_ERROR.getErrorMsg(), exception);
        }
    });
}
 
Example #6
Source File: DefaultAsyncEventBus.java    From j360-dubbo-app-all with Apache License 2.0 5 votes vote down vote up
public DefaultAsyncEventBus() {
    this.blockingQueue = new LinkedBlockingQueue<>(1000);
    this.executor = new ThreadPoolExecutor(30, 100, 3, TimeUnit.SECONDS, blockingQueue, ThreadPoolUtil.buildThreadFactory("DefaultAsyncEventBus", true), new ThreadPoolExecutor.AbortPolicy());

    this.eventBus = new AsyncEventBus(executor, new SubscriberExceptionHandler() {
        @Override
        public void handleException(Throwable exception, SubscriberExceptionContext context) {
            log.error("异步消息队列异常: [subscribeMethod={}, event={} ]",context.getSubscriberMethod(), context.getEvent().toString(),exception);
        }
    });

}
 
Example #7
Source File: BuildIntegrationTestCase.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void handleException(Throwable exception, SubscriberExceptionContext context) {
  System.err.println("subscriber exception: ");
  exception.printStackTrace();
  if (this.exception == null) {
    this.exception = exception;
  }
}
 
Example #8
Source File: Slf4jSubscriberExceptionHandler.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void handleException(final Throwable exception, final SubscriberExceptionContext context) {
  logger.error("Could not dispatch event {} to subscriber {} method [{}]",
      context.getEvent(), context.getSubscriber(), context.getSubscriberMethod(), exception);
}
 
Example #9
Source File: ManagedEventBus.java    From jesos with Apache License 2.0 4 votes vote down vote up
@Override
public void handleException(final Throwable e, final SubscriberExceptionContext context)
{
    LOG.error(e, "Could not call %s/%s on bus %s", context.getSubscriber().getClass().getSimpleName(), context.getSubscriberMethod().getName(), name);
}
 
Example #10
Source File: RethrowingExceptionHandler.java    From OpenRTS with MIT License 4 votes vote down vote up
@Override
public void handleException(Throwable exception, SubscriberExceptionContext context) {
	throw new TechnicalException(exception);
}