Search in sources :

Example 1 with EJBModuleIdentifier

use of org.jboss.ejb.client.EJBModuleIdentifier in project wildfly by wildfly.

the class AssociationImpl method registerModuleAvailabilityListener.

@Override
public ListenerHandle registerModuleAvailabilityListener(@NotNull final ModuleAvailabilityListener moduleAvailabilityListener) {
    final DeploymentRepositoryListener listener = new DeploymentRepositoryListener() {

        @Override
        public void listenerAdded(final DeploymentRepository repository) {
            List<EJBModuleIdentifier> list = new ArrayList<>();
            if (!repositoryIsSuspended()) {
                // only send out the initial list if the deployment repository (i.e. the server + clean transaction state) is not in a suspended state
                for (DeploymentModuleIdentifier deploymentModuleIdentifier : repository.getModules().keySet()) {
                    EJBModuleIdentifier ejbModuleIdentifier = toModuleIdentifier(deploymentModuleIdentifier);
                    list.add(ejbModuleIdentifier);
                }
                EjbLogger.EJB3_INVOCATION_LOGGER.debugf("Sending initial module availability to connecting client: server is not suspended");
            } else {
                // send out empty list if the deploymentRepository is suspended
                EjbLogger.EJB3_INVOCATION_LOGGER.debugf("Sending empty initial module availability to connecting client: server is suspended");
            }
            moduleAvailabilityListener.moduleAvailable(list);
        }

        @Override
        public void deploymentAvailable(final DeploymentModuleIdentifier deployment, final ModuleDeployment moduleDeployment) {
        }

        @Override
        public void deploymentStarted(final DeploymentModuleIdentifier deployment, final ModuleDeployment moduleDeployment) {
            // only send out moduleAvailability until module has started (WFLY-13009)
            moduleAvailabilityListener.moduleAvailable(Collections.singletonList(toModuleIdentifier(deployment)));
        }

        @Override
        public void deploymentRemoved(final DeploymentModuleIdentifier deployment) {
            moduleAvailabilityListener.moduleUnavailable(Collections.singletonList(toModuleIdentifier(deployment)));
        }

        @Override
        public void deploymentSuspended(DeploymentModuleIdentifier deployment) {
            moduleAvailabilityListener.moduleUnavailable(Collections.singletonList(toModuleIdentifier(deployment)));
        }

        @Override
        public void deploymentResumed(DeploymentModuleIdentifier deployment) {
            moduleAvailabilityListener.moduleAvailable(Collections.singletonList(toModuleIdentifier(deployment)));
        }

        private boolean repositoryIsSuspended() {
            return deploymentRepository.isSuspended();
        }
    };
    deploymentRepository.addListener(listener);
    return () -> deploymentRepository.removeListener(listener);
}
Also used : ModuleDeployment(org.jboss.as.ejb3.deployment.ModuleDeployment) EJBModuleIdentifier(org.jboss.ejb.client.EJBModuleIdentifier) DeploymentRepositoryListener(org.jboss.as.ejb3.deployment.DeploymentRepositoryListener) ArrayList(java.util.ArrayList) DeploymentModuleIdentifier(org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier) DeploymentRepository(org.jboss.as.ejb3.deployment.DeploymentRepository)

Example 2 with EJBModuleIdentifier

use of org.jboss.ejb.client.EJBModuleIdentifier 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

ArrayList (java.util.ArrayList)2 EJBModuleIdentifier (org.jboss.ejb.client.EJBModuleIdentifier)2 AbstractMap (java.util.AbstractMap)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 DeploymentModuleIdentifier (org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier)1 DeploymentRepository (org.jboss.as.ejb3.deployment.DeploymentRepository)1 DeploymentRepositoryListener (org.jboss.as.ejb3.deployment.DeploymentRepositoryListener)1 ModuleDeployment (org.jboss.as.ejb3.deployment.ModuleDeployment)1 ClientMapping (org.jboss.as.network.ClientMapping)1 ProtocolSocketBinding (org.jboss.as.network.ProtocolSocketBinding)1 ModuleAvailabilityListener (org.jboss.ejb.server.ModuleAvailabilityListener)1 InjectedValue (org.jboss.msc.value.InjectedValue)1 Value (org.jboss.msc.value.Value)1 Group (org.wildfly.clustering.group.Group)1 Registry (org.wildfly.clustering.registry.Registry)1 AttributeValue (org.wildfly.discovery.AttributeValue)1 ServiceURL (org.wildfly.discovery.ServiceURL)1