@Override public ModelNode execute(EmbeddedCacheManager manager) { Address address = manager.getAddress(); return (address != null) ? new ModelNode(address.toString()) : null; } },
@Override public K createIdentifier() { return this.affinity.getKeyForAddress(this.manager.getAddress()).getValue(); }
@Override public Node getLocalMember() { return this.createNode(this.cache.getCacheManager().getAddress()); }
@TopologyChanged public void topologyChanged(TopologyChangedEvent<?, ?> event) { if (event.isPre()) return; int viewId = event.getCache().getCacheManager().getTransport().getViewId(); if (!this.listeners.isEmpty()) { Address localAddress = event.getCache().getCacheManager().getAddress(); Membership previousMembership = new CacheMembership(localAddress, event.getWriteConsistentHashAtStart(), this); Membership membership = new CacheMembership(localAddress, event.getWriteConsistentHashAtEnd(), this); Boolean status = this.views.get(viewId); boolean merged = (status != null) ? status.booleanValue() : false; for (Map.Entry<GroupListener, ExecutorService> entry : this.listeners.entrySet()) { GroupListener listener = entry.getKey(); ExecutorService executor = entry.getValue(); try { executor.submit(() -> { try { listener.membershipChanged(previousMembership, membership, merged); } catch (Throwable e) { ClusteringServerLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e); } }); } catch (RejectedExecutionException e) { // Listener was unregistered } } } // Purge obsolete views this.views.headMap(viewId).clear(); }
@Override public <K> KeyAffinityService<K> createService(Cache<K, ?> cache, KeyGenerator<K> generator) { CacheMode mode = cache.getCacheConfiguration().clustering().cacheMode(); return mode.isDistributed() || mode.isReplicated() ? new KeyAffinityServiceImpl<>(executor, cache, generator, bufferSize, Collections.singleton(cache.getCacheManager().getAddress()), false) : new SimpleKeyAffinityService<>(generator); } };
public ConsistentHashLocality(Cache<?, ?> cache, ConsistentHash hash) { this.topology = new LocalizedCacheTopology(cache.getCacheConfiguration().clustering().cacheMode(), new CacheTopology(0, 0, hash, null, CacheTopology.Phase.NO_REBALANCE, Collections.emptyList(), Collections.emptyList()), cache.getCacheConfiguration().clustering().hash().keyPartitioner(), cache.getCacheManager().getAddress(), true); }
@Override public String locate(String sessionId) { DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); Address address = (dist != null) && !this.cache.getCacheConfiguration().clustering().cacheMode().isScattered() ? dist.getCacheTopology().getDistribution(new Key<>(sessionId)).primary() : this.cache.getCacheManager().getAddress(); Node node = (address != null) ? this.factory.createNode(address) : null; Map.Entry<String, Void> entry = (node != null) ? this.registry.getEntry(node) : null; if (entry == null) { entry = this.registry.getEntry(this.registry.getGroup().getLocalMember()); } return (entry != null) ? entry.getKey() : null; } }
public InfinispanBeanManager(InfinispanBeanManagerConfiguration<I, T> configuration, IdentifierFactory<I> identifierFactory, Configuration<BeanKey<I>, BeanEntry<I>, BeanFactory<I, T>> beanConfiguration, Configuration<BeanGroupKey<I>, BeanGroupEntry<I, T>, BeanGroupFactory<I, T>> groupConfiguration) { this.filter = configuration.getBeanFilter(); this.groupFactory = groupConfiguration.getFactory(); this.beanFactory = beanConfiguration.getFactory(); this.cache = beanConfiguration.getCache(); this.properties = configuration.getProperties(); this.batcher = new InfinispanBatcher(this.cache); Address address = this.cache.getCacheManager().getAddress(); KeyAffinityServiceFactory affinityFactory = configuration.getAffinityFactory(); KeyGenerator<BeanKey<I>> beanKeyGenerator = () -> beanConfiguration.getFactory().createKey(identifierFactory.createIdentifier()); this.affinity = affinityFactory.createService(this.cache, beanKeyGenerator); this.identifierFactory = () -> this.affinity.getKeyForAddress(address).getId(); this.registry = configuration.getRegistry(); this.nodeFactory = configuration.getNodeFactory(); this.dispatcherFactory = configuration.getCommandDispatcherFactory(); this.expiration = configuration.getExpirationConfiguration(); this.passivation = configuration.getPassivationConfiguration(); }
public EmbeddedCacheManager manager(Address a) { for (EmbeddedCacheManager cm : cacheManagers) { if (cm.getAddress().equals(a)) { return cm; } } throw new IllegalArgumentException(a + " is not a valid cache manager address!"); }
public int managerIndex(Address a) { for (int i = 0; i < cacheManagers.size(); i++) { EmbeddedCacheManager cm = cacheManagers.get(i); if (cm.getAddress().equals(a)) { return i; } } throw new IllegalArgumentException(a + " is not a valid cache manager address!"); }
@Override public Object visitGetCacheEntryCommand(InvocationContext ctx, GetCacheEntryCommand command) throws Throwable { hit.set(true); throw new IllegalStateException("Did not expect the command to be executed on node " + cache.getCacheManager().getAddress()); }
public void testAddressInformation() throws Exception { String cm1Address = manager(0).getAddress().toString(); String cm2Address = manager(1).getAddress().toString(); assert server.getAttribute(name1, "NodeAddress").equals(cm1Address); assert server.getAttribute(name1, "ClusterMembers").toString().contains(cm1Address); assert !server.getAttribute(name1, "PhysicalAddresses").toString().equals("local"); assert server.getAttribute(name1, "ClusterSize").equals(2); assert server.getAttribute(name2, "NodeAddress").equals(cm2Address); assert server.getAttribute(name2, "ClusterMembers").toString().contains(cm2Address); assert !server.getAttribute(name2, "PhysicalAddresses").toString().equals("local"); assert server.getAttribute(name2, "ClusterSize").equals(2); }
public static boolean areCacheViewsComplete(boolean barfIfTooManyMembers, CacheContainer... cacheContainers) { if (cacheContainers == null) throw new NullPointerException("Cache Manager array is null"); int memberCount = cacheContainers.length; for (CacheContainer cacheContainer : cacheContainers) { EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) cacheContainer; if (!isCacheViewComplete(cacheManager.getMembers(), cacheManager.getAddress(), memberCount, barfIfTooManyMembers)) { return false; } } return true; }
public PerCacheExecutorThread(Cache<Object, Object> cache, int index) { super("PerCacheExecutorThread-" + index + "," + cache.getCacheManager().getAddress()); this.cache = cache; start(); }
@Override public void setEnvironment(Cache cache, Set inputKeys) { log.info("Setting env..." + cache.getAdvancedCache().getCacheManager().getAddress() + ", keys: " + inputKeys); this.cache = cache; this.key = (TestKey) inputKeys.iterator().next(); this.tm = cache.getAdvancedCache().getTransactionManager(); }
@Override public void call() throws InterruptedException, ExecutionException, TimeoutException { EmbeddedCacheManager cm1 = cms[0]; EmbeddedCacheManager cm2 = cms[1]; atomicIntegerSupplier.get().set(0); SerializableSupplier<AtomicInteger> supplier = atomicIntegerSupplier; executor(cm1).filterTargets(Collections.singleton(cm2.getAddress())) .submit(() -> supplier.get().getAndIncrement()).get(10, TimeUnit.SECONDS); assertEquals(1, atomicIntegerSupplier.get().get()); } });
/** * @param c * @param memberCount */ public static boolean isCacheViewComplete(Cache c, int memberCount) { EmbeddedCacheManager cacheManager = c.getCacheManager(); return isCacheViewComplete(cacheManager.getMembers(), cacheManager.getAddress(), memberCount, true); }
public static BlockingLocalTopologyManager replaceTopologyManager(EmbeddedCacheManager cacheContainer, String cacheName) { LocalTopologyManager manager = TestingUtil.extractGlobalComponent(cacheContainer, LocalTopologyManager.class); BlockingLocalTopologyManager controlledLocalTopologyManager = new BlockingLocalTopologyManager(manager, cacheContainer.getAddress(), cacheName); TestingUtil.replaceComponent(cacheContainer, LocalTopologyManager.class, controlledLocalTopologyManager, true); return controlledLocalTopologyManager; }
public static boolean areCacheViewsComplete(Cache[] caches, boolean barfIfTooManyMembers) { int memberCount = caches.length; for (Cache cache : caches) { EmbeddedCacheManager cacheManager = cache.getCacheManager(); if (!isCacheViewComplete(cacheManager.getMembers(), cacheManager.getAddress(), memberCount, barfIfTooManyMembers)) { return false; } } return true; }
Address startNewMember() { joinerManager = addClusterEnabledCacheManager(); joinerManager.defineConfiguration(cacheName, configuration.build()); joiner = joinerManager.getCache(cacheName); return manager(joiner).getAddress(); }