private void assertConnectorMessageNotification(ServerNotificationHandler notificationHandler, MessageSource messageSource, ComponentLocation location, int action) { ArgumentCaptor<ConnectorMessageNotification> notificationCaptor = ArgumentCaptor.forClass(ConnectorMessageNotification.class); verify(notificationHandler).fireNotification(notificationCaptor.capture()); ConnectorMessageNotification notification = notificationCaptor.getValue(); assertThat(notification.getComponent(), is(messageSource)); assertThat(notification.getAction().getActionId(), is(action)); assertThat(notification.getComponent().getLocation(), is(location)); }
private void initMocks(ServerNotificationHandler notificationHandler) { when(notificationHandler.isNotificationEnabled(TestServerNotification.class)).thenReturn(true); when(notificationHandler.isNotificationEnabled(ConnectorMessageNotification.class)).thenReturn(true); }
public OptimisedNotificationHandler(ServerNotificationHandler delegate, Class<? extends Notification> type) { this.delegate = delegate; this.type = type; dynamic = delegate.isNotificationDynamic(); }
public void fireNotification(CoreEvent event, Exception e, int action) { if (notificationHandler != null && event != null && notificationHandler.isNotificationEnabled(PolicyNotification.class)) { notificationHandler.fireNotification(createNotification(event, e, action)); } }
@Override public boolean isListenerRegistered(NotificationListener listener) { return delegate.isListenerRegistered(listener); }
/** * Fires a {@link ConnectorMessageNotification} for the given arguments using the {@link ServerNotificationHandler} associated * to the given {@code event} and based on a {@link ComponentLocation}. * * @param source * @param event a {@link CoreEvent} * @param location the location of the component that generated the notification * @param action the action code for the notification */ public void fireNotification(Component source, CoreEvent event, ComponentLocation location, int action) { try { if (defaultNotificationHandler.isNotificationEnabled(notificationClass)) { defaultNotificationHandler .fireNotification(new ConnectorMessageNotification(createInfo(event, null, source), location, action)); } } catch (Exception e) { logger.warn("Could not fire notification. Action: " + action, e); } }
/** * Fires the given {@code notification} using the {@link #defaultNotificationHandler}. * * @param notification a {@link Notification} */ public void fireNotification(Notification notification) { defaultNotificationHandler.fireNotification(notification); }
/** * Checks if the {@link #defaultNotificationHandler} is enabled to fire instances of {@link #notificationClass}. * * @return {@code true} if {@link #defaultNotificationHandler} is enabled for {@link #notificationClass} */ public boolean isNotificationEnabled() { return defaultNotificationHandler.isNotificationEnabled(notificationClass); }
@Override public void fireNotification(Notification notification) { if (isNotificationEnabled(notification.getClass())) { delegate.fireNotification(notification); } } }
/** * This returns a very "conservative" value - it is true if the notification or any subclass would be accepted. So if it returns * false then you can be sure that there is no need to send the notification. On the other hand, if it returns true there is no * guarantee that the notification "really" will be dispatched to any listener. * * @param notfnClass Either the notification class being generated or some superclass * @return false if there is no need to dispatch the notification */ @Override public boolean isNotificationEnabled(Class<? extends Notification> notfnClass) { if ((!dynamic) && type.isAssignableFrom(notfnClass)) { if (enabled == null) { enabled = delegate.isNotificationEnabled(notfnClass); } return enabled; } else { return delegate.isNotificationEnabled(notfnClass); } }
private void assertConnectorMessageNotification(ServerNotificationHandler notificationHandler, MessageSource messageSource, ComponentLocation location, int action) { ArgumentCaptor<ConnectorMessageNotification> notificationCaptor = ArgumentCaptor.forClass(ConnectorMessageNotification.class); verify(notificationHandler).fireNotification(notificationCaptor.capture()); ConnectorMessageNotification notification = notificationCaptor.getValue(); assertThat(notification.getComponent(), is(messageSource)); assertThat(notification.getAction().getActionId(), is(action)); assertThat(notification.getComponent().getLocation(), is(location)); }
private void initMocks(ServerNotificationHandler notificationHandler) { when(notificationHandler.isNotificationEnabled(TestServerNotification.class)).thenReturn(true); when(notificationHandler.isNotificationEnabled(ConnectorMessageNotification.class)).thenReturn(true); }