public AffinityIdentifierFactory(IdentifierFactory<K> factory, Cache<Key<K>, ?> cache, KeyAffinityServiceFactory affinityFactory) { this.factory = factory; this.affinity = affinityFactory.createService(cache, this); this.manager = cache.getCacheManager(); }
@Override public boolean isSingleton() { return this.cache.getCacheManager().getTransport() == null; }
@Override public void close() { this.cache.removeListener(this); this.cache.getCacheManager().removeListener(this); // Cleanup any unregistered listeners for (ExecutorService executor : this.listeners.values()) { PrivilegedAction<List<Runnable>> action = () -> executor.shutdownNow(); WildFlySecurityManager.doUnchecked(action); } this.listeners.clear(); }
@Override public Node getLocalMember() { return this.createNode(this.cache.getCacheManager().getAddress()); }
@Override public int hashCode() { return this.cache.getCacheManager().getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName().hashCode() ^ this.cache.getName().hashCode(); }
@Override public boolean equals(Object object) { if ((object == null) || !(object instanceof InfinispanXAResourceRecovery)) return false; InfinispanXAResourceRecovery recovery = (InfinispanXAResourceRecovery) object; return this.cache.getCacheManager().getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName().equals(recovery.cache.getCacheManager().getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName()) && this.cache.getName().equals(recovery.cache.getName()); }
public CacheGroup(CacheGroupConfiguration config) { this.cache = config.getCache(); this.nodeFactory = config.getMemberFactory(); this.cache.getCacheManager().addListener(this); this.cache.addListener(this); }
@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 String toString() { return this.cache.getCacheManager().getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName() + "." + this.cache.getName(); } }
ClusteringServerLogger.ROOT_LOGGER.registryListenerFailed(e, this.cache.getCacheManager().getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName(), this.cache.getName(), type, entries);
@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); } };
ClusteringServerLogger.ROOT_LOGGER.registryPurgeFailed(e, this.cache.getCacheManager().toString(), this.cache.getName(), leftMembers); ClusteringServerLogger.ROOT_LOGGER.failedToRestoreLocalRegistryEntry(e, this.cache.getCacheManager().toString(), this.cache.getName());
@CacheEntryCreated @CacheEntryModified public void modified(CacheEntryEvent<T, Set<Address>> event) { if (event.isPre()) return; Map.Entry<Listener, ExecutorService> entry = this.listeners.get(event.getKey()); if (entry != null) { Listener listener = entry.getKey(); if (listener != null) { ExecutorService executor = entry.getValue(); Set<Node> members = new TreeSet<>(); for (Address address : event.getValue()) { members.add(this.group.createNode(address)); } try { executor.submit(() -> { try { listener.providersChanged(members); } catch (Throwable e) { ClusteringServerLogger.ROOT_LOGGER.serviceProviderRegistrationListenerFailed(e, this.cache.getCacheManager().getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName(), this.cache.getName(), members); } }); } catch (RejectedExecutionException e) { // Executor was shutdown } } } } }
@Override public String getName() { GlobalConfiguration global = this.cache.getCacheManager().getCacheManagerConfiguration(); TransportConfiguration transport = global.transport(); return transport.transport() != null ? transport.clusterName() : global.globalJmxStatistics().cacheManagerName(); }
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 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 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(); }
private static NodeController setNodeControllerIn(Cache<Object, Object> cache) { NodeController nodeController = new NodeController(); nodeController.interceptor = new ControlledCommandInterceptor(cache); nodeController.topologyManager = BlockingLocalTopologyManager.replaceTopologyManagerDefaultCache( cache.getCacheManager()); return nodeController; }
private void installNewView(Cache installing, Cache... cachesInView) { JGroupsTransport transport = (JGroupsTransport) installing.getCacheManager().getTransport(); JChannel channel = transport.getChannel(); org.jgroups.Address[] members = Stream.of(cachesInView) .map(c -> ((JGroupsAddress) address(c)).getJGroupsAddress()) .toArray(org.jgroups.Address[]::new); View view = View.create(members[0], transport.getViewId() + 1, members); ((GMS) channel.getProtocolStack().findProtocol(GMS.class)).installView(view); }