@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof NotificationListener) { muleContext.getNotificationManager().addListener((NotificationListener) bean); } return bean; }
protected void registerDefaultListeners() { manager.addListenerSubscription(listener1, notification -> "id1".equals(notification.getResourceIdentifier())); manager.addListener(listener2); }
private void startMuleContext() throws MuleException, InterruptedException { final AtomicReference<Latch> contextStartedLatch = new AtomicReference<>(); contextStartedLatch.set(new Latch()); // Do not inline it, otherwise the type of the listener is lost final MuleContextNotificationListener<MuleContextNotification> listener = new MuleContextNotificationListener<MuleContextNotification>() { @Override public boolean isBlocking() { return false; } @Override public void onNotification(MuleContextNotification notification) { contextStartedLatch.get().countDown(); } }; muleContext.getNotificationManager().addListener(listener); muleContext.start(); contextStartedLatch.get().await(20, SECONDS); }
protected void registerDefaultListeners() { manager.addListenerSubscription(listener1, notification -> "id1".equals(notification.getResourceIdentifier())); manager.addListener(listener2); }
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof NotificationListener) { if (!muleContext.getNotificationManager().isListenerRegistered((NotificationListener) bean)) { muleContext.getNotificationManager().addListener((NotificationListener) bean); } } return bean; }
@Test public void testSyncNotificationException() { ServerNotificationManager manager = new ServerNotificationManager(); manager.setMuleContext(muleContext); manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); Notification notification = mock(CustomNotification.class); when(notification.isSynchronous()).thenReturn(true); NotificationListener notificationListener = mock(CustomNotificationListener.class); doThrow(new IllegalArgumentException()).when(notificationListener).onNotification(any(CustomNotification.class)); manager.addListener(notificationListener); manager.fireNotification(notification); verify(notificationListener, times(1)).onNotification(notification); }
private void setupMessageProcessorNotificationListener(List<MessageProcessorNotification> notificationList) { muleContext.getNotificationManager().addInterfaceToType(MessageProcessorNotificationListener.class, MessageProcessorNotification.class); muleContext.getNotificationManager().addListener((MessageProcessorNotificationListener) notification -> { notificationList.add((MessageProcessorNotification) notification); }); }
@Test public void testAsyncNotificationRejectedExecution() { MuleContext muleContext = mock(MuleContext.class); SchedulerService schedulerService = mock(SchedulerService.class); Scheduler scheduler = mock(Scheduler.class); when(muleContext.getSchedulerService()).thenReturn(schedulerService); when(schedulerService.cpuLightScheduler()).thenReturn(scheduler); when(scheduler.submit(any(Callable.class))).thenThrow(new RejectedExecutionException()); Notification notification = mock(CustomNotification.class); when(notification.isSynchronous()).thenReturn(false); NotificationListener notificationListener = mock(CustomNotificationListener.class); ServerNotificationManager manager = new ServerNotificationManager(); manager.setMuleContext(muleContext); manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); manager.addListener(notificationListener); manager.fireNotification(notification); verify(notificationListener, never()).onNotification(notification); }
@Test public void testSyncNotificationError() { ServerNotificationManager manager = new ServerNotificationManager(); manager.setMuleContext(muleContext); manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); Notification notification = mock(CustomNotification.class); when(notification.isSynchronous()).thenReturn(true); NotificationListener notificationListener = mock(CustomNotificationListener.class); doThrow(new LinkageError()).when(notificationListener).onNotification(any(CustomNotification.class)); manager.addListener(notificationListener); manager.fireNotification(notification); verify(notificationListener, times(1)).onNotification(notification); }
public MuleContext build() throws Exception { List<ConfigurationBuilder> builders = new ArrayList<>(3); ConfigurationBuilder cfgBuilder = getDomainBuilder(domainConfig); builders.add(new MockExtensionManagerConfigurationBuilder()); builders.add(cfgBuilder); testServicesConfigBuilder = new TestServicesConfigurationBuilder(); addBuilders(builders); final DefaultMuleConfiguration muleConfiguration = new DefaultMuleConfiguration(); if (contextId != null) { muleConfiguration.setId(contextId); } muleContextBuilder.setMuleConfiguration(muleConfiguration); DefaultMuleContextFactory muleContextFactory = new DefaultMuleContextFactory(); MuleContext domainContext = muleContextFactory.createMuleContext(builders, muleContextBuilder); domainContext.start(); MuleContextNotificationListener listener = notification -> { try { testServicesConfigBuilder.stopServices(); } catch (MuleException e) { throw new MuleRuntimeException(e); } }; domainContext.getNotificationManager().addListener(listener); return domainContext; }
protected void testAsyncCpuLightNotificationThreads(AtomicReference<Thread> beforeThread, AtomicReference<Thread> afterThread) throws Exception { muleContext.getNotificationManager().addInterfaceToType(MessageProcessorNotificationListener.class, MessageProcessorNotification.class); muleContext.getNotificationManager().addListener((MessageProcessorNotificationListener) notification -> { if (new IntegerAction(MESSAGE_PROCESSOR_PRE_INVOKE).equals(notification.getAction())) { beforeThread.set(currentThread()); } else if (new IntegerAction(MESSAGE_PROCESSOR_POST_INVOKE).equals(notification.getAction())) { afterThread.set(currentThread()); } }); flow = flowBuilder.get().processors(annotatedAsyncProcessor).build(); flow.initialise(); flow.start(); processFlow(testEvent()); }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof NotificationListener) { muleContext.getNotificationManager().addListener((NotificationListener) bean); } return bean; }
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof NotificationListener) { if (!muleContext.getNotificationManager().isListenerRegistered((NotificationListener) bean)) { muleContext.getNotificationManager().addListener((NotificationListener) bean); } } return bean; }
@Override public <N extends Notification> void registerListener(NotificationListener<N> listener) { requireNonNull(context.getNotificationManager(), serverNotificationManagerNotEnabled().getMessage()); context.getNotificationManager().addListener(listener); }
protected void handleNotificationListeners() { if (!muleContext.getNotificationManager().isDisposed()) { if (DefaultMuleConfiguration.isFlowTrace()) { muleContext.getNotificationManager().addListener(messageProcessorTextDebugger); muleContext.getNotificationManager().addListener(pipelineProcessorDebugger); } else { removeNotificationListeners(); } } }
@Test public void testSyncNotificationException() { ServerNotificationManager manager = new ServerNotificationManager(); manager.setMuleContext(muleContext); manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); Notification notification = mock(CustomNotification.class); when(notification.isSynchronous()).thenReturn(true); NotificationListener notificationListener = mock(CustomNotificationListener.class); doThrow(new IllegalArgumentException()).when(notificationListener).onNotification(any(CustomNotification.class)); manager.addListener(notificationListener); manager.fireNotification(notification); verify(notificationListener, times(1)).onNotification(notification); }
private void setupMessageProcessorNotificationListener(List<MessageProcessorNotification> notificationList) { muleContext.getNotificationManager().addInterfaceToType(MessageProcessorNotificationListener.class, MessageProcessorNotification.class); muleContext.getNotificationManager().addListener((MessageProcessorNotificationListener) notification -> { notificationList.add((MessageProcessorNotification) notification); }); }
@Test public void testAsyncNotificationRejectedExecution() { MuleContext muleContext = mock(MuleContext.class); SchedulerService schedulerService = mock(SchedulerService.class); Scheduler scheduler = mock(Scheduler.class); when(muleContext.getSchedulerService()).thenReturn(schedulerService); when(schedulerService.cpuLightScheduler()).thenReturn(scheduler); when(scheduler.submit(any(Callable.class))).thenThrow(new RejectedExecutionException()); Notification notification = mock(CustomNotification.class); when(notification.isSynchronous()).thenReturn(false); NotificationListener notificationListener = mock(CustomNotificationListener.class); ServerNotificationManager manager = new ServerNotificationManager(); manager.setMuleContext(muleContext); manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); manager.addListener(notificationListener); manager.fireNotification(notification); verify(notificationListener, never()).onNotification(notification); }
@Test public void testSyncNotificationError() { ServerNotificationManager manager = new ServerNotificationManager(); manager.setMuleContext(muleContext); manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); Notification notification = mock(CustomNotification.class); when(notification.isSynchronous()).thenReturn(true); NotificationListener notificationListener = mock(CustomNotificationListener.class); doThrow(new LinkageError()).when(notificationListener).onNotification(any(CustomNotification.class)); manager.addListener(notificationListener); manager.fireNotification(notification); verify(notificationListener, times(1)).onNotification(notification); }
protected void testAsyncCpuLightNotificationThreads(AtomicReference<Thread> beforeThread, AtomicReference<Thread> afterThread) throws Exception { muleContext.getNotificationManager().addInterfaceToType(MessageProcessorNotificationListener.class, MessageProcessorNotification.class); muleContext.getNotificationManager().addListener((MessageProcessorNotificationListener) notification -> { if (new IntegerAction(MESSAGE_PROCESSOR_PRE_INVOKE).equals(notification.getAction())) { beforeThread.set(currentThread()); } else if (new IntegerAction(MESSAGE_PROCESSOR_POST_INVOKE).equals(notification.getAction())) { afterThread.set(currentThread()); } }); flow = flowBuilder.get().processors(annotatedAsyncProcessor).build(); flow.initialise(); flow.start(); processFlow(testEvent()); }