Refine search
public CacheLocality(Cache<?, ?> cache) { DistributionManager dist = cache.getAdvancedCache().getDistributionManager(); this.locality = (dist != null) ? new ConsistentHashLocality(dist.getCacheTopology()) : new SimpleLocality(true); }
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(); }
@Merged @ViewChanged public void viewChanged(ViewChangedEvent event) { if (this.cache.getAdvancedCache().getDistributionManager() != null) { // Record view status for use by @TopologyChanged event this.views.put(event.getViewId(), event.isMergeView()); } else if (!this.listeners.isEmpty()) { Membership previousMembership = new CacheMembership(event.getLocalAddress(), event.getOldMembers(), this); Membership membership = new CacheMembership(event.getLocalAddress(), event.getNewMembers(), this); 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, event.isMergeView()); } catch (Throwable e) { ClusteringServerLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e); } }); } catch (RejectedExecutionException e) { // Listener was unregistered } } } }
@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); }
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 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; } }
/** * {@inheritDoc} * @see org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager#isLocal(java.lang.String) */ @Override public boolean isLocal(String sessionId) { DistributionManager manager = this.sessionCache.getAdvancedCache().getDistributionManager(); return (manager != null) ? manager.isLocal(sessionId) : true; }
private Address locatePrimaryOwner(String sessionId) { DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); return (dist != null) ? dist.getPrimaryLocation(sessionId) : this.cache.getCacheManager().getAddress(); }
private void mockRehashInProgress(String cacheName, Cache mockedCache, AdvancedCache mockedAdvancedCache, DistributionManager mockedDistributionManager) { when(mockedCacheManager.getCache(cacheName, false)).thenReturn(mockedCache); when(mockedCache.getAdvancedCache()).thenReturn(mockedAdvancedCache); when(mockedCache.getStatus()).thenReturn(INSTANTIATED); when(mockedAdvancedCache.getDistributionManager()).thenReturn(mockedDistributionManager); when(mockedDistributionManager.isRehashInProgress()).thenReturn(true); }
public static boolean isOwner(Cache<?, ?> c, Object key) { DistributionManager dm = c.getAdvancedCache().getDistributionManager(); List<Address> ownerAddresses = dm.locate(key); return ownerAddresses.contains(addressOf(c)); }
public static boolean isFirstOwner(Cache<?, ?> c, Object key) { DistributionManager dm = c.getAdvancedCache().getDistributionManager(); Address primaryOwnerAddress = dm.getPrimaryLocation(key); return addressOf(c).equals(primaryOwnerAddress); }
public static boolean hasOwners(Object key, Cache<?, ?> primaryOwner, Cache<?, ?>... backupOwners) { DistributionManager dm = primaryOwner.getAdvancedCache().getDistributionManager(); List<Address> ownerAddresses = dm.locate(key); if (!addressOf(primaryOwner).equals(ownerAddresses.get(0))) return false; for (int i = 0; i < backupOwners.length; i++) { if (!ownerAddresses.contains(addressOf(backupOwners[i]))) return false; } return true; }
public void assertConsistentHashMembers(List<org.infinispan.remoting.transport.Address> expectedMembers) { for (Cache c : cachesInThisPartition()) { assertEquals(new HashSet<>(c.getAdvancedCache().getDistributionManager().getCacheTopology().getMembers()), new HashSet<>(expectedMembers)); } }
private Object[] getKeys(boolean isOwner, int num) { return IntStream.iterate(0, i -> i + 1) .mapToObj(i -> "key" + i) .filter(k -> cache(0, DIST).getAdvancedCache().getDistributionManager().getLocality(k).isLocal() == isOwner) .limit(num).toArray(Object[]::new); } }
private String getStringKeyForCache(Cache cache) { LocalizedCacheTopology topology = cache.getAdvancedCache().getDistributionManager().getCacheTopology(); return IntStream.generate(ThreadLocalRandom.current()::nextInt).mapToObj(i -> "key" + i) .filter(key -> topology.getDistribution(key).isPrimary()).findAny().get(); }
private int currentTopologyId(Cache cache) { return cache.getAdvancedCache().getDistributionManager().getCacheTopology().getTopologyId(); }
public void testDistributionFromNonOwner() throws Exception { Object key = "testDistributionFromNonOwner"; doTestDistribution(key, cacheManagers.stream() .map(cm -> cm.<Object, Integer>getCache(DIST).getAdvancedCache()) .filter(cache -> !cache.getDistributionManager().getCacheTopology().isWriteOwner(key)) .findAny() .get()); }
public void testDistributionFromSecondaryOwner() throws Exception { Object key = "testDistributionFromSecondaryOwner"; doTestDistribution(key, cacheManagers.stream() .map(cm -> cm.<Object, Integer>getCache(DIST).getAdvancedCache()) // owner... .filter(cache -> cache.getDistributionManager().getCacheTopology().getDistribution(key).isWriteBackup()) .findAny() .get()); }
public static byte[] newKey(Cache<?, ?> cache) throws Exception { LocalizedCacheTopology cacheTopology = cache.getAdvancedCache().getDistributionManager().getCacheTopology(); Random r = new Random(); JBossMarshaller sm = new JBossMarshaller(); for (int i = 0; i < 1000; i++) { String candidate = String.valueOf(r.nextLong()); byte[] candidateBytes = sm.objectToByteBuffer(candidate, 64); if (cacheTopology.isReadOwner(candidateBytes)) { return candidateBytes; } } throw new RuntimeException("Unable to find a key local to node " + cache); }
public void assertActualMembers() { Set<org.infinispan.remoting.transport.Address> expected = cachesInThisPartition().stream() .map(c -> c.getAdvancedCache().getRpcManager().getAddress()) .collect(Collectors.toSet()); for (Cache c : cachesInThisPartition()) { eventuallyEquals(expected, () -> new HashSet<>(c.getAdvancedCache().getDistributionManager().getCacheTopology().getActualMembers())); } }