@Test public void testNotification() throws ClassNotFoundException { registerDefaultEvents(); registerDefaultListeners(); assertNoListenersNotified(); manager.notifyListeners(new Event1(), (listener, nfn) -> listener.onNotification(nfn)); assertNoListenersNotified(); manager.notifyListeners(new SubEvent1(), (listener, nfn) -> listener.onNotification(nfn)); assertNoListenersNotified(); manager.notifyListeners(new Event1("id1"), (listener, nfn) -> listener.onNotification(nfn)); assertNoListenersNotified(); manager.notifyListeners(new SubSubEvent1("id1"), (listener, nfn) -> listener.onNotification(nfn)); assertTrue(listener1.isNotified()); assertFalse(listener2.isNotified()); manager.notifyListeners(new Event2(), (listener, nfn) -> listener.onNotification(nfn)); assertTrue(listener1.isNotified()); assertTrue(listener2.isNotified()); }
@Override public void fireNotification(Notification notification) { if (disposed.get()) { logger.warn("Notification not enqueued after ServerNotificationManager disposal: " + notification); return; } activeFires.incrementAndGet(); try { if (notification instanceof AbstractServerNotification) { ((AbstractServerNotification) notification).setServerId(muleContext.getId()); } if (notification.isSynchronous()) { notifyListeners(notification, (listener, nfn) -> listener.onNotification(nfn)); } else { notifyListeners(notification, (listener, nfn) -> { if (listener.isBlocking()) { notificationsIoScheduler.submit(() -> listener.onNotification(nfn)); } else { notificationsLiteScheduler.submit(() -> listener.onNotification(nfn)); } }); } } finally { if (0 == activeFires.decrementAndGet() && disposed.get()) { disposeLatch.countDown(); } } }
@Test public void testNotification() throws ClassNotFoundException { registerDefaultEvents(); registerDefaultListeners(); assertNoListenersNotified(); manager.notifyListeners(new Event1(), (listener, nfn) -> listener.onNotification(nfn)); assertNoListenersNotified(); manager.notifyListeners(new SubEvent1(), (listener, nfn) -> listener.onNotification(nfn)); assertNoListenersNotified(); manager.notifyListeners(new Event1("id1"), (listener, nfn) -> listener.onNotification(nfn)); assertNoListenersNotified(); manager.notifyListeners(new SubSubEvent1("id1"), (listener, nfn) -> listener.onNotification(nfn)); assertTrue(listener1.isNotified()); assertFalse(listener2.isNotified()); manager.notifyListeners(new Event2(), (listener, nfn) -> listener.onNotification(nfn)); assertTrue(listener1.isNotified()); assertTrue(listener2.isNotified()); }