private static String message(SubscriberExceptionContext context) { Method method = context.getSubscriberMethod(); return "Exception thrown by subscriber method " + method.getName() + '(' + method.getParameterTypes()[0].getName() + ')' + " on subscriber " + context.getSubscriber() + " when dispatching event: " + context.getEvent(); } }
import com.google.common.eventbus.SubscriberExceptionContext; import com.google.common.eventbus.SubscriberExceptionHandler; class CustomExceptionHandler implements SubscriberExceptionHandler { @Override public void handleException(Throwable exception, SubscriberExceptionContext context) { System.out.println("Handler '"+context.getSubscriber()+"' could not handle '"+context.getEvent().getClass().getName()+"'["+context.getEvent()+"]: " + exception.getMessage()); } }
private static String message(SubscriberExceptionContext context) { Method method = context.getSubscriberMethod(); return "Exception thrown by subscriber method " + method.getName() + '(' + method.getParameterTypes()[0].getName() + ')' + " on subscriber " + context.getSubscriber() + " when dispatching event: " + context.getEvent(); } }
private static String message(SubscriberExceptionContext context) { Method method = context.getSubscriberMethod(); return "Exception thrown by subscriber method " + method.getName() + '(' + method.getParameterTypes()[0].getName() + ')' + " on subscriber " + context.getSubscriber() + " when dispatching event: " + context.getEvent(); } }
public void testSubscriberThrowsException() throws Exception { final RecordingSubscriberExceptionHandler handler = new RecordingSubscriberExceptionHandler(); final EventBus eventBus = new EventBus(handler); final RuntimeException exception = new RuntimeException("but culottes have a tendancy to ride up!"); final Object subscriber = new Object() { @Subscribe public void throwExceptionOn(String message) { throw exception; } }; eventBus.register(subscriber); eventBus.post(EVENT); assertEquals("Cause should be available.", exception, handler.exception); assertEquals("EventBus should be available.", eventBus, handler.context.getEventBus()); assertEquals("Event should be available.", EVENT, handler.context.getEvent()); assertEquals("Subscriber should be available.", subscriber, handler.context.getSubscriber()); assertEquals( "Method should be available.", subscriber.getClass().getMethod("throwExceptionOn", String.class), handler.context.getSubscriberMethod()); }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { logger.error(exception, "Could not dispatch event: " + context.getSubscriber() + " to " + context.getSubscriberMethod(), exception.getCause()); } });
@Override public void handleException(final Throwable exception, final SubscriberExceptionContext context) { logger.error( "Could not dispatch event: {} to {}", context.getSubscriber(), context.getSubscriberMethod(), exception ); } }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { logger.error("Could not dispatch event: " + context.getSubscriber() + " to " + context.getSubscriberMethod(), exception); } }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { logger.log(Level.SEVERE, "Could not dispatch event: " + context.getSubscriber() + " to " + context.getSubscriberMethod(), exception.getCause()); } }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { logger.log(Level.SEVERE, "Could not dispatch event: " + context.getSubscriber() + " to " + context.getSubscriberMethod(), exception.getCause()); } }
@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); } }
private static String message(SubscriberExceptionContext context) { Method method = context.getSubscriberMethod(); return "Exception thrown by subscriber method " + method.getName() + '(' + method.getParameterTypes()[0].getName() + ')' + " on subscriber " + context.getSubscriber() + " when dispatching event: " + context.getEvent(); } }
private static String message(SubscriberExceptionContext context) { Method method = context.getSubscriberMethod(); return "Exception thrown by subscriber method " + method.getName() + '(' + method.getParameterTypes()[0].getName() + ')' + " on subscriber " + context.getSubscriber() + " when dispatching event: " + context.getEvent(); } }
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { Method method = context.getSubscriberMethod(); Output.get().logError("&c&l!!! Event Exception!!!"); Output.get().logError( "&cException thrown by subscriber method " + method.getName() + '(' + method .getParameterTypes()[0].getName() + ')' + " on listener " + context.getSubscriber() .getClass().getName()); Output.get().logError("&6Here's the stack trace:", exception); Output.get().logError( "&6Report this entire message to the developers if you can't solve the problem yourself."); Output.get().logError("&c&l!!! Event Exception!!!"); }
@Override public void onSessionInitiated(BindingAwareBroker.ProviderContext providerContext) { LOG.info("starting vpp renderer"); MountPointService mountService = Preconditions.checkNotNull(providerContext.getSALService(MountPointService.class)); MountedDataBrokerProvider mountDataProvider = new MountedDataBrokerProvider(mountService); vppNodeManager = new VppNodeManager(dataBroker, providerContext); EventBus dtoEventBus = new EventBus((exception, context) -> LOG.error("Could not dispatch event: {} to {}", context.getSubscriber(), context.getSubscriberMethod(), exception)); interfaceManager = new InterfaceManager(mountDataProvider, dataBroker, NETCONF_WORKER); dtoEventBus.register(interfaceManager); ForwardingManager fwManager = new ForwardingManager(interfaceManager, new BridgeDomainManagerImpl(dataBroker), dataBroker); vppRendererPolicyManager = new VppRendererPolicyManager(fwManager, dataBroker); dtoEventBus.register(vppRendererPolicyManager); vppNodeListener = new VppNodeListener(dataBroker, vppNodeManager, dtoEventBus); vppEndpointListener = new VppEndpointListener(dataBroker, dtoEventBus); rendererPolicyListener = new RendererPolicyListener(dataBroker, dtoEventBus); registerToRendererManager(); }
public void testSubscriberThrowsException() throws Exception{ final RecordingSubscriberExceptionHandler handler = new RecordingSubscriberExceptionHandler(); final EventBus eventBus = new EventBus(handler); final RuntimeException exception = new RuntimeException("but culottes have a tendancy to ride up!"); final Object subscriber = new Object() { @Subscribe public void throwExceptionOn(String message) { throw exception; } }; eventBus.register(subscriber); eventBus.post(EVENT); assertEquals("Cause should be available.", exception, handler.exception); assertEquals("EventBus should be available.", eventBus, handler.context.getEventBus()); assertEquals("Event should be available.", EVENT, handler.context.getEvent()); assertEquals("Subscriber should be available.", subscriber, handler.context.getSubscriber()); assertEquals("Method should be available.", subscriber.getClass().getMethod("throwExceptionOn", String.class), handler.context.getSubscriberMethod()); }