Search in sources :

Example 1 with Disposable

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();
    }
}
Also used : Disposable(org.mule.runtime.api.lifecycle.Disposable) Lock(java.util.concurrent.locks.Lock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 2 with Disposable

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();
}
Also used : Disposable(org.mule.runtime.api.lifecycle.Disposable) INITIAL_STATE_STOPPED(org.mule.runtime.core.api.construct.Flow.INITIAL_STATE_STOPPED) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) BiFunction(java.util.function.BiFunction) DefaultFlow(org.mule.runtime.core.internal.construct.DefaultFlowBuilder.DefaultFlow) Thread.currentThread(java.lang.Thread.currentThread) Collections.singletonList(java.util.Collections.singletonList) Assert.assertThat(org.junit.Assert.assertThat) Mockito.doThrow(org.mockito.Mockito.doThrow) Arrays.asList(java.util.Arrays.asList) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) Mono.just(reactor.core.publisher.Mono.just) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Assert.fail(org.junit.Assert.fail) Parameterized(org.junit.runners.Parameterized) Startable(org.mule.runtime.api.lifecycle.Startable) I18nMessage(org.mule.runtime.api.i18n.I18nMessage) StringAppendTransformer(org.mule.runtime.core.internal.transformer.simple.StringAppendTransformer) Collection(java.util.Collection) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) Message.of(org.mule.runtime.api.message.Message.of) Flow(org.mule.runtime.core.api.construct.Flow) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) ResponseMessageProcessorAdapter(org.mule.runtime.core.internal.processor.ResponseMessageProcessorAdapter) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Mockito.inOrder(org.mockito.Mockito.inOrder) Mockito.withSettings(org.mockito.Mockito.withSettings) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Mockito.mock(org.mockito.Mockito.mock) LifecycleTrackerProcessor(org.mule.tck.core.lifecycle.LifecycleTrackerProcessor) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CoreMatchers.not(org.hamcrest.CoreMatchers.not) MessageSource(org.mule.runtime.core.api.source.MessageSource) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Mockito.spy(org.mockito.Mockito.spy) Processor(org.mule.runtime.core.api.processor.Processor) BLOCKING(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.BLOCKING) ArrayList(java.util.ArrayList) DEFAULT_MAX_CONCURRENCY(org.mule.runtime.core.api.processor.strategy.AsyncProcessingStrategyFactory.DEFAULT_MAX_CONCURRENCY) MuleException(org.mule.runtime.api.exception.MuleException) ExpectedException.none(org.junit.rules.ExpectedException.none) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) Disposable(org.mule.runtime.api.lifecycle.Disposable) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) BlockingProcessingStrategyFactory(org.mule.runtime.core.internal.processor.strategy.BlockingProcessingStrategyFactory) InOrder(org.mockito.InOrder) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Sink(org.mule.runtime.core.api.processor.Sink) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) Startable(org.mule.runtime.api.lifecycle.Startable) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) LifecycleTrackerProcessor(org.mule.tck.core.lifecycle.LifecycleTrackerProcessor) Processor(org.mule.runtime.core.api.processor.Processor) InOrder(org.mockito.InOrder) Sink(org.mule.runtime.core.api.processor.Sink) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) Test(org.junit.Test)

Aggregations

Disposable (org.mule.runtime.api.lifecycle.Disposable)2 Thread.currentThread (java.lang.Thread.currentThread)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 BiFunction (java.util.function.BiFunction)1 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)1 CoreMatchers.not (org.hamcrest.CoreMatchers.not)1 CoreMatchers.nullValue (org.hamcrest.CoreMatchers.nullValue)1 CoreMatchers.sameInstance (org.hamcrest.CoreMatchers.sameInstance)1 After (org.junit.After)1 Assert.assertThat (org.junit.Assert.assertThat)1 Assert.fail (org.junit.Assert.fail)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1