use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.
the class MailSessionAdd method installRuntimeServices.
static void installRuntimeServices(OperationContext context, PathAddress address, ModelNode fullModel) throws OperationFailedException {
String name = address.getLastElement().getValue();
final String jndiName = getJndiName(fullModel, context);
final ServiceTarget serviceTarget = context.getServiceTarget();
final MailSessionConfig config = from(context, fullModel);
final MailSessionService service = new MailSessionService(config);
final ServiceName serviceName = MAIL_SESSION_SERVICE_NAME.append(name);
final ServiceBuilder<?> mailSessionBuilder = serviceTarget.addService(serviceName, service);
addOutboundSocketDependency(service, mailSessionBuilder, config.getImapServer());
addCredentialStoreReference(config.getImapServer(), context, fullModel, mailSessionBuilder, MailSubsystemModel.IMAP_SERVER_PATH.getKey(), MailSubsystemModel.IMAP_SERVER_PATH.getValue());
addOutboundSocketDependency(service, mailSessionBuilder, config.getPop3Server());
addCredentialStoreReference(config.getPop3Server(), context, fullModel, mailSessionBuilder, MailSubsystemModel.POP3_SERVER_PATH.getKey(), MailSubsystemModel.POP3_SERVER_PATH.getValue());
addOutboundSocketDependency(service, mailSessionBuilder, config.getSmtpServer());
addCredentialStoreReference(config.getSmtpServer(), context, fullModel, mailSessionBuilder, MailSubsystemModel.SMTP_SERVER_PATH.getKey(), MailSubsystemModel.SMTP_SERVER_PATH.getValue());
for (CustomServerConfig server : config.getCustomServers()) {
if (server.getOutgoingSocketBinding() != null) {
addOutboundSocketDependency(service, mailSessionBuilder, server);
}
addCredentialStoreReference(server, context, fullModel, mailSessionBuilder, MailSubsystemModel.CUSTOM_SERVER_PATH.getKey(), server.getProtocol());
}
final ManagedReferenceFactory valueManagedReferenceFactory = new MailSessionManagedReferenceFactory(service);
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
final BinderService binderService = new BinderService(bindInfo.getBindName());
final ServiceBuilder<?> binderBuilder = serviceTarget.addService(bindInfo.getBinderServiceName(), binderService).addInjection(binderService.getManagedObjectInjector(), valueManagedReferenceFactory).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addListener(new AbstractServiceListener<Object>() {
public void transition(final ServiceController<? extends Object> controller, final ServiceController.Transition transition) {
switch(transition) {
case STARTING_to_UP:
{
MailLogger.ROOT_LOGGER.boundMailSession(jndiName);
break;
}
case START_REQUESTED_to_DOWN:
{
MailLogger.ROOT_LOGGER.unboundMailSession(jndiName);
break;
}
case REMOVING_to_REMOVED:
{
MailLogger.ROOT_LOGGER.removedMailSession(jndiName);
break;
}
}
}
});
mailSessionBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
}
use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.
the class ApplicationContextProcessor method deploy.
/**
* Add a ContextService for this module.
*
* @param phaseContext the deployment unit context
* @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException
*/
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (deploymentUnit.getParent() != null) {
return;
}
EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
final ServiceName applicationContextServiceName = ContextNames.contextServiceNameOfApplication(moduleDescription.getApplicationName());
final NamingStoreService contextService = new NamingStoreService(true);
serviceTarget.addService(applicationContextServiceName, contextService).install();
final BinderService applicationNameBinder = new BinderService("AppName");
final ServiceName appNameServiceName = applicationContextServiceName.append("AppName");
serviceTarget.addService(appNameServiceName, applicationNameBinder).addDependency(applicationContextServiceName, ServiceBasedNamingStore.class, applicationNameBinder.getNamingStoreInjector()).addInjection(applicationNameBinder.getManagedObjectInjector(), new ValueManagedReferenceFactory(Values.immediateValue(moduleDescription.getApplicationName()))).install();
deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, appNameServiceName);
deploymentUnit.putAttachment(Attachments.APPLICATION_CONTEXT_CONFIG, applicationContextServiceName);
}
use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.
the class InstanceNameBindingProcessor method bindServices.
private void bindServices(DeploymentUnit deploymentUnit, ServiceTarget serviceTarget, ServiceName contextServiceName) {
final ServiceName instanceNameServiceName = contextServiceName.append("InstanceName");
final BinderService instanceNameService = new BinderService("InstanceName");
serviceTarget.addService(instanceNameServiceName, instanceNameService).addDependency(contextServiceName, ServiceBasedNamingStore.class, instanceNameService.getNamingStoreInjector()).addDependency(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class, new Injector<ServerEnvironment>() {
@Override
public void inject(final ServerEnvironment serverEnvironment) throws InjectionException {
instanceNameService.getManagedObjectInjector().inject(new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
return new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
final String nodeName = serverEnvironment.getNodeName();
return nodeName == null ? "" : nodeName;
}
};
}
});
}
@Override
public void uninject() {
instanceNameService.getManagedObjectInjector().uninject();
}
}).install();
deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, instanceNameServiceName);
}
use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.
the class ModuleContextProcessor method deploy.
/**
* Add a ContextService for this module.
*
* @param phaseContext the deployment unit context
* @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException
*/
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
return;
}
EEModuleDescription moduleDescription = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
final ServiceName appContextServiceName = ContextNames.contextServiceNameOfApplication(moduleDescription.getApplicationName());
final ServiceName moduleContextServiceName = ContextNames.contextServiceNameOfModule(moduleDescription.getApplicationName(), moduleDescription.getModuleName());
final NamingStoreService contextService = new NamingStoreService(true);
serviceTarget.addService(moduleContextServiceName, contextService).install();
final BinderService moduleNameBinder = new BinderService("ModuleName");
final ServiceName moduleNameServiceName = moduleContextServiceName.append("ModuleName");
serviceTarget.addService(moduleNameServiceName, moduleNameBinder).addInjection(moduleNameBinder.getManagedObjectInjector(), new ValueManagedReferenceFactory(Values.immediateValue(moduleDescription.getModuleName()))).addDependency(moduleContextServiceName, ServiceBasedNamingStore.class, moduleNameBinder.getNamingStoreInjector()).install();
deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, moduleNameServiceName);
deploymentUnit.putAttachment(MODULE_CONTEXT_CONFIG, moduleContextServiceName);
final InjectedEENamespaceContextSelector selector = new InjectedEENamespaceContextSelector();
phaseContext.addDependency(appContextServiceName, NamingStore.class, selector.getAppContextInjector());
phaseContext.addDependency(moduleContextServiceName, NamingStore.class, selector.getModuleContextInjector());
phaseContext.addDependency(moduleContextServiceName, NamingStore.class, selector.getCompContextInjector());
phaseContext.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, NamingStore.class, selector.getJbossContextInjector());
phaseContext.addDependency(ContextNames.EXPORTED_CONTEXT_SERVICE_NAME, NamingStore.class, selector.getExportedContextInjector());
phaseContext.addDependency(ContextNames.GLOBAL_CONTEXT_SERVICE_NAME, NamingStore.class, selector.getGlobalContextInjector());
moduleDescription.setNamespaceContextSelector(selector);
final Set<ServiceName> serviceNames = new HashSet<ServiceName>();
serviceNames.add(appContextServiceName);
serviceNames.add(moduleContextServiceName);
serviceNames.add(ContextNames.JBOSS_CONTEXT_SERVICE_NAME);
serviceNames.add(ContextNames.GLOBAL_CONTEXT_SERVICE_NAME);
// add the arquillian setup action, so the module namespace is available in arquillian tests
final JavaNamespaceSetup setupAction = new JavaNamespaceSetup(selector, deploymentUnit.getServiceName());
deploymentUnit.addToAttachmentList(SETUP_ACTIONS, setupAction);
deploymentUnit.addToAttachmentList(org.jboss.as.ee.component.Attachments.WEB_SETUP_ACTIONS, setupAction);
deploymentUnit.putAttachment(Attachments.JAVA_NAMESPACE_SETUP_ACTION, setupAction);
}
use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.
the class BinderServiceUtil method installBinderService.
/**
* Install a binder service to bind the value of the {@code service} using the binding {@code name}.
* @param serviceTarget
* @param name the binding name
* @param service the service whose value must be bound
*/
public static void installBinderService(final ServiceTarget serviceTarget, final String name, final Service<?> service, final ServiceName... dependencies) {
final BindInfo bindInfo = ContextNames.bindInfoFor(name);
final BinderService binderService = new BinderService(bindInfo.getBindName());
final ServiceBuilder serviceBuilder = serviceTarget.addService(bindInfo.getBinderServiceName(), binderService).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addInjection(binderService.getManagedObjectInjector(), new ValueManagedReferenceFactory(service)).setInitialMode(ServiceController.Mode.PASSIVE);
if (dependencies != null && dependencies.length > 0) {
serviceBuilder.addDependencies(dependencies);
}
serviceBuilder.install();
}
Aggregations