use of org.mule.runtime.core.api.lifecycle.LifecycleObject 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);
}
use of org.mule.runtime.core.api.lifecycle.LifecycleObject in project mule by mulesoft.
the class RegistryLifecycleCallback method doApplyLifecycle.
private void doApplyLifecycle(LifecyclePhase phase, Set<Object> duplicates, LifecycleObject lifecycleObject, Collection<?> targetObjects) throws LifecycleException {
if (CollectionUtils.isEmpty(targetObjects)) {
return;
}
for (Object target : targetObjects) {
if (duplicates.contains(target) || target == null) {
continue;
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("lifecycle phase: " + phase.getName() + " for object: " + target);
}
applyLifecycle(phase, duplicates, target);
}
// the target object might have created and registered a new object
// (e.g.: an endpoint which registers a connector)
// check if there're new objects for the phase
int originalTargetCount = targetObjects.size();
targetObjects = lookupObjectsForLifecycle(lifecycleObject);
if (targetObjects.size() > originalTargetCount) {
doApplyLifecycle(phase, duplicates, lifecycleObject, targetObjects);
}
}
Aggregations