org.mule.lifecycle.RegistryLifecycleCallback Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mule-core Show documentation
Show all versions of mule-core Show documentation
Mule server and core classes
/*
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.lifecycle;
import org.mule.api.MuleException;
import org.mule.api.lifecycle.HasLifecycleInterceptor;
import org.mule.api.lifecycle.LifecycleCallback;
import org.mule.api.lifecycle.LifecycleException;
import org.mule.api.lifecycle.LifecycleInterceptor;
import org.mule.api.lifecycle.LifecyclePhase;
import org.mule.api.registry.Registry;
import org.mule.lifecycle.phases.ContainerManagedLifecyclePhase;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* An implementation of {@link LifecycleCallback} for applying {@link Registry} lifecycles
*
* @since 3.7.0
*/
public class RegistryLifecycleCallback implements LifecycleCallback, HasLifecycleInterceptor
{
private static final Logger LOGGER = LoggerFactory.getLogger(RegistryLifecycleCallback.class);
protected final RegistryLifecycleManager registryLifecycleManager;
private LifecycleInterceptor interceptor = new NullLifecycleInterceptor();
public RegistryLifecycleCallback(RegistryLifecycleManager registryLifecycleManager)
{
this.registryLifecycleManager = registryLifecycleManager;
}
@Override
public void onTransition(String phaseName, T object) throws MuleException
{
LifecyclePhase phase = registryLifecycleManager.phases.get(phaseName);
if (LOGGER.isDebugEnabled())
{
LOGGER.debug(String.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