Search in sources :

Example 1 with ModuleAvailabilityListener

use of org.jboss.ejb.server.ModuleAvailabilityListener in project wildfly by wildfly.

the class AssociationImpl method registerModuleAvailabilityListener.

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

        public void listenerAdded(final DeploymentRepository repository) {
            List<ModuleAvailabilityListener.ModuleIdentifier> identifierList = new ArrayList<>();
            for (DeploymentModuleIdentifier identifier : repository.getModules().keySet()) {
                final ModuleAvailabilityListener.ModuleIdentifier moduleIdentifier = toModuleIdentifier(identifier);
                identifierList.add(moduleIdentifier);
            }
            moduleAvailabilityListener.moduleAvailable(identifierList);
        }

        private ModuleAvailabilityListener.ModuleIdentifier toModuleIdentifier(final DeploymentModuleIdentifier identifier) {
            return new ModuleAvailabilityListener.ModuleIdentifier(identifier.getApplicationName(), identifier.getModuleName(), identifier.getDistinctName());
        }

        public void deploymentAvailable(final DeploymentModuleIdentifier deployment, final ModuleDeployment moduleDeployment) {
            moduleAvailabilityListener.moduleAvailable(Collections.singletonList(toModuleIdentifier(deployment)));
        }

        public void deploymentStarted(final DeploymentModuleIdentifier deployment, final ModuleDeployment moduleDeployment) {
        }

        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)));
        }
    };
    deploymentRepository.addListener(listener);
    return () -> deploymentRepository.removeListener(listener);
}
Also used : ModuleDeployment(org.jboss.as.ejb3.deployment.ModuleDeployment) 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) DeploymentModuleIdentifier(org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier) ModuleAvailabilityListener(org.jboss.ejb.server.ModuleAvailabilityListener)

Example 2 with ModuleAvailabilityListener

use of org.jboss.ejb.server.ModuleAvailabilityListener in project wildfly by wildfly.

the class AssociationService method start.

public void start(final StartContext context) throws StartException {
    // todo suspendController
    value = new AssociationImpl(deploymentRepositoryInjector.getValue(), registryCollectorInjector.getValue());
    // register the fact that the local receiver can handle invocations targeted at its node name
    final ServiceURL.Builder builder = new ServiceURL.Builder();
    builder.setAbstractType("ejb").setAbstractTypeAuthority("jboss");
    builder.setUri(Affinity.LOCAL.getUri());
    builder.addAttribute(EJBClientContext.FILTER_ATTR_NODE, AttributeValue.fromString(serverEnvironmentServiceInjector.getValue().getNodeName()));
    serviceRegistration = getLocalRegistryProvider().registerService(builder.create());
    // track deployments at an association level for local dispatchers to utilize
    handle = value.registerModuleAvailabilityListener(new ModuleAvailabilityListener() {

        private final ConcurrentHashMap<ModuleIdentifier, ServiceRegistration> map = new ConcurrentHashMap<ModuleIdentifier, ServiceRegistration>();

        public void moduleAvailable(final List<ModuleIdentifier> modules) {
            for (ModuleIdentifier module : modules) {
                final String appName = module.getAppName();
                final String moduleName = module.getModuleName();
                final String distinctName = module.getDistinctName();
                final ServiceURL.Builder builder = new ServiceURL.Builder();
                builder.setUri(Affinity.LOCAL.getUri());
                builder.setAbstractType("ejb");
                builder.setAbstractTypeAuthority("jboss");
                if (distinctName.isEmpty()) {
                    if (appName.isEmpty()) {
                        builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(moduleName));
                    } else {
                        builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(appName + "/" + moduleName));
                    }
                } else {
                    if (appName.isEmpty()) {
                        builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(moduleName + "/" + distinctName));
                    } else {
                        builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(appName + "/" + moduleName + "/" + distinctName));
                    }
                }
                final ServiceRegistration serviceRegistration = localRegistry.registerService(builder.create());
                // should never conflict normally!
                map.putIfAbsent(module, serviceRegistration);
            }
        }

        public void moduleUnavailable(final List<ModuleIdentifier> modules) {
            for (ModuleIdentifier module : modules) {
                map.computeIfPresent(module, (i, old) -> {
                    old.close();
                    return null;
                });
            }
        }
    });
}
Also used : ServiceURL(org.wildfly.discovery.ServiceURL) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ModuleAvailabilityListener(org.jboss.ejb.server.ModuleAvailabilityListener) ServiceRegistration(org.wildfly.discovery.ServiceRegistration)

Aggregations

ModuleAvailabilityListener (org.jboss.ejb.server.ModuleAvailabilityListener)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)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 ServiceRegistration (org.wildfly.discovery.ServiceRegistration)1 ServiceURL (org.wildfly.discovery.ServiceURL)1