Ejemplo n.º 1
0
 @Override
 public CompletableFuture<Object> invokeAsync() throws Throwable {
   GlobalComponentRegistry globalComponentRegistry = cacheManager.getGlobalComponentRegistry();
   ComponentRegistry cacheComponentRegistry =
       globalComponentRegistry.getNamedComponentRegistry(cacheName);
   String name = cacheName.toString();
   if (cacheComponentRegistry != null) {
     cacheComponentRegistry.getComponent(PersistenceManager.class).setClearOnStop(true);
     cacheComponentRegistry.getComponent(CacheJmxRegistration.class).setUnregisterCacheMBean(true);
     cacheComponentRegistry.getComponent(PassivationManager.class).skipPassivationOnStop(true);
     Cache<?, ?> cache = cacheManager.getCache(name, false);
     if (cache != null) {
       cache.stop();
     }
   }
   globalComponentRegistry.removeCache(name);
   // Remove cache configuration and remove it from the computed cache name list
   globalComponentRegistry.getComponent(ConfigurationManager.class).removeConfiguration(name);
   // Remove cache from dependency graph
   //noinspection unchecked
   globalComponentRegistry
       .getComponent(DependencyGraph.class, CACHE_DEPENDENCY_GRAPH)
       .remove(cacheName);
   return CompletableFutures.completedNull();
 }
Ejemplo n.º 2
0
 private void unregisterProtobufMetadataManagerMBean(GlobalComponentRegistry gcr) {
   try {
     ObjectName objName = gcr.getComponent(ProtobufMetadataManager.class).getObjectName();
     MBeanServer mBeanServer = JmxUtil.lookupMBeanServer(gcr.getGlobalConfiguration());
     JmxUtil.unregisterMBean(objName, mBeanServer);
   } catch (Exception e) {
     throw new CacheException("Unable to unregister ProtobufMetadataManager MBean", e);
   }
 }
Ejemplo n.º 3
0
 @Override
 protected EmbeddedCacheManager createCacheManager() throws Exception {
   ConfigurationBuilder c = getDefaultStandaloneCacheConfig(false);
   c.jmxStatistics().enable();
   cacheManager = TestCacheManagerFactory.createCacheManager(c);
   memcachedServer = MemcachedTestingUtil.startMemcachedTextServer(cacheManager);
   port = memcachedServer.getPort();
   memcachedClient = MemcachedTestingUtil.createMemcachedClient(60000, port);
   GlobalComponentRegistry gcr = TestingUtil.extractGlobalComponentRegistry(cacheManager);
   interpreter = gcr.getComponent(Interpreter.class);
   return cacheManager;
 }
Ejemplo n.º 4
0
 @Override
 protected void setup() throws Exception {
   super.setup();
   hotrodServer = HotRodClientTestingUtil.startHotRodServer(cacheManager);
   port = hotrodServer.getPort();
   remoteCacheManager =
       new RemoteCacheManager(
           new org.infinispan.client.hotrod.configuration.ConfigurationBuilder()
               .addServers("localhost:" + hotrodServer.getPort())
               .build());
   remoteCacheManager.start();
   GlobalComponentRegistry gcr = TestingUtil.extractGlobalComponentRegistry(cacheManager);
   interpreter = gcr.getComponent(Interpreter.class);
 }
 /**
  * Replaces a component in a running cache manager (global component registry)
  *
  * @param cacheContainer cache in which to replace component
  * @param componentType component type of which to replace
  * @param replacementComponent new instance
  * @param rewire if true, ComponentRegistry.rewire() is called after replacing.
  * @return the original component that was replaced
  */
 public static <T> T replaceComponent(
     CacheContainer cacheContainer,
     Class<T> componentType,
     T replacementComponent,
     boolean rewire) {
   GlobalComponentRegistry cr = extractGlobalComponentRegistry(cacheContainer);
   T old = cr.getComponent(componentType);
   cr.registerComponent(replacementComponent, componentType);
   if (rewire) {
     cr.rewire();
     cr.rewireNamedRegistries();
   }
   return old;
 }
Ejemplo n.º 6
0
 private SearchFactoryIntegrator getSearchFactory(
     Properties indexingProperties, ComponentRegistry cr) {
   Object component = cr.getComponent(SearchFactoryIntegrator.class);
   SearchFactoryIntegrator searchFactory = null;
   if (component
       instanceof
       SearchFactoryIntegrator) { // could be the placeholder Object REMOVED_REGISTRY_COMPONENT
     searchFactory = (SearchFactoryIntegrator) component;
   }
   // defend against multiple initialization:
   if (searchFactory == null) {
     GlobalComponentRegistry globalComponentRegistry = cr.getGlobalComponentRegistry();
     EmbeddedCacheManager uninitializedCacheManager =
         globalComponentRegistry.getComponent(EmbeddedCacheManager.class);
     indexingProperties = addProgrammaticMappings(indexingProperties, cr);
     // Set up the search factory for Hibernate Search first.
     SearchConfiguration config =
         new SearchableCacheConfiguration(
             new Class[0], indexingProperties, uninitializedCacheManager, cr);
     searchFactory = new SearchFactoryBuilder().configuration(config).buildSearchFactory();
     cr.registerComponent(searchFactory, SearchFactoryIntegrator.class);
   }
   return searchFactory;
 }
 public static ExternalizerTable extractExtTable(CacheContainer cacheContainer) {
   GlobalComponentRegistry gcr =
       (GlobalComponentRegistry) extractField(cacheContainer, "globalComponentRegistry");
   return gcr.getComponent(ExternalizerTable.class);
 }
 public static AbstractDelegatingMarshaller extractGlobalMarshaller(EmbeddedCacheManager cm) {
   GlobalComponentRegistry gcr =
       (GlobalComponentRegistry) extractField(cm, "globalComponentRegistry");
   return (AbstractDelegatingMarshaller)
       gcr.getComponent(StreamingMarshaller.class, KnownComponentNames.GLOBAL_MARSHALLER);
 }
 /** Extracts a component of a given type from the cache's internal component registry */
 public static <T> T extractGlobalComponent(
     CacheContainer cacheContainer, Class<T> componentType) {
   GlobalComponentRegistry gcr = extractGlobalComponentRegistry(cacheContainer);
   return gcr.getComponent(componentType);
 }
Ejemplo n.º 10
0
 @Override
 public void cacheManagerStarted(GlobalComponentRegistry gcr) {
   EmbeddedCacheManager cacheManager = gcr.getComponent(EmbeddedCacheManager.class);
   initProtobufMetadataManager((DefaultCacheManager) cacheManager, gcr);
 }