Search in sources :

Example 1 with InjectedValue

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

the class HttpsListenerAdd method configureAdditionalDependencies.

@Override
void configureAdditionalDependencies(OperationContext context, ServiceBuilder<? extends UndertowListener> serviceBuilder, ModelNode model, ListenerService service) throws OperationFailedException {
    serviceBuilder.addDependency(HttpListenerAdd.REGISTRY_SERVICE_NAME, ListenerRegistry.class, ((HttpListenerService) service).getHttpListenerRegistry());
    ModelNode sslContextModel = HttpsListenerResourceDefinition.SSL_CONTEXT.resolveModelAttribute(context, model);
    ModelNode securityRealmModel = HttpsListenerResourceDefinition.SECURITY_REALM.resolveModelAttribute(context, model);
    final String sslContextRef = sslContextModel.isDefined() ? sslContextModel.asString() : null;
    final String securityRealmRef = securityRealmModel.isDefined() ? securityRealmModel.asString() : null;
    final InjectedValue<SSLContext> sslContextInjector = new InjectedValue<>();
    final InjectedValue<SecurityRealm> securityRealmInjector = new InjectedValue<>();
    if (securityRealmRef != null) {
        SecurityRealm.ServiceUtil.addDependency(serviceBuilder, securityRealmInjector, securityRealmRef, false);
    }
    if (sslContextRef != null) {
        String runtimeCapability = RuntimeCapability.buildDynamicCapabilityName(SSL_CONTEXT_CAPABILITY, sslContextRef);
        ServiceName sslContextServiceName = context.getCapabilityServiceName(runtimeCapability, SSLContext.class);
        serviceBuilder.addDependency(sslContextServiceName, SSLContext.class, sslContextInjector);
    }
    ((HttpsListenerService) service).setSSLContextSupplier(() -> {
        if (sslContextRef != null) {
            return sslContextInjector.getValue();
        }
        if (securityRealmRef != null) {
            SSLContext sslContext = securityRealmInjector.getValue().getSSLContext();
            if (sslContext == null) {
                throw UndertowLogger.ROOT_LOGGER.noSslContextInSecurityRealm(securityRealmRef);
            }
            return sslContext;
        }
        try {
            return SSLContext.getDefault();
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    });
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) ServiceName(org.jboss.msc.service.ServiceName) SecurityRealm(org.jboss.as.domain.management.SecurityRealm) SSLContext(javax.net.ssl.SSLContext) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 2 with InjectedValue

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

the class ModClusterSubsystemAdd method performBoottime.

@Override
public void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    ServiceTarget target = context.getServiceTarget();
    final ModelNode fullModel = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
    final ModelNode modelConfig = fullModel.get(ModClusterConfigResourceDefinition.PATH.getKeyValuePair());
    ModClusterConfigurationServiceBuilder configurationBuilder = new ModClusterConfigurationServiceBuilder();
    configurationBuilder.configure(context, modelConfig).build(target).install();
    // Construct LoadBalanceFactorProvider and call pluggable boot time handlers.
    Set<LoadMetric> metrics = new HashSet<>();
    final LoadBalanceFactorProvider loadProvider = getModClusterLoadProvider(metrics, context, modelConfig);
    for (BoottimeHandlerProvider handler : ServiceLoader.load(BoottimeHandlerProvider.class, BoottimeHandlerProvider.class.getClassLoader())) {
        handler.performBoottime(metrics, context, operation, modelConfig);
    }
    final String connector = CONNECTOR.resolveModelAttribute(context, modelConfig).asString();
    final int statusInterval = STATUS_INTERVAL.resolveModelAttribute(context, modelConfig).asInt();
    InjectedValue<ModClusterConfiguration> modClusterConfiguration = new InjectedValue<>();
    ContainerEventHandlerService service = new ContainerEventHandlerService(modClusterConfiguration, loadProvider);
    // Install the main service
    new AsynchronousServiceBuilder<>(ContainerEventHandlerService.SERVICE_NAME, service).build(target).addDependency(configurationBuilder.getServiceName(), ModClusterConfiguration.class, modClusterConfiguration).setInitialMode(Mode.ACTIVE).install();
    // Install services for web container integration
    for (ContainerEventHandlerAdapterBuilder adapterBuilder : ServiceLoader.load(ContainerEventHandlerAdapterBuilder.class, ContainerEventHandlerAdapterBuilder.class.getClassLoader())) {
        adapterBuilder.build(target, connector, statusInterval).setInitialMode(Mode.PASSIVE).install();
    }
}
Also used : ModClusterConfiguration(org.jboss.modcluster.config.ModClusterConfiguration) InjectedValue(org.jboss.msc.value.InjectedValue) ServiceTarget(org.jboss.msc.service.ServiceTarget) LoadBalanceFactorProvider(org.jboss.modcluster.load.LoadBalanceFactorProvider) SimpleLoadBalanceFactorProvider(org.jboss.modcluster.load.impl.SimpleLoadBalanceFactorProvider) DynamicLoadBalanceFactorProvider(org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProvider) LoadMetric(org.jboss.modcluster.load.metric.LoadMetric) AsynchronousServiceBuilder(org.wildfly.clustering.service.AsynchronousServiceBuilder) ModelNode(org.jboss.dmr.ModelNode) HashSet(java.util.HashSet)

Example 3 with InjectedValue

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

the class NodeServicePolicyActivator method activate.

@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    try {
        SingletonPolicy policy = (SingletonPolicy) context.getServiceRegistry().getRequiredService(ServiceName.parse(SingletonDefaultRequirement.SINGLETON_POLICY.getName())).awaitValue();
        InjectedValue<Group> group = new InjectedValue<>();
        NodeService service = new NodeService(group);
        policy.createSingletonServiceBuilder(SERVICE_NAME, service).build(context.getServiceTarget()).addDependency(ServiceName.parse("org.wildfly.clustering.default-group"), Group.class, group).install();
    } catch (InterruptedException e) {
        throw new ServiceRegistryException(e);
    }
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) Group(org.wildfly.clustering.group.Group) SingletonPolicy(org.wildfly.clustering.singleton.SingletonPolicy) ServiceRegistryException(org.jboss.msc.service.ServiceRegistryException)

Example 4 with InjectedValue

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

the class SingletonServiceActivator method install.

private static void install(ServiceTarget target, SingletonServiceBuilderFactory factory, ServiceName name, String preferredNode) {
    InjectedValue<Group> group = new InjectedValue<>();
    NodeService service = new NodeService(group);
    factory.createSingletonServiceBuilder(name, service).electionPolicy(new PreferredSingletonElectionPolicy(new SimpleSingletonElectionPolicy(), new NamePreference(preferredNode))).build(target).addDependency(ServiceName.JBOSS.append("clustering", "group", "default"), Group.class, group).install();
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) Group(org.wildfly.clustering.group.Group) NamePreference(org.wildfly.clustering.singleton.election.NamePreference) NodeService(org.jboss.as.test.clustering.cluster.singleton.service.NodeService) SimpleSingletonElectionPolicy(org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy) PreferredSingletonElectionPolicy(org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy)

Example 5 with InjectedValue

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

the class ServiceActivator method activate.

@Override
public void activate(ServiceActivatorContext serviceActivatorContext) {
    try {
        SingletonPolicy policy = (SingletonPolicy) serviceActivatorContext.getServiceRegistry().getRequiredService(ServiceName.parse(SingletonDefaultRequirement.SINGLETON_POLICY.getName())).awaitValue();
        InjectedValue<Group> group = new InjectedValue<>();
        Service<Node> service = new SingletonService(group);
        policy.createSingletonServiceBuilder(SINGLETON_SERVICE_NAME, service).build(serviceActivatorContext.getServiceTarget()).addDependency(ServiceName.parse("org.wildfly.clustering.default-group"), Group.class, group).install();
        serviceActivatorContext.getServiceTarget().addService(QUERYING_SERVICE_NAME, new QueryingService()).setInitialMode(ServiceController.Mode.ACTIVE).install();
        LOG.info("Singleton and querying services activated.");
    } catch (InterruptedException e) {
        throw new ServiceRegistryException(e);
    }
}
Also used : Group(org.wildfly.clustering.group.Group) InjectedValue(org.jboss.msc.value.InjectedValue) SingletonPolicy(org.wildfly.clustering.singleton.SingletonPolicy) Node(org.wildfly.clustering.group.Node) ServiceRegistryException(org.jboss.msc.service.ServiceRegistryException)

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