Search in sources :

Example 1 with ServiceRegistration

use of org.wildfly.discovery.ServiceRegistration 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

List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ModuleAvailabilityListener (org.jboss.ejb.server.ModuleAvailabilityListener)1 ServiceRegistration (org.wildfly.discovery.ServiceRegistration)1 ServiceURL (org.wildfly.discovery.ServiceURL)1