Search in sources :

Example 1 with LifecycleException

use of org.mule.runtime.api.lifecycle.LifecycleException in project mule by mulesoft.

the class RegistryLifecycleManager method doApplyLifecycle.

private void doApplyLifecycle(Object object, String phase) throws LifecycleException {
    LifecyclePhase lp = phases.get(phase);
    lifecycleInterceptor.beforePhaseExecution(lp, object);
    try {
        lp.applyLifecycle(object);
        lifecycleInterceptor.afterPhaseExecution(lp, object, empty());
    } catch (Exception e) {
        lifecycleInterceptor.afterPhaseExecution(lp, object, of(e));
        throw e;
    }
}
Also used : LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) ConnectException(org.mule.runtime.core.api.connector.ConnectException) NotInLifecyclePhase(org.mule.runtime.core.internal.lifecycle.phases.NotInLifecyclePhase) LifecyclePhase(org.mule.runtime.core.internal.lifecycle.phases.LifecyclePhase)

Example 2 with LifecycleException

use of org.mule.runtime.api.lifecycle.LifecycleException in project mule by mulesoft.

the class MuleContextDisposePhase method applyLifecycle.

@Override
public void applyLifecycle(Object o) throws LifecycleException {
    if (o == null) {
        return;
    }
    if (ignoreType(o.getClass())) {
        return;
    }
    // retain default Lifecycle behaviour
    try {
        super.applyLifecycle(o);
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn("Failed to dispose object " + o, e);
        }
    }
    List<AnnotationMetaData> annos = AnnotationUtils.getMethodAnnotations(o.getClass(), PreDestroy.class);
    if (annos.size() == 0) {
        return;
    }
    // Note that the registry has a processor that validates that there is at most one {@link PostConstruct} annotation
    // per object and that the method conforms to a lifecycle method
    AnnotationMetaData anno = annos.get(0);
    try {
        ((Method) anno.getMember()).invoke(o);
    } catch (Exception e) {
        throw new LifecycleException(CoreMessages.failedToInvokeLifecycle((anno == null ? "null" : anno.getMember().getName()), o), e, this);
    }
}
Also used : LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) Method(java.lang.reflect.Method) AnnotationMetaData(org.mule.runtime.core.privileged.util.annotation.AnnotationMetaData) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException)

Example 3 with LifecycleException

use of org.mule.runtime.api.lifecycle.LifecycleException in project mule by mulesoft.

the class DefaultFlowTestCase method testFailStartingMessageSourceOnLifecycleShouldStopStartedPipelineProcesses.

@Test
public void testFailStartingMessageSourceOnLifecycleShouldStopStartedPipelineProcesses() throws Exception {
    // Need to start mule context to have endpoints started during flow start
    muleContext.start();
    MessageSource mockMessageSource = mock(MessageSource.class, withSettings().extraInterfaces(Startable.class, Stoppable.class));
    doThrow(new LifecycleException(mock(I18nMessage.class), mockMessageSource)).when(((Startable) mockMessageSource)).start();
    final List<Processor> processors = new ArrayList<>(flow.getProcessors());
    Processor mockMessageProcessor = spy(new LifecycleTrackerProcessor());
    processors.add(mockMessageProcessor);
    after();
    flow = (DefaultFlow) Flow.builder(FLOW_NAME, muleContext).source(mockMessageSource).processors(processors).build();
    flow.initialise();
    try {
        flow.start();
        fail();
    } catch (LifecycleException e) {
    }
    verify((Startable) mockMessageProcessor, times(1)).start();
    verify((Stoppable) mockMessageProcessor, times(1)).stop();
    verify((Startable) mockMessageSource, times(1)).start();
    verify((Stoppable) mockMessageSource, times(1)).stop();
}
Also used : Startable(org.mule.runtime.api.lifecycle.Startable) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) 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) LifecycleTrackerProcessor(org.mule.tck.core.lifecycle.LifecycleTrackerProcessor) ArrayList(java.util.ArrayList) MessageSource(org.mule.runtime.core.api.source.MessageSource) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) Test(org.junit.Test)

Example 4 with LifecycleException

use of org.mule.runtime.api.lifecycle.LifecycleException in project mule by mulesoft.

the class MuleContextInitialisePhase method applyLifecycle.

@Override
public void applyLifecycle(Object o) throws LifecycleException {
    // retain default Lifecycle behaviour
    super.applyLifecycle(o);
    if (o == null) {
        return;
    }
    if (ignoreType(o.getClass())) {
        return;
    }
    // Lets check for {@link PostConstruct} annotations on methods of this object and invoke
    List<AnnotationMetaData> annos = AnnotationUtils.getMethodAnnotations(o.getClass(), PostConstruct.class);
    // per object and that the method conforms to a lifecycle method
    if (annos.size() == 1) {
        AnnotationMetaData anno = annos.get(0);
        try {
            ((Method) anno.getMember()).invoke(o);
        } catch (Exception e) {
            throw new LifecycleException(CoreMessages.failedToInvokeLifecycle(anno.getMember().getName(), o), e, this);
        }
    }
}
Also used : LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) Method(java.lang.reflect.Method) AnnotationMetaData(org.mule.runtime.core.privileged.util.annotation.AnnotationMetaData) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException)

Example 5 with LifecycleException

use of org.mule.runtime.api.lifecycle.LifecycleException in project mule by mulesoft.

the class AbstractRegistry method initialise.

@Override
public final void initialise() throws InitialisationException {
    if (id == null) {
        logger.warn("No unique id has been set on this registry");
        id = UUID.getUUID();
    }
    try {
        doInitialise();
    } catch (InitialisationException e) {
        throw e;
    } catch (Exception e) {
        throw new InitialisationException(e, this);
    }
    try {
        fireLifecycle(Initialisable.PHASE_NAME);
    } catch (InitialisationException e) {
        throw e;
    } catch (LifecycleException e) {
        if (e.getComponent() instanceof Initialisable) {
            throw new InitialisationException(e, (Initialisable) e.getComponent());
        }
        throw new InitialisationException(e, this);
    }
}
Also used : LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException)

Aggregations

LifecycleException (org.mule.runtime.api.lifecycle.LifecycleException)6 Method (java.lang.reflect.Method)2 MuleException (org.mule.runtime.api.exception.MuleException)2 ConnectException (org.mule.runtime.core.api.connector.ConnectException)2 AnnotationMetaData (org.mule.runtime.core.privileged.util.annotation.AnnotationMetaData)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 Initialisable (org.mule.runtime.api.lifecycle.Initialisable)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 Startable (org.mule.runtime.api.lifecycle.Startable)1 Stoppable (org.mule.runtime.api.lifecycle.Stoppable)1 Processor (org.mule.runtime.core.api.processor.Processor)1 ReactiveProcessor (org.mule.runtime.core.api.processor.ReactiveProcessor)1 MessageSource (org.mule.runtime.core.api.source.MessageSource)1 LifecyclePhase (org.mule.runtime.core.internal.lifecycle.phases.LifecyclePhase)1 NotInLifecyclePhase (org.mule.runtime.core.internal.lifecycle.phases.NotInLifecyclePhase)1 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)1 SensingNullMessageProcessor (org.mule.tck.SensingNullMessageProcessor)1 LifecycleTrackerProcessor (org.mule.tck.core.lifecycle.LifecycleTrackerProcessor)1