Search in sources :

Example 11 with ImmediateValue

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

the class PersistenceUnitServiceHandler method entityManagerFactoryBind.

private static void entityManagerFactoryBind(EEModuleDescription eeModuleDescription, ServiceTarget serviceTarget, PersistenceUnitMetadata pu, ServiceName puServiceName) {
    if (pu.getProperties().containsKey(ENTITYMANAGERFACTORY_JNDI_PROPERTY)) {
        String jndiName = pu.getProperties().get(ENTITYMANAGERFACTORY_JNDI_PROPERTY).toString();
        final ContextNames.BindInfo bindingInfo;
        if (jndiName.startsWith("java:")) {
            bindingInfo = ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jndiName);
        } else {
            bindingInfo = ContextNames.bindInfoFor(jndiName);
        }
        ROOT_LOGGER.tracef("binding the entity manager factory to jndi name '%s'", bindingInfo.getAbsoluteJndiName());
        final BinderService binderService = new BinderService(bindingInfo.getBindName());
        serviceTarget.addService(bindingInfo.getBinderServiceName(), binderService).addDependency(bindingInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addDependency(puServiceName, PersistenceUnitServiceImpl.class, new Injector<PersistenceUnitServiceImpl>() {

            @Override
            public void inject(final PersistenceUnitServiceImpl value) throws InjectionException {
                binderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(value.getEntityManagerFactory())));
            }

            @Override
            public void uninject() {
                binderService.getNamingStoreInjector().uninject();
            }
        }).install();
    }
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) PhaseOnePersistenceUnitServiceImpl(org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl) PersistenceUnitServiceImpl(org.jboss.as.jpa.service.PersistenceUnitServiceImpl) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) CastingInjector(org.jboss.msc.inject.CastingInjector) Injector(org.jboss.msc.inject.Injector) ContextNames(org.jboss.as.naming.deployment.ContextNames) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 12 with ImmediateValue

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

the class UndertowDeploymentProcessor method installSessionManagerFactory.

private static ServiceName installSessionManagerFactory(CapabilityServiceSupport support, ServiceTarget target, ServiceName deploymentServiceName, String deploymentName, Module module, JBossWebMetaData metaData, ServletContainerService servletContainerService) {
    Integer maxActiveSessions = metaData.getMaxActiveSessions();
    if (maxActiveSessions == null && servletContainerService != null) {
        maxActiveSessions = servletContainerService.getMaxSessions();
    }
    ServiceName name = deploymentServiceName.append("session");
    if (metaData.getDistributable() != null) {
        DistributableSessionManagerFactoryBuilder sessionManagerFactoryBuilder = new DistributableSessionManagerFactoryBuilderValue().getValue();
        if (sessionManagerFactoryBuilder != null) {
            sessionManagerFactoryBuilder.build(support, target, name, new SimpleDistributableSessionManagerConfiguration(maxActiveSessions, metaData.getReplicationConfig(), deploymentName, module)).setInitialMode(Mode.ON_DEMAND).install();
            return name;
        }
        // Fallback to local session manager if server does not support clustering
        UndertowLogger.ROOT_LOGGER.clusteringNotSupported();
    }
    InMemorySessionManagerFactory factory = (maxActiveSessions != null) ? new InMemorySessionManagerFactory(maxActiveSessions) : new InMemorySessionManagerFactory();
    target.addService(name, new ValueService<>(new ImmediateValue<>(factory))).setInitialMode(Mode.ON_DEMAND).install();
    return name;
}
Also used : SimpleDistributableSessionManagerConfiguration(org.wildfly.extension.undertow.session.SimpleDistributableSessionManagerConfiguration) DistributableSessionManagerFactoryBuilder(org.wildfly.extension.undertow.session.DistributableSessionManagerFactoryBuilder) ServiceName(org.jboss.msc.service.ServiceName) InMemorySessionManagerFactory(io.undertow.servlet.core.InMemorySessionManagerFactory) DistributableSessionManagerFactoryBuilderValue(org.wildfly.extension.undertow.session.DistributableSessionManagerFactoryBuilderValue) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 13 with ImmediateValue

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

the class BinderServiceBuilder method build.

@Override
public ServiceBuilder<ManagedReferenceFactory> build(ServiceTarget target) {
    if (!this.enabled) {
        // If naming is not enabled, just install a dummy service that never starts
        Value<ManagedReferenceFactory> value = new ImmediateValue<>(null);
        return target.addService(this.getServiceName(), new ValueService<>(value)).setInitialMode(ServiceController.Mode.NEVER);
    }
    String name = this.binding.getBindName();
    BinderService binder = new BinderService(name);
    ServiceBuilder<ManagedReferenceFactory> builder = target.addService(this.getServiceName(), binder).addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(name)).addDependency(this.targetServiceName, this.targetClass, new ManagedReferenceInjector<T>(binder.getManagedObjectInjector())).addDependency(this.binding.getParentContextServiceName(), ServiceBasedNamingStore.class, binder.getNamingStoreInjector());
    for (ContextNames.BindInfo alias : this.aliases) {
        builder.addAliases(alias.getBinderServiceName(), ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(alias.getBindName()));
    }
    return builder.setInitialMode(ServiceController.Mode.PASSIVE);
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ManagedReferenceInjector(org.jboss.as.naming.ManagedReferenceInjector) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ValueService(org.jboss.msc.service.ValueService) ImmediateValue(org.jboss.msc.value.ImmediateValue) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 14 with ImmediateValue

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

the class ThreadPoolFactoryBuilder method build.

@Override
public ServiceBuilder<ThreadPoolFactory> build(ServiceTarget target) {
    int queueLength = this.getQueueLength();
    BlockingQueue<Runnable> queue = (queueLength > 0) ? new ArrayBlockingQueue<>(queueLength) : new SynchronousQueue<>();
    ClassLoader loader = JChannelFactory.class.getClassLoader();
    ThreadFactory threadFactory = new ClassLoaderThreadFactory(new DefaultThreadFactory(this.getThreadGroupPrefix(), false, true), loader);
    RejectedExecutionHandler handler = new ShutdownRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
    ThreadPoolFactory factory = () -> new ThreadPoolExecutor(this.getMinThreads(), this.getMaxThreads(), this.getKeepAliveTime(), TimeUnit.MILLISECONDS, queue, threadFactory, handler);
    return target.addService(this.getServiceName(), new ValueService<>(new ImmediateValue<>(factory)));
}
Also used : ClassLoaderThreadFactory(org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory) DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) ThreadFactory(org.jgroups.util.ThreadFactory) ShutdownRejectedExecutionHandler(org.jgroups.util.ShutdownRejectedExecutionHandler) RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) ImmediateValue(org.jboss.msc.value.ImmediateValue) DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) ClassLoaderThreadFactory(org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory) ShutdownRejectedExecutionHandler(org.jgroups.util.ShutdownRejectedExecutionHandler) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 15 with ImmediateValue

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

the class TimerFactoryBuilder method build.

@Override
public ServiceBuilder<TimerFactory> build(ServiceTarget target) {
    ThreadFactory threadFactory = new ClassLoaderThreadFactory(new LazyThreadFactory(this.getThreadGroupPrefix(), true, true), JChannelFactory.class.getClassLoader());
    TimerFactory factory = () -> new TimeScheduler3(threadFactory, this.getMinThreads(), this.getMaxThreads(), this.getKeepAliveTime(), this.getQueueLength(), "abort");
    return target.addService(this.getServiceName(), new ValueService<>(new ImmediateValue<>(factory)));
}
Also used : ClassLoaderThreadFactory(org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory) ThreadFactory(org.jgroups.util.ThreadFactory) LazyThreadFactory(org.jgroups.util.LazyThreadFactory) LazyThreadFactory(org.jgroups.util.LazyThreadFactory) JChannelFactory(org.jboss.as.clustering.jgroups.JChannelFactory) TimeScheduler3(org.jgroups.util.TimeScheduler3) ClassLoaderThreadFactory(org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Aggregations

ImmediateValue (org.jboss.msc.value.ImmediateValue)20 BinderService (org.jboss.as.naming.service.BinderService)6 ServiceName (org.jboss.msc.service.ServiceName)6 ValueManagedReferenceFactory (org.jboss.as.naming.ValueManagedReferenceFactory)5 Method (java.lang.reflect.Method)3 ContextNames (org.jboss.as.naming.deployment.ContextNames)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 ServiceTarget (org.jboss.msc.service.ServiceTarget)3 ArrayList (java.util.ArrayList)2 ObjectName (javax.management.ObjectName)2 ClassLoaderThreadFactory (org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory)2 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 PersistenceUnitServiceImpl (org.jboss.as.jpa.service.PersistenceUnitServiceImpl)2 PhaseOnePersistenceUnitServiceImpl (org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl)2 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)2 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)2 JBossServiceDependencyConfig (org.jboss.as.service.descriptor.JBossServiceDependencyConfig)2 Module (org.jboss.modules.Module)2 CastingInjector (org.jboss.msc.inject.CastingInjector)2