Search in sources :

Example 16 with InjectedValue

use of org.jboss.msc.value.InjectedValue in project wildfly by wildfly.

the class RemotingProfileAdd method installServices.

protected void installServices(final OperationContext context, final PathAddress address, final ModelNode profileNode) throws OperationFailedException {
    try {
        final ModelNode staticEjbDiscoery = StaticEJBDiscoveryDefinition.INSTANCE.resolveModelAttribute(context, profileNode);
        List<StaticEJBDiscoveryDefinition.StaticEjbDiscovery> discoveryList = StaticEJBDiscoveryDefinition.createStaticEjbList(context, staticEjbDiscoery);
        final List<ServiceURL> urls = new ArrayList<>();
        for (StaticEJBDiscoveryDefinition.StaticEjbDiscovery resource : discoveryList) {
            ServiceURL.Builder builder = new ServiceURL.Builder();
            builder.setAbstractType("ejb").setAbstractTypeAuthority("jboss").setUri(new URI(resource.getUrl()));
            String distinctName = resource.getDistinct() == null ? "" : resource.getDistinct();
            String appName = resource.getApp() == null ? "" : resource.getApp();
            String moduleName = resource.getModule();
            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));
                }
            }
            urls.add(builder.create());
        }
        final Map<String, RemotingProfileService.RemotingConnectionSpec> map = new HashMap<>();
        final List<RemotingProfileService.HttpConnectionSpec> httpConnectionSpecs = new ArrayList<>();
        final RemotingProfileService profileService = new RemotingProfileService(urls, map, httpConnectionSpecs);
        // populating the map after the fact is cheating, but it works thanks to the MSC start service "fence"
        final CapabilityServiceBuilder capabilityServiceBuilder = context.getCapabilityServiceTarget().addCapability(RemotingProfileResourceDefinition.REMOTING_PROFILE_CAPABILITY, profileService);
        if (profileNode.hasDefined(EJB3SubsystemModel.REMOTING_EJB_RECEIVER)) {
            for (final Property receiverProperty : profileNode.get(EJB3SubsystemModel.REMOTING_EJB_RECEIVER).asPropertyList()) {
                final ModelNode receiverNode = receiverProperty.getValue();
                final String connectionRef = RemotingEjbReceiverDefinition.OUTBOUND_CONNECTION_REF.resolveModelAttribute(context, receiverNode).asString();
                final long timeout = RemotingEjbReceiverDefinition.CONNECT_TIMEOUT.resolveModelAttribute(context, receiverNode).asLong();
                final InjectedValue<OutboundConnection> connectionInjector = new InjectedValue<>();
                capabilityServiceBuilder.addCapabilityRequirement(OUTBOUND_CONNECTION_CAPABILITY_NAME, OutboundConnection.class, connectionInjector, connectionRef);
                final ModelNode channelCreationOptionsNode = receiverNode.get(EJB3SubsystemModel.CHANNEL_CREATION_OPTIONS);
                OptionMap channelCreationOptions = createChannelOptionMap(context, channelCreationOptionsNode);
                map.put(connectionRef, new RemotingProfileService.RemotingConnectionSpec(connectionRef, connectionInjector, channelCreationOptions, timeout));
            }
        }
        final boolean isLocalReceiverExcluded = RemotingProfileResourceDefinition.EXCLUDE_LOCAL_RECEIVER.resolveModelAttribute(context, profileNode).asBoolean();
        if (profileNode.hasDefined(EJB3SubsystemModel.REMOTE_HTTP_CONNECTION)) {
            for (final Property receiverProperty : profileNode.get(EJB3SubsystemModel.REMOTE_HTTP_CONNECTION).asPropertyList()) {
                final ModelNode receiverNode = receiverProperty.getValue();
                final String uri = RemoteHttpConnectionDefinition.URI.resolveModelAttribute(context, receiverNode).asString();
                httpConnectionSpecs.add(new RemotingProfileService.HttpConnectionSpec(uri));
            }
        }
        // if the local receiver is enabled for this context, then add a dependency on the appropriate LocalEjbReceive service
        if (!isLocalReceiverExcluded) {
            final ModelNode passByValueNode = RemotingProfileResourceDefinition.LOCAL_RECEIVER_PASS_BY_VALUE.resolveModelAttribute(context, profileNode);
            if (passByValueNode.isDefined()) {
                final ServiceName localTransportProviderServiceName = passByValueNode.asBoolean() == true ? LocalTransportProvider.BY_VALUE_SERVICE_NAME : LocalTransportProvider.BY_REFERENCE_SERVICE_NAME;
                capabilityServiceBuilder.addDependency(localTransportProviderServiceName, EJBTransportProvider.class, profileService.getLocalTransportProviderInjector());
            } else {
                // setup a dependency on the default local Jakarta Enterprise Beans receiver service configured at the subsystem level
                capabilityServiceBuilder.addDependency(LocalTransportProvider.DEFAULT_LOCAL_TRANSPORT_PROVIDER_SERVICE_NAME, EJBTransportProvider.class, profileService.getLocalTransportProviderInjector());
            }
        }
        capabilityServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    } catch (IllegalArgumentException | URISyntaxException e) {
        throw new OperationFailedException(e.getLocalizedMessage());
    }
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) OutboundConnection(org.jboss.as.network.OutboundConnection) HashMap(java.util.HashMap) CapabilityServiceBuilder(org.jboss.as.controller.CapabilityServiceBuilder) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ServiceURL(org.wildfly.discovery.ServiceURL) RemotingProfileService(org.jboss.as.ejb3.remote.RemotingProfileService) Property(org.jboss.dmr.Property) OperationFailedException(org.jboss.as.controller.OperationFailedException) CapabilityServiceBuilder(org.jboss.as.controller.CapabilityServiceBuilder) ServiceName(org.jboss.msc.service.ServiceName) OptionMap(org.xnio.OptionMap) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

InjectedValue (org.jboss.msc.value.InjectedValue)16 ServiceName (org.jboss.msc.service.ServiceName)7 HashMap (java.util.HashMap)5 ModelNode (org.jboss.dmr.ModelNode)5 Group (org.wildfly.clustering.group.Group)5 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)4 HashSet (java.util.HashSet)3 OperationFailedException (org.jboss.as.controller.OperationFailedException)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 Module (org.jboss.modules.Module)3 ArrayList (java.util.ArrayList)2 ManagementHome (javax.management.j2ee.ManagementHome)2 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)2 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)2 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)2 ComponentView (org.jboss.as.ee.component.ComponentView)2 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)2 DeploymentModuleIdentifier (org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier)2 EjbDeploymentInformation (org.jboss.as.ejb3.deployment.EjbDeploymentInformation)2