Search in sources :

Example 1 with LifecyclePhase

use of org.mule.runtime.core.internal.lifecycle.phases.LifecyclePhase in project mule by mulesoft.

the class RegistryLifecycleCallback method doOnTransition.

private void doOnTransition(String phaseName, T object) throws MuleException {
    LifecyclePhase phase = registryLifecycleManager.phases.get(phaseName);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Applying lifecycle phase: %s for registry: %s", phase, object.getClass().getSimpleName()));
    }
    if (phase instanceof ContainerManagedLifecyclePhase) {
        phase.applyLifecycle(object);
        return;
    }
    // overlapping interfaces can cause duplicates
    // TODO: each LifecycleManager should keep this set per executing phase
    // and clear it when the phase is fully applied
    Set<Object> duplicates = new HashSet<>();
    final NotificationDispatcher notificationFirer = ((MuleContextWithRegistries) registryLifecycleManager.muleContext).getRegistry().lookupObject(NotificationDispatcher.class);
    for (LifecycleObject lifecycleObject : phase.getOrderedLifecycleObjects()) {
        lifecycleObject.firePreNotification(notificationFirer);
        // TODO Collection -> List API refactoring
        Collection<?> targetsObj = lookupObjectsForLifecycle(lifecycleObject);
        doApplyLifecycle(phase, duplicates, lifecycleObject, targetsObj);
        lifecycleObject.firePostNotification(notificationFirer);
    }
    interceptor.onPhaseCompleted(phase);
}
Also used : ContainerManagedLifecyclePhase(org.mule.runtime.core.internal.lifecycle.phases.ContainerManagedLifecyclePhase) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) LifecycleObject(org.mule.runtime.core.api.lifecycle.LifecycleObject) LifecycleObject(org.mule.runtime.core.api.lifecycle.LifecycleObject) LifecyclePhase(org.mule.runtime.core.internal.lifecycle.phases.LifecyclePhase) ContainerManagedLifecyclePhase(org.mule.runtime.core.internal.lifecycle.phases.ContainerManagedLifecyclePhase) HashSet(java.util.HashSet)

Example 2 with LifecyclePhase

use of org.mule.runtime.core.internal.lifecycle.phases.LifecyclePhase 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)

Aggregations

LifecyclePhase (org.mule.runtime.core.internal.lifecycle.phases.LifecyclePhase)2 HashSet (java.util.HashSet)1 LifecycleException (org.mule.runtime.api.lifecycle.LifecycleException)1 NotificationDispatcher (org.mule.runtime.api.notification.NotificationDispatcher)1 ConnectException (org.mule.runtime.core.api.connector.ConnectException)1 LifecycleObject (org.mule.runtime.core.api.lifecycle.LifecycleObject)1 ContainerManagedLifecyclePhase (org.mule.runtime.core.internal.lifecycle.phases.ContainerManagedLifecyclePhase)1 NotInLifecyclePhase (org.mule.runtime.core.internal.lifecycle.phases.NotInLifecyclePhase)1