org.infinispan.factories.GlobalComponentRegistry Maven / Gradle / Ivy
package org.infinispan.factories;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import net.jcip.annotations.ThreadSafe;
import org.infinispan.Version;
import org.infinispan.commands.module.ModuleCommandFactory;
import org.infinispan.commands.module.ModuleCommandInitializer;
import org.infinispan.commons.CacheException;
import org.infinispan.commons.util.InfinispanCollections;
import org.infinispan.configuration.global.GlobalConfiguration;
import org.infinispan.configuration.global.ShutdownHookBehavior;
import org.infinispan.factories.annotations.SurvivesRestarts;
import org.infinispan.factories.components.ComponentMetadataRepo;
import org.infinispan.factories.scopes.Scope;
import org.infinispan.factories.scopes.Scopes;
import org.infinispan.jmx.CacheManagerJmxRegistration;
import org.infinispan.lifecycle.ComponentStatus;
import org.infinispan.lifecycle.ModuleLifecycle;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.manager.EmbeddedCacheManagerStartupException;
import org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier;
import org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifierImpl;
import org.infinispan.registry.ClusterRegistry;
import org.infinispan.registry.impl.ClusterRegistryImpl;
import org.infinispan.remoting.transport.Transport;
import org.infinispan.topology.ClusterTopologyManager;
import org.infinispan.topology.LocalTopologyManager;
import org.infinispan.util.ModuleProperties;
import org.infinispan.util.TimeService;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
/**
* A global component registry where shared components are stored.
*
* @author Manik Surtani
* @since 4.0
*/
@Scope(Scopes.GLOBAL)
@SurvivesRestarts
@ThreadSafe
public class GlobalComponentRegistry extends AbstractComponentRegistry {
private static final Log log = LogFactory.getLog(GlobalComponentRegistry.class);
private static volatile boolean versionLogged = false;
/**
* Hook to shut down the cache when the JVM exits.
*/
private Thread shutdownHook;
/**
* A flag that the shutdown hook sets before calling cache.stop(). Allows stop() to identify if it has been called
* from a shutdown hook.
*/
private boolean invokedFromShutdownHook;
private final GlobalConfiguration globalConfiguration;
/**
* Tracking set of created caches in order to make it easy to remove a cache on remote nodes.
*/
private final Set createdCaches;
private final ModuleProperties moduleProperties = new ModuleProperties();
private final ComponentMetadataRepo componentMetadataRepo;
final Collection moduleLifecycles;
final ConcurrentMap namedComponents = new ConcurrentHashMap(4);
protected final WeakReference defaultClassLoader;
/**
* Creates an instance of the component registry. The configuration passed in is automatically registered.
*
* @param configuration configuration with which this is created
*/
public GlobalComponentRegistry(GlobalConfiguration configuration,
EmbeddedCacheManager cacheManager,
Set createdCaches) {
ClassLoader configuredClassLoader = configuration.classLoader();
moduleLifecycles = moduleProperties.resolveModuleLifecycles(configuredClassLoader);
componentMetadataRepo = new ComponentMetadataRepo();
// Load up the component metadata
componentMetadataRepo.initialize(moduleProperties.getModuleMetadataFiles(configuredClassLoader), configuredClassLoader);
defaultClassLoader = new WeakReference(registerDefaultClassLoader(configuredClassLoader));
try {
// this order is important ...
globalConfiguration = configuration;
registerComponent(this, GlobalComponentRegistry.class);
registerComponent(configuration, GlobalConfiguration.class);
registerComponent(cacheManager, EmbeddedCacheManager.class);
registerComponent(new CacheManagerJmxRegistration(), CacheManagerJmxRegistration.class);
registerComponent(new CacheManagerNotifierImpl(), CacheManagerNotifier.class);
registerComponent(new ClusterRegistryImpl(), ClusterRegistry.class);
moduleProperties.loadModuleCommandHandlers(configuredClassLoader);
Map factories = moduleProperties.moduleCommandFactories();
if (factories != null && !factories.isEmpty())
registerNonVolatileComponent(factories, KnownComponentNames.MODULE_COMMAND_FACTORIES);
else
registerNonVolatileComponent(
InfinispanCollections.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy