@Override public Affinity getWeakAffinity(I id) { if (this.cache.getCacheConfiguration().clustering().cacheMode().isClustered()) { Node node = this.locatePrimaryOwner(id); Map.Entry<String, ?> entry = this.registry.getEntry(node); if (entry != null) { return new NodeAffinity(entry.getKey()); } } return Affinity.NONE; }
@Override public Affinity getStrictAffinity() { Group group = this.registry.getGroup(); return this.cache.getCacheConfiguration().clustering().cacheMode().isClustered() ? new ClusterAffinity(group.getName()) : new NodeAffinity(this.registry.getEntry(group.getLocalMember()).getKey()); }
/** * Indicates whether the given cache is configured to cluster its contents. * A cache is considered to clustered if it's configured with any cache mode * except {@link org.infinispan.configuration.cache.CacheMode#LOCAL} * * @param cache to check whether it clusters its contents * @return true if the cache is configured with clustering, false otherwise */ public static boolean isClustered(AdvancedCache cache) { return cache.getCacheConfiguration() .clustering().cacheMode().isClustered(); }
private static void validateIndexCaches(String indexName, Cache<?, ?>... caches) { Arrays.stream(caches).filter(Objects::nonNull).forEach(cache -> { ClusteringConfiguration clusteringConfiguration = cache.getCacheConfiguration().clustering(); CacheMode cacheMode = clusteringConfiguration.cacheMode(); if (cacheMode.isClustered() && !cacheMode.isSynchronous()) { throw log.cannotStoreIndexOnAsyncCaches(indexName, cache.getName(), cacheMode); } }); }
private static void validateIndexCaches(String indexName, Cache<?, ?>... caches) { Arrays.stream(caches).filter(Objects::nonNull).forEach(cache -> { ClusteringConfiguration clusteringConfiguration = cache.getCacheConfiguration().clustering(); CacheMode cacheMode = clusteringConfiguration.cacheMode(); if (cacheMode.isClustered() && !cacheMode.isSynchronous()) { throw log.cannotStoreIndexOnAsyncCaches(indexName, cache.getName(), cacheMode); } }); }
@Override public Affinity getWeakAffinity(I id) { if (this.cache.getCacheConfiguration().clustering().cacheMode().isClustered()) { Node node = this.locatePrimaryOwner(id); Map.Entry<String, ?> entry = this.registry.getEntry(node); if (entry != null) { return new NodeAffinity(entry.getKey()); } } return Affinity.NONE; }
public PartitionHandlingSupport(AdvancedCache<?, ?> cache) { this.cache = cache; ClusteringConfiguration clusteringConfiguration = cache.getCacheConfiguration().clustering(); this.isClustered = clusteringConfiguration.cacheMode().isClustered(); this.partitionHandling = isClustered ? clusteringConfiguration.partitionHandling().whenSplit() : null; }
private void waitForPartitionToForm(boolean waitForNoRebalance) { List<Cache<Object, Object>> caches = new ArrayList<>(getCaches(null)); Iterator<Cache<Object, Object>> i = caches.iterator(); while (i.hasNext()) { if (!channels.contains(channel(i.next()))) i.remove(); } Cache<Object, Object> cache = caches.get(0); TestingUtil.blockUntilViewsReceived(10000, caches); if (waitForNoRebalance) { if (cache.getCacheConfiguration().clustering().cacheMode().isClustered()) { TestingUtil.waitForNoRebalance(caches); } } }
@Override public Affinity getStrictAffinity() { Group group = this.registry.getGroup(); return this.cache.getCacheConfiguration().clustering().cacheMode().isClustered() ? new ClusterAffinity(group.getName()) : new NodeAffinity(this.registry.getEntry(group.getLocalMember()).getKey()); }
private CacheTopology getCounterCacheTopology(EmbeddedCacheManager cacheManager) { AdvancedCache<?, ?> cache = cacheManager.getCache(CounterModuleLifecycle.COUNTER_CACHE_NAME).getAdvancedCache(); return cache.getCacheConfiguration().clustering().cacheMode().isClustered() ? cache.getComponentRegistry().getDistributionManager().getCacheTopology() : null; //local cache }
protected void waitForClusterToForm(String cacheName) { List<Cache<Object, Object>> caches = getCaches(cacheName); Cache<Object, Object> cache = caches.get(0); TestingUtil.blockUntilViewsReceived(30000, caches); if (cache.getCacheConfiguration().clustering().cacheMode().isClustered()) { TestingUtil.waitForNoRebalance(caches); } }
public MobicentsCache(String name, CacheContainer jBossCacheContainer, ClassLoader classLoader, CacheDataExecutorService cacheDataExecutorService) { this.jBossCacheContainer = jBossCacheContainer; this.cacheDataExecutorService = cacheDataExecutorService; if (this.jBossCacheContainer.getCache().getCacheConfiguration().clustering().cacheMode().isClustered()) { this.cache = new DecoratedCache<Object, Object>(this.jBossCacheContainer.getCache(name).getAdvancedCache(), classLoader); } else { this.cache = this.jBossCacheContainer.getCache(name); } this.name = name; this.managedCache = false; setLocalMode(); }
public NonTxInvalidationCacheAccessDelegate(InfinispanDataRegion region, PutFromLoadValidator validator) { super(region, validator); isLocal = !region.getCache().getCacheConfiguration().clustering().cacheMode().isClustered(); ComponentRegistry cr = region.getCache().getComponentRegistry(); invoker = cr.getComponent(AsyncInterceptorChain.class); commandsFactory = cr.getComponent(CommandsFactory.class); keyPartitioner = cr.getComponent(KeyPartitioner.class); contextFactory = cr.getComponent(InvocationContextFactory.class); nonTxPutFromLoadInterceptor = cr.getComponent(NonTxPutFromLoadInterceptor.class); }
public void testExpirationMaxIdleInExec() throws Exception { for (int i = 0; i < SIZE; i++) { cache.put("key-" + i, "value-" + i,-1, null, 1, TimeUnit.MILLISECONDS); } timeService.advance(2); if (cache.getCacheConfiguration().clustering().cacheMode().isClustered()) { AtomicInteger invocationCount = new AtomicInteger(); cache.getAdvancedCache().getDataContainer().executeTask(KeyFilter.ACCEPT_ALL_FILTER, (k, ice) -> invocationCount.incrementAndGet()); assertEquals(SIZE, invocationCount.get()); } else { cache.getAdvancedCache().getDataContainer().executeTask(KeyFilter.ACCEPT_ALL_FILTER, (k, ice) -> { throw new RuntimeException("No task should be executed on expired entry"); }); } }
/** * {@inheritDoc} * @see org.jboss.msc.service.Service#start(org.jboss.msc.service.StartContext) */ @Override public void start(StartContext context) throws StartException { this.config = this.getConfigurationBuilder().build(); EmbeddedCacheManager container = this.getCacheContainer(); CacheMode mode = this.config.clustering().cacheMode(); if (mode.isClustered() && (container.getTransport() == null)) { throw InfinispanMessages.MESSAGES.transportRequired(mode, this.name, container.getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName()); } SecurityActions.defineContainerConfiguration(container, this.name, this.config); log.debugf("%s cache configuration started", this.name); }
public static EmbeddedCacheManager createCacheManager(CacheMode mode, boolean indexing) { ConfigurationBuilder builder = new ConfigurationBuilder(); builder .clustering() .cacheMode(mode) .indexing() .index(indexing ? Index.ALL : Index.NONE) .addProperty("lucene_version", "LUCENE_CURRENT") ; if (mode.isClustered()) { return createClusteredCacheManager(builder); } else { return createCacheManager(builder); } }
protected <K, V> Cache<K, V> getLockOwner(Object key, String cacheName) { Configuration c = getCache(0, cacheName).getCacheConfiguration(); if (c.clustering().cacheMode().isInvalidation()) { return getCache(0, cacheName); //for replicated caches only the coordinator acquires lock } else if (!c.clustering().cacheMode().isClustered()) { throw new IllegalStateException("This is not a clustered cache!"); } else { Address address = getCache(0, cacheName).getAdvancedCache().getDistributionManager().getCacheTopology() .getDistribution(key).primary(); for (Cache<K, V> cache : this.<K, V>caches(cacheName)) { if (cache.getAdvancedCache().getRpcManager().getTransport().getAddress().equals(address)) { return cache; } } throw new IllegalStateException(); } }
@Override protected void createCacheManagers() throws Throwable { builderUsed = new ConfigurationBuilder(); builderUsed.clustering().cacheMode(cacheMode); if (transactional) { builderUsed.transaction().transactionMode(TransactionMode.TRANSACTIONAL); } if (cacheMode.isClustered()) { builderUsed.clustering().stateTransfer().chunkSize(50); enhanceConfiguration(builderUsed); createClusteredCaches(3, CACHE_NAME, builderUsed); } else { enhanceConfiguration(builderUsed); EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(builderUsed); cacheManagers.add(cm); cm.defineConfiguration(CACHE_NAME, builderUsed.build()); } }
public void testRollbackSpanningCaches2() throws Exception { startAllCaches(); Cache<String, String> c1 = cache(0, "c1"); assertTrue(c1.getCacheConfiguration().clustering().cacheMode().isClustered()); Cache<String, String> c1Replica = cache(1, "c1"); assertTrue(c1.isEmpty()); assertTrue(c1Replica.isEmpty()); c1.put("c1key", "c1value"); assertEquals(c1.get("c1key"), "c1value"); assertEquals(c1Replica.get("c1key"), "c1value"); }
@Override protected void createCacheManagers() throws Throwable { builderUsed = new ConfigurationBuilder(); builderUsed.clustering().cacheMode(cacheMode); builderUsed.clustering().hash().numOwners(1); builderUsed.persistence().passivation(false).addStore(DummyInMemoryStoreConfigurationBuilder.class) .storeName(cacheName); if (tx) { builderUsed.transaction().transactionMode(TransactionMode.TRANSACTIONAL); } if (cacheMode.isClustered()) { createClusteredCaches(3, cacheName, builderUsed); } else { createClusteredCaches(1, cacheName, builderUsed); } }