use of org.mule.runtime.api.notification.IntegerAction in project mule by mulesoft.
the class ServerNotificationsTestCase method onNotification.
@Override
public void onNotification(Notification notification) {
if (new IntegerAction(CONTEXT_STOPPED).equals(notification.getAction())) {
managerStopped.set(true);
managerStoppedEvents.incrementAndGet();
}
}
use of org.mule.runtime.api.notification.IntegerAction in project mule by mulesoft.
the class TransactionNotificationsTestCase method testTransactionNotifications.
@Test
public void testTransactionNotifications() throws Exception {
final CountDownLatch latch = new CountDownLatch(3);
// the code is simple and deceptive :) The trick is this dummy transaction is handled by
// a global TransactionCoordination instance, which binds it to the current thread.
Transaction transaction = new DummyTransaction(muleContext);
((MuleContextWithRegistries) muleContext).getRegistry().lookupObject(NotificationListenerRegistry.class).registerListener(new TransactionNotificationListener<TransactionNotification>() {
@Override
public boolean isBlocking() {
return false;
}
@Override
public void onNotification(TransactionNotification notification) {
if (new IntegerAction(TRANSACTION_BEGAN).equals(notification.getAction())) {
assertEquals("begin", notification.getActionName());
latch.countDown();
} else if (new IntegerAction(TRANSACTION_COMMITTED).equals(notification.getAction())) {
assertEquals("commit", notification.getActionName());
latch.countDown();
} else if (new IntegerAction(TRANSACTION_ROLLEDBACK).equals(notification.getAction())) {
assertEquals("rollback", notification.getActionName());
latch.countDown();
}
}
}, notification -> transaction.getId().equals(notification.getResourceIdentifier()));
transaction.begin();
transaction.commit();
transaction.rollback();
// Wait for the notifcation event to be fired as they are queued
latch.await(2000, MILLISECONDS);
assertEquals("There are still some notifications left unfired.", 0, latch.getCount());
}
use of org.mule.runtime.api.notification.IntegerAction in project mule by mulesoft.
the class AbstractProcessingStrategyTestCase method testAsyncCpuLightNotificationThreads.
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());
}
use of org.mule.runtime.api.notification.IntegerAction in project mule by mulesoft.
the class DefaultExceptionStrategyTestCase method testExceptionNotifications.
// MULE-1627
@Test
public void testExceptionNotifications() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger notificationCount = new AtomicInteger(0);
((MuleContextWithRegistries) muleContext).getRegistry().lookupObject(NotificationListenerRegistry.class).registerListener((ExceptionNotificationListener) notification -> {
if (new IntegerAction(EXCEPTION_ACTION).equals(notification.getAction())) {
assertEquals("exception", notification.getActionName());
assertEquals("Wrong info type", TYPE_ERROR, notification.getType());
notificationCount.incrementAndGet();
latch.countDown();
}
});
// throwing exception
InstrumentedExceptionStrategy strategy = new InstrumentedExceptionStrategy(muleContext);
strategy.setAnnotations(singletonMap(LOCATION_KEY, TEST_CONNECTOR_LOCATION));
strategy.setMuleContext(muleContext);
strategy.setNotificationFirer(((MuleContextWithRegistries) muleContext).getRegistry().lookupObject(NotificationDispatcher.class));
strategy.handleException(new IllegalArgumentException("boom"));
// Wait for the notifcation event to be fired as they are queue
latch.await(2000, MILLISECONDS);
assertEquals(1, notificationCount.get());
}
use of org.mule.runtime.api.notification.IntegerAction in project mule by mulesoft.
the class DefaultMuleApplication method setMuleContext.
private void setMuleContext(final MuleContext muleContext, Registry registry) {
statusListener = new MuleContextNotificationListener<MuleContextNotification>() {
@Override
public boolean isBlocking() {
return false;
}
@Override
public void onNotification(MuleContextNotification notification) {
Action action = notification.getAction();
if (new IntegerAction(CONTEXT_INITIALISED).equals(action) || new IntegerAction(CONTEXT_STARTED).equals(action) || new IntegerAction(CONTEXT_STOPPED).equals(action) || new IntegerAction(CONTEXT_DISPOSED).equals(action)) {
updateStatusFor(muleContext.getLifecycleManager().getCurrentPhase());
}
}
};
notificationRegistrer = registry.lookupByType(NotificationListenerRegistry.class).get();
notificationRegistrer.registerListener(statusListener);
}
Aggregations