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;
}
}
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);
}
}
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();
}
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);
}
}
}
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);
}
}
Aggregations