Search in sources :

Example 1 with Registry

use of org.wildfly.clustering.registry.Registry in project wildfly by wildfly.

the class CacheRegistry method topologyChanged.

@TopologyChanged
public void topologyChanged(TopologyChangedEvent<Node, Map.Entry<K, V>> event) {
    if (event.isPre())
        return;
    ConsistentHash previousHash = event.getConsistentHashAtStart();
    List<Address> previousMembers = previousHash.getMembers();
    ConsistentHash hash = event.getConsistentHashAtEnd();
    List<Address> members = hash.getMembers();
    Address localAddress = event.getCache().getCacheManager().getAddress();
    // Determine which nodes have left the cache view
    Set<Address> addresses = new HashSet<>(previousMembers);
    addresses.removeAll(members);
    try {
        this.topologyChangeExecutor.submit(() -> {
            if (!addresses.isEmpty()) {
                // We're only interested in the entries for which we are the primary owner
                List<Node> nodes = addresses.stream().filter(address -> hash.locatePrimaryOwner(address).equals(localAddress)).map(address -> this.factory.createNode(address)).collect(Collectors.toList());
                if (!nodes.isEmpty()) {
                    Cache<Node, Map.Entry<K, V>> cache = this.cache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS);
                    Map<K, V> removed = new HashMap<>();
                    try (Batch batch = this.batcher.createBatch()) {
                        for (Node node : nodes) {
                            Map.Entry<K, V> old = cache.remove(node);
                            if (old != null) {
                                removed.put(old.getKey(), old.getValue());
                            }
                        }
                    } catch (CacheException e) {
                        ClusteringServerLogger.ROOT_LOGGER.registryPurgeFailed(e, this.cache.getCacheManager().toString(), this.cache.getName(), nodes);
                    }
                    // Invoke listeners outside above tx context
                    if (!removed.isEmpty()) {
                        this.notifyListeners(Event.Type.CACHE_ENTRY_REMOVED, removed);
                    }
                }
            } else {
                // This is a merge after cluster split: re-populate the cache registry with lost registry entries
                if (!previousMembers.contains(localAddress)) {
                    // If this node is not a member at merge start, its mapping is lost and needs to be recreated and listeners notified
                    try {
                        this.populateRegistry();
                        // Local cache events do not trigger notifications
                        this.notifyListeners(Event.Type.CACHE_ENTRY_CREATED, this.entry);
                    } catch (CacheException e) {
                        ClusteringServerLogger.ROOT_LOGGER.failedToRestoreLocalRegistryEntry(e, this.cache.getCacheManager().toString(), this.cache.getName());
                    }
                }
            }
        });
    } catch (RejectedExecutionException e) {
    // Executor was shutdown
    }
}
Also used : CacheEntryRemoved(org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved) TopologyChanged(org.infinispan.notifications.cachelistener.annotation.TopologyChanged) ClusteringLogger(org.jboss.as.clustering.logging.ClusteringLogger) HashMap(java.util.HashMap) Cache(org.infinispan.Cache) HashSet(java.util.HashSet) ClassLoaderThreadFactory(org.wildfly.clustering.service.concurrent.ClassLoaderThreadFactory) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Map(java.util.Map) CacheEntryModified(org.infinispan.notifications.cachelistener.annotation.CacheEntryModified) CacheEntryRemovedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent) ThreadFactory(java.util.concurrent.ThreadFactory) NodeFactory(org.wildfly.clustering.group.NodeFactory) ExecutorService(java.util.concurrent.ExecutorService) Address(org.infinispan.remoting.transport.Address) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) CacheException(org.infinispan.commons.CacheException) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) Batcher(org.wildfly.clustering.ee.Batcher) Registry(org.wildfly.clustering.registry.Registry) Group(org.wildfly.clustering.group.Group) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PrivilegedAction(java.security.PrivilegedAction) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TopologyChangedEvent(org.infinispan.notifications.cachelistener.event.TopologyChangedEvent) TimeUnit(java.util.concurrent.TimeUnit) CacheEntryCreated(org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated) AbstractMap(java.util.AbstractMap) List(java.util.List) WildFlySecurityManager(org.wildfly.security.manager.WildFlySecurityManager) Flag(org.infinispan.context.Flag) KeyFilter(org.infinispan.filter.KeyFilter) CacheEntryEvent(org.infinispan.notifications.cachelistener.event.CacheEntryEvent) Batch(org.wildfly.clustering.ee.Batch) Event(org.infinispan.notifications.cachelistener.event.Event) Node(org.wildfly.clustering.group.Node) ClusteringServerLogger(org.wildfly.clustering.server.logging.ClusteringServerLogger) Collections(java.util.Collections) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) Address(org.infinispan.remoting.transport.Address) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CacheException(org.infinispan.commons.CacheException) Node(org.wildfly.clustering.group.Node) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Batch(org.wildfly.clustering.ee.Batch) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AbstractMap(java.util.AbstractMap) HashSet(java.util.HashSet) TopologyChanged(org.infinispan.notifications.cachelistener.annotation.TopologyChanged)

Example 2 with Registry

use of org.wildfly.clustering.registry.Registry in project wildfly by wildfly.

the class RegistryServiceConfigurator method build.

@Override
public ServiceBuilder<?> build(ServiceTarget target) {
    ServiceBuilder<?> builder = new AsyncServiceConfigurator(this.getServiceName()).build(target);
    Consumer<Registry<K, V>> registry = new CompositeDependency(this.factory, this.entry).register(builder).provides(this.getServiceName());
    Service service = new FunctionalService<>(registry, Function.identity(), this, Consumers.close());
    return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Also used : FunctionalService(org.wildfly.clustering.service.FunctionalService) AsyncServiceConfigurator(org.wildfly.clustering.service.AsyncServiceConfigurator) FunctionalService(org.wildfly.clustering.service.FunctionalService) Service(org.jboss.msc.Service) Registry(org.wildfly.clustering.registry.Registry) CompositeDependency(org.wildfly.clustering.service.CompositeDependency)

Example 3 with Registry

use of org.wildfly.clustering.registry.Registry in project wildfly by wildfly.

the class AssociationService method start.

@Override
public void start(final StartContext context) throws StartException {
    // todo suspendController
    // noinspection unchecked
    List<Map.Entry<ProtocolSocketBinding, Registry<String, List<ClientMapping>>>> clientMappingsRegistries = this.clientMappingsRegistries.isEmpty() ? Collections.emptyList() : new ArrayList<>(this.clientMappingsRegistries.size());
    for (Map.Entry<Value<ProtocolSocketBinding>, Value<Registry>> entry : this.clientMappingsRegistries) {
        clientMappingsRegistries.add(new SimpleImmutableEntry<>(entry.getKey().getValue(), entry.getValue().getValue()));
    }
    value = new AssociationImpl(deploymentRepositoryInjector.getValue(), clientMappingsRegistries);
    String ourNodeName = serverEnvironmentServiceInjector.getValue().getNodeName();
    // track deployments at an association level for local dispatchers to utilize
    moduleAvailabilityListener = value.registerModuleAvailabilityListener(new ModuleAvailabilityListener() {

        public void moduleAvailable(final List<EJBModuleIdentifier> modules) {
            synchronized (serviceLock) {
                ourModules.addAll(modules);
                cachedServiceURL = null;
            }
        }

        public void moduleUnavailable(final List<EJBModuleIdentifier> modules) {
            synchronized (serviceLock) {
                ourModules.removeAll(modules);
                cachedServiceURL = null;
            }
        }
    });
    // do this last
    mutableDiscoveryProvider.setDiscoveryProvider((serviceType, filterSpec, result) -> {
        ServiceURL serviceURL = this.cachedServiceURL;
        if (serviceURL == null) {
            synchronized (serviceLock) {
                serviceURL = this.cachedServiceURL;
                if (serviceURL == null) {
                    ServiceURL.Builder b = new ServiceURL.Builder();
                    b.setUri(Affinity.LOCAL.getUri()).setAbstractType("ejb").setAbstractTypeAuthority("jboss");
                    b.addAttribute(EJBClientContext.FILTER_ATTR_NODE, AttributeValue.fromString(ourNodeName));
                    for (Map.Entry<ProtocolSocketBinding, Registry<String, List<ClientMapping>>> entry : clientMappingsRegistries) {
                        Group group = entry.getValue().getGroup();
                        if (!group.isSingleton()) {
                            b.addAttribute(EJBClientContext.FILTER_ATTR_CLUSTER, AttributeValue.fromString(group.getName()));
                        }
                    }
                    for (EJBModuleIdentifier moduleIdentifier : ourModules) {
                        final String appName = moduleIdentifier.getAppName();
                        final String moduleName = moduleIdentifier.getModuleName();
                        final String distinctName = moduleIdentifier.getDistinctName();
                        if (distinctName.isEmpty()) {
                            if (appName.isEmpty()) {
                                b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(moduleName));
                            } else {
                                b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(appName + '/' + moduleName));
                            }
                        } else {
                            if (appName.isEmpty()) {
                                b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(moduleName + '/' + distinctName));
                            } else {
                                b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(appName + '/' + moduleName + '/' + distinctName));
                            }
                        }
                    }
                    serviceURL = this.cachedServiceURL = b.create();
                }
            }
        }
        if (serviceURL.satisfies(filterSpec)) {
            result.addMatch(serviceURL);
        }
        result.complete();
        return DiscoveryRequest.NULL;
    });
}
Also used : Group(org.wildfly.clustering.group.Group) EJBModuleIdentifier(org.jboss.ejb.client.EJBModuleIdentifier) Registry(org.wildfly.clustering.registry.Registry) ModuleAvailabilityListener(org.jboss.ejb.server.ModuleAvailabilityListener) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) ProtocolSocketBinding(org.jboss.as.network.ProtocolSocketBinding) Value(org.jboss.msc.value.Value) AttributeValue(org.wildfly.discovery.AttributeValue) InjectedValue(org.jboss.msc.value.InjectedValue) ServiceURL(org.wildfly.discovery.ServiceURL) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ClientMapping(org.jboss.as.network.ClientMapping) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Aggregations

Registry (org.wildfly.clustering.registry.Registry)3 AbstractMap (java.util.AbstractMap)2 List (java.util.List)2 Map (java.util.Map)2 Group (org.wildfly.clustering.group.Group)2 PrivilegedAction (java.security.PrivilegedAction)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1