@Override public boolean isLocal(Object key) { return this.topology.getDistribution(key).isPrimary(); } }
Node locatePrimaryOwner(String sessionId) { DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); Address address = (dist != null) ? dist.getCacheTopology().getDistribution(new Key<>(sessionId)).primary() : null; Node node = (address != null) ? this.memberFactory.createNode(address) : null; return (node != null) ? node : this.group.getLocalMember(); }
public CacheLocality(Cache<?, ?> cache) { DistributionManager dist = cache.getAdvancedCache().getDistributionManager(); this.locality = (dist != null) ? new ConsistentHashLocality(dist.getCacheTopology()) : new SimpleLocality(true); }
protected LocalizedCacheTopology getCacheTopology(Cache<?, ?> c) { return getDistributionManager(c).getCacheTopology(); }
private void assertOwnershipConsensus(String key) { List l1 = getCacheTopology(c1).getDistribution(key).writeOwners(); List l2 = getCacheTopology(c2).getDistribution(key).writeOwners(); List l3 = getCacheTopology(c3).getDistribution(key).writeOwners(); List l4 = getCacheTopology(c4).getDistribution(key).writeOwners(); assertEquals("L1 "+l1+" and L2 "+l2+" don't agree.", l1, l2); assertEquals("L2 "+l2+" and L3 "+l3+" don't agree.", l2, l3); assertEquals("L3 "+l3+" and L4 "+l4+" don't agree.", l3, l4); }
@Override protected String[] parameterNames() { return concat(super.parameterNames(), "shared", "preload", "segmented"); }
@Override protected Object[] parameterValues() { return concat(super.parameterValues(), shared, preload, segmented); }
@Override protected void createCacheManagers() throws Throwable { addClusterEnabledCacheManager(buildCacheConfig("DistCacheStoreTxDisjointSetTest0")); addClusterEnabledCacheManager(buildCacheConfig("DistCacheStoreTxDisjointSetTest1")); addClusterEnabledCacheManager(buildCacheConfig("DistCacheStoreTxDisjointSetTest2")); waitForClusterToForm(); }
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); }
private void checkOwnership(MagicKey k1, MagicKey k2, String v1, String v2) { assertOnAllCachesAndOwnership(k1, v1); assertOnAllCachesAndOwnership(k2, v2); assertIsInL1(c4, k1); assertIsInL1(c4, k2); assertIsInL1(c1, k2); assertIsInL1(c3, k1); }
@Override protected Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable { if (!blockAfter) { blockIfNeeded(ctx, command); } return invokeNextAndFinally(ctx, command, (rCtx, rCommand, rv, t) -> { if (blockAfter) { blockIfNeeded(rCtx, rCommand); } }); } }
@Override public Object[] factory() { return new Object[] { new DistSyncStoreSharedTest().segmented(true), new DistSyncStoreSharedTest().segmented(false), }; }
@Override protected final boolean isOwner(Cache cache, Object key) { return DistributionTestHelper.isOwner(cache, key); } }
Node locatePrimaryOwner(I id) { DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); Address address = (dist != null) && !this.cache.getCacheConfiguration().clustering().cacheMode().isScattered() ? dist.getCacheTopology().getDistribution(new Key<>(id)).primary() : null; Node member = (address != null) ? this.nodeFactory.createNode(address) : null; return (member != null) ? member : this.registry.getGroup().getLocalMember(); }
@Override public Membership getMembership() { if (this.isSingleton()) { return new SingletonMembership(this.getLocalMember()); } Transport transport = this.cache.getCacheManager().getTransport(); DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); return (dist != null) ? new CacheMembership(transport.getAddress(), dist.getCacheTopology(), this) : new CacheMembership(transport, this); }
@Override protected final boolean isOwner(Cache cache, Object key) { return DistributionTestHelper.isOwner(cache, key); } }
@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; } }
@Override protected final boolean isOwner(Cache cache, Object key) { return DistributionTestHelper.isOwner(cache, key); } }