use of org.jboss.msc.service.ServiceTarget in project wildfly by wildfly.
the class DiscoveryGroupAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
final String name = address.getLastElement().getValue();
ServiceRegistry registry = context.getServiceRegistry(false);
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
ServiceController<?> service = registry.getService(serviceName);
if (service != null) {
context.reloadRequired();
} else {
final ServiceTarget target = context.getServiceTarget();
if (model.hasDefined(JGROUPS_CHANNEL.getName())) {
// nothing to do, in that case, the clustering.jgroups subsystem will have setup the stack
} else if (model.hasDefined(RemoteTransportDefinition.SOCKET_BINDING.getName())) {
final GroupBindingService bindingService = new GroupBindingService();
target.addService(GroupBindingService.getDiscoveryBaseServiceName(serviceName).append(name), bindingService).addDependency(SocketBinding.JBOSS_BINDING_NAME.append(model.get(SOCKET_BINDING).asString()), SocketBinding.class, bindingService.getBindingRef()).install();
}
}
}
use of org.jboss.msc.service.ServiceTarget 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.service.ServiceTarget in project wildfly by wildfly.
the class ParsedServiceDeploymentProcessor method deploy.
/**
* Process a deployment for JbossService configuration. Will install a {@code JBossService} for each configured service.
*
* @param phaseContext the deployment unit context
* @throws DeploymentUnitProcessingException
*/
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final JBossServiceXmlDescriptor serviceXmlDescriptor = deploymentUnit.getAttachment(JBossServiceXmlDescriptor.ATTACHMENT_KEY);
if (serviceXmlDescriptor == null) {
// Skip deployments without a service xml descriptor
return;
}
// assert module
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
if (module == null)
throw SarLogger.ROOT_LOGGER.failedToGetAttachment("module", deploymentUnit);
// assert reflection index
final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX);
if (reflectionIndex == null)
throw SarLogger.ROOT_LOGGER.failedToGetAttachment("reflection index", deploymentUnit);
// install services
final ClassLoader classLoader = module.getClassLoader();
final List<JBossServiceConfig> serviceConfigs = serviceXmlDescriptor.getServiceConfigs();
final ServiceTarget target = phaseContext.getServiceTarget();
final Map<String, ServiceComponentInstantiator> serviceComponents = deploymentUnit.getAttachment(ServiceAttachments.SERVICE_COMPONENT_INSTANTIATORS);
for (final JBossServiceConfig serviceConfig : serviceConfigs) {
addServices(target, serviceConfig, classLoader, reflectionIndex, serviceComponents != null ? serviceComponents.get(serviceConfig.getName()) : null, phaseContext);
}
}
use of org.jboss.msc.service.ServiceTarget in project wildfly by wildfly.
the class AbstractPojoPhase method startInternal.
protected void startInternal(StartContext context) throws StartException {
try {
executeInstalls();
// only after describe do we have a bean
if (getLifecycleState().isAfter(BeanState.DESCRIBED)) {
addCallbacks(true);
addCallbacks(false);
ServiceRegistry registry = context.getController().getServiceContainer();
InstancesService.addInstance(registry, context.getChildTarget(), getLifecycleState(), getBean());
}
// do we have a next phase
final AbstractPojoPhase nextPhase = createNextPhase();
if (nextPhase != null) {
final BeanState state = getLifecycleState();
final BeanState next = state.next();
final BeanMetaDataConfig beanConfig = getBeanConfig();
final ServiceName name = BeanMetaDataConfig.toBeanName(beanConfig.getName(), next);
final ServiceTarget serviceTarget = context.getChildTarget();
final ServiceBuilder serviceBuilder = serviceTarget.addService(name, nextPhase);
registerAliases(serviceBuilder, next);
final ConfigVisitor visitor = new DefaultConfigVisitor(serviceBuilder, state, getModule(), getIndex(), getBeanInfo());
beanConfig.visit(visitor);
nextPhase.setModule(getModule());
nextPhase.setBeanConfig(getBeanConfig());
nextPhase.setIndex(getIndex());
nextPhase.setBeanInfo(getBeanInfo());
nextPhase.setBean(getBean());
serviceBuilder.install();
}
} catch (Throwable t) {
throw new StartException(t);
}
}
use of org.jboss.msc.service.ServiceTarget in project wildfly by wildfly.
the class SingletonServiceActivator method activate.
@Override
public void activate(ServiceActivatorContext context) {
try {
SingletonServiceBuilderFactory factory = (SingletonServiceBuilderFactory) context.getServiceRegistry().getRequiredService(SingletonServiceName.BUILDER.getServiceName(CONTAINER_NAME)).awaitValue();
ServiceTarget target = context.getServiceTarget();
install(target, factory, SERVICE_A_NAME, SERVICE_A_PREFERRED_NODE);
install(target, factory, SERVICE_B_NAME, SERVICE_B_PREFERRED_NODE);
} catch (InterruptedException e) {
throw new ServiceRegistryException(e);
}
}
Aggregations