use of org.mule.runtime.api.lifecycle.Disposable in project mule by mulesoft.
the class RegistryMap method putAndLogWarningIfDuplicate.
public void putAndLogWarningIfDuplicate(String key, Object object) {
Lock writeLock = registryLock.writeLock();
try {
writeLock.lock();
final Object previousObject = registry.put(key, object);
if (previousObject != null && previousObject != object) {
if (previousObject instanceof Disposable) {
lostObjects.add(previousObject);
}
// registry.put(key, value) would overwrite a previous entity with the same name. Is this really what we want?
// Not sure whether to throw an exception or log a warning here.
// throw new RegistrationException("TransientRegistry already contains an object named '" + key + "'. The previous
// object would be overwritten.");
logger.warn("TransientRegistry already contains an object named '" + key + "'. The previous object will be overwritten.");
}
} finally {
writeLock.unlock();
}
}
use of org.mule.runtime.api.lifecycle.Disposable in project mule by mulesoft.
the class DefaultFlowTestCase method lifecycleOrder.
@Test
public void lifecycleOrder() throws MuleException {
Sink sink = mock(Sink.class, withSettings().extraInterfaces(Disposable.class));
Processor processor = mock(Processor.class, withSettings().extraInterfaces(Startable.class, Stoppable.class));
ProcessingStrategy processingStrategy = mock(ProcessingStrategy.class, withSettings().extraInterfaces(Startable.class, Stoppable.class));
when(processingStrategy.createSink(any(FlowConstruct.class), any(ReactiveProcessor.class))).thenReturn(sink);
flow = (DefaultFlow) Flow.builder(FLOW_NAME, muleContext).source(directInboundMessageSource).processors(singletonList(processor)).processingStrategyFactory((muleContext, s) -> processingStrategy).build();
flow.initialise();
flow.start();
InOrder inOrder = inOrder(sink, processor, processingStrategy);
inOrder.verify((Startable) processingStrategy).start();
inOrder.verify(processingStrategy).createSink(any(FlowConstruct.class), any(ReactiveProcessor.class));
inOrder.verify((Startable) processor).start();
flow.stop();
inOrder.verify((Disposable) sink).dispose();
inOrder.verify((Stoppable) processor).stop();
inOrder.verify((Stoppable) processingStrategy).stop();
}
Aggregations