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);
}
});
}
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();
}
}
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);
}
}
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();
}
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);
}
}
Aggregations