@Override public EmbeddedCacheManager get() { GlobalConfiguration config = this.configuration.get(); String defaultCacheName = config.defaultCacheName().orElse(null); // We need to create a dummy default configuration if cache has a default cache Configuration defaultConfiguration = (defaultCacheName != null) ? new ConfigurationBuilder().build() : null; EmbeddedCacheManager manager = new DefaultCacheManager(config, defaultConfiguration, false); // Undefine the default cache, if we defined one if (defaultCacheName != null) { manager.undefineConfiguration(defaultCacheName); } // Override GlobalConfigurationManager with a local implementation @SuppressWarnings("deprecation") BasicComponentRegistry registry = manager.getGlobalComponentRegistry().getComponent(BasicComponentRegistry.class); registry.replaceComponent(GlobalConfigurationManager.class.getName(), new LocalGlobalConfigurationManager(), false); registry.rewire(); manager.start(); manager.addListener(this); InfinispanLogger.ROOT_LOGGER.debugf("%s cache container started", this.name); return manager; }
@Override public synchronized void start() { this.container.start(); }
@Override public synchronized void start() throws Exception { manager().start(); }
public static void registerAndStartContainer(final EmbeddedCacheManager container, final Object listener) { PrivilegedAction<Void> action = () -> { container.addListener(listener); container.start(); return null; }; doPrivileged(action); }
private void start(CacheContainerRegistryEntry entry) { EmbeddedCacheManager container = entry.getContainer(); container.start(); container.addListener(this.factory); String jndiName = entry.getJndiName(); if (jndiName != null) { try { logger.info("Binding " + entry.getId() + " cache container to " + jndiName); this.bind(jndiName, container); } catch (NamingException e) { logger.warn(e.getMessage(), e); } } }
public void testStopStartCM() throws Exception { EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(false); cacheContainers.add(cm); cm.stop(); cm.start(); }
protected EmbeddedCacheManager addClusterEnabledCacheManager(GlobalConfigurationBuilder globalBuilder, ConfigurationBuilder builder, TransportFlags flags) { EmbeddedCacheManager cm = TestCacheManagerFactory.createClusteredCacheManager(false, globalBuilder, builder, flags, false); amendCacheManagerBeforeStart(cm); cacheManagers.add(cm); cm.start(); return cm; }
protected EmbeddedCacheManager addClusterEnabledCacheManager(ConfigurationBuilderHolder builderHolder) { EmbeddedCacheManager cm = TestCacheManagerFactory.createClusteredCacheManager(false, builderHolder, false); amendCacheManagerBeforeStart(cm); cacheManagers.add(cm); cm.start(); return cm; }
/** * Creates a new optionally transactional cache manager, starts it, and adds it to the list of known cache managers on * the current thread. Uses a default clustered cache manager global config. * * @param builder default cfg to use * @return the new CacheManager */ protected EmbeddedCacheManager addClusterEnabledCacheManager(ConfigurationBuilder builder, TransportFlags flags) { EmbeddedCacheManager cm = TestCacheManagerFactory.createClusteredCacheManager(false, GlobalConfigurationBuilder.defaultClusteredBuilder(), builder, flags, false); amendCacheManagerBeforeStart(cm); cacheManagers.add(cm); cm.start(); return cm; }
@BeforeClass public void startCacheManagers() { DEFAULT_CACHE_MANAGER = TestCacheManagerFactory.createCacheManager(); DEFAULT_CACHE_MANAGER.start(); InputStream configStream = null; try { configStream = NAMED_ASYNC_CACHE_CONFIG_LOCATION.getInputStream(); PRECONFIGURED_DEFAULT_CACHE_MANAGER = TestCacheManagerFactory.fromStream(configStream); } catch (final IOException e) { throw new ExceptionInInitializerError(e); } finally { if (configStream != null) { try { configStream.close(); } catch (final IOException e) { // Ignore } } } }
@BeforeClass public void startCacheManagers() { DEFAULT_CACHE_MANAGER = TestCacheManagerFactory.createCacheManager(); DEFAULT_CACHE_MANAGER.start(); InputStream configStream = null; try { configStream = NAMED_ASYNC_CACHE_CONFIG_LOCATION.getInputStream(); PRECONFIGURED_DEFAULT_CACHE_MANAGER = TestCacheManagerFactory.fromStream(configStream); } catch (final IOException e) { throw new ExceptionInInitializerError(e); } finally { if (configStream != null) { try { configStream.close(); } catch (final IOException e) { // Ignore } } } }
@BeforeClass public void startCacheManagers() { DEFAULT_CACHE_MANAGER = TestCacheManagerFactory.createCacheManager(); DEFAULT_CACHE_MANAGER.start(); InputStream configStream = null; try { configStream = NAMED_ASYNC_CACHE_CONFIG_LOCATION.getInputStream(); PRECONFIGURED_DEFAULT_CACHE_MANAGER = TestCacheManagerFactory.fromStream(configStream); } catch (final IOException e) { throw new ExceptionInInitializerError(e); } finally { if (configStream != null) { try { configStream.close(); } catch (final IOException e) { // Ignore } } } }
public <T extends FieldElement<T>> void testInitialClusterSizeFail() throws Throwable { List<Future<Void>> futures = new ArrayList<>(); for (int i = 0; i < CLUSTER_SIZE - 1; i++) { EmbeddedCacheManager manager = manager(i); futures.add(fork(() -> { manager.start(); return null; })); } for (Future<Void> future : futures) { try { // JGroupsTransport only starts counting down on initialClusterTimeout *after* it connects. // The initial connection may take take 3 seconds (GMS.join_timeout) because of JGRP-2028 // Shutdown may also take 2 seconds (GMS.view_ack_collection_timeout) because of JGRP-2030 future.get(CLUSTER_TIMEOUT_SECONDS + 5, TimeUnit.SECONDS); fail("Should have thrown an exception"); } catch (ExecutionException ee) { Exceptions.assertException(EmbeddedCacheManagerStartupException.class, ee.getCause()); Exceptions.assertException(CacheException.class, org.infinispan.util.concurrent.TimeoutException.class, "ISPN000399:.*", ee.getCause().getCause()); } } }
public void testInitialClusterSize() throws ExecutionException, InterruptedException, TimeoutException { Future<?>[] threads = new Future[CLUSTER_SIZE]; for (int i = 0; i < CLUSTER_SIZE; i++) { final int index = i; threads[i] = fork(() -> { manager(index).start(); }); } for(Future<?> f : threads) { f.get(15, TimeUnit.SECONDS); } assertEquals(CLUSTER_SIZE, manager(0).getMembers().size()); }
/** * Creates a new cache manager, starts it, and adds it to the list of known * cache managers on the current thread. Uses a default clustered cache * manager global config. * * @param flags properties that allow transport stack to be tweaked * @return the new CacheManager */ protected EmbeddedCacheManager addClusterEnabledCacheManager(TransportFlags flags) { EmbeddedCacheManager cm = TestCacheManagerFactory.createClusteredCacheManager(false, GlobalConfigurationBuilder.defaultClusteredBuilder(), new ConfigurationBuilder(), flags, false); amendCacheManagerBeforeStart(cm); cacheManagers.add(cm); cm.start(); return cm; }
public void testLockPersistentLocation() { String stateDirectory = TestingUtil.tmpDirectory(this.getClass().getSimpleName() + File.separator + "COMMON"); GlobalConfigurationBuilder global1 = statefulGlobalBuilder(stateDirectory, true); GlobalConfigurationBuilder global2 = statefulGlobalBuilder(stateDirectory, true); EmbeddedCacheManager cm1 = TestCacheManagerFactory.createClusteredCacheManager(false, global1, new ConfigurationBuilder(), new TransportFlags(), false); EmbeddedCacheManager cm2 = TestCacheManagerFactory.createClusteredCacheManager(false, global2, new ConfigurationBuilder(), new TransportFlags(), false); try { cm1.start(); Exceptions.expectException(EmbeddedCacheManagerStartupException.class, "org.infinispan.commons.CacheConfigurationException: ISPN000512: Cannot acquire lock.*", () -> cm2.start()); } finally { TestingUtil.killCacheManagers(cm1, cm2); } }
public void testRegisterLocalCache() throws Exception { EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(false); cacheContainers.add(cm); cm.start(); ConfigurationBuilder configuration = config(); configuration.clustering().cacheMode(CacheMode.LOCAL); cm.defineConfiguration("first", configuration.build()); Cache first = cm.getCache("first"); ComponentMetadataRepo metadataRepo = cm.getGlobalComponentRegistry().getComponentMetadataRepo(); ComponentMetadata metadata = metadataRepo.getComponentMetadata(first.getClass()); ResourceDMBean mbean = new ResourceDMBean(first, metadata.toManageableComponentMetadata()); Collection<ResourceDMBean> mbeans = singleton(mbean); ComponentsJmxRegistration regComponents = buildRegistrator(first); regComponents.registerMBeans(mbeans); String name = regComponents.getObjectName("Cache").toString(); ObjectName name1 = new ObjectName(name); assert mBeanServer.isRegistered(name1); regComponents.unregisterMBeans(mbeans); assert !mBeanServer.isRegistered(name1); assertCorrectJmxName(name1, first); }
public void testRegisterReplicatedCache() throws Exception { GlobalConfigurationBuilder globalConfiguration = GlobalConfigurationBuilder.defaultClusteredBuilder(); globalConfiguration.globalJmxStatistics().enable(); EmbeddedCacheManager cm = TestCacheManagerFactory.createClusteredCacheManager(globalConfiguration, new ConfigurationBuilder()); cacheContainers.add(cm); cm.start(); ConfigurationBuilder configurationOverride = config(); configurationOverride.clustering().cacheMode(CacheMode.REPL_SYNC); cm.defineConfiguration("first", configurationOverride.build()); Cache first = cm.getCache("first"); ComponentMetadataRepo metadataRepo = cm.getGlobalComponentRegistry().getComponentMetadataRepo(); ComponentMetadata metadata = metadataRepo.getComponentMetadata(first.getClass()); ResourceDMBean mbean = new ResourceDMBean(first, metadata.toManageableComponentMetadata()); Collection<ResourceDMBean> mbeans = singleton(mbean); ComponentsJmxRegistration regComponents = buildRegistrator(first); regComponents.registerMBeans(mbeans); String name = regComponents.getObjectName("Cache").toString(); ObjectName name1 = new ObjectName(name); assertCorrectJmxName(name1, first); assert mBeanServer.isRegistered(name1); regComponents.unregisterMBeans(mbeans); assert !mBeanServer.isRegistered(name1); }
public void testConfigBuilder() { GlobalConfiguration globalConfig = new GlobalConfigurationBuilder() .transport().defaultTransport() .build(); Configuration cacheConfig = new ConfigurationBuilder().persistence().addStore(LevelDBStoreConfigurationBuilder.class).location(tmpDataDirectory) .expiredLocation(tmpExpiredDirectory).implementationType(LevelDBStoreConfiguration.ImplementationType.AUTO).build(); StoreConfiguration cacheLoaderConfig = cacheConfig.persistence().stores().get(0); assertTrue(cacheLoaderConfig instanceof LevelDBStoreConfiguration); LevelDBStoreConfiguration leveldbConfig = (LevelDBStoreConfiguration) cacheLoaderConfig; assertEquals(tmpDataDirectory, leveldbConfig.location()); assertEquals(tmpExpiredDirectory, leveldbConfig.expiredLocation()); EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfig); cacheManager.defineConfiguration("testCache", cacheConfig); cacheManager.start(); Cache<String, String> cache = cacheManager.getCache("testCache"); cache.put("hello", "there"); cache.stop(); cacheManager.stop(); }