Search in sources :

Example 1 with ValueService

use of org.jboss.msc.service.ValueService in project wildfly by wildfly.

the class InfinispanBeanManagerFactoryBuilder method build.

@Override
public ServiceBuilder<BeanManagerFactory<I, T, TransactionBatch>> build(ServiceTarget target) {
    String containerName = this.configuration.getContainerName();
    ServiceName deploymentUnitServiceName = this.context.getDeploymentUnitServiceName();
    return target.addService(this.getServiceName(), new ValueService<>(this)).addDependency(InfinispanCacheRequirement.CACHE.getServiceName(this.support, containerName, InfinispanBeanManagerFactoryBuilderFactory.getCacheName(deploymentUnitServiceName)), Cache.class, this.cache).addDependency(InfinispanRequirement.KEY_AFFINITY_FACTORY.getServiceName(this.support, containerName), KeyAffinityServiceFactory.class, this.affinityFactory).addDependency(deploymentUnitServiceName.append("marshalling"), MarshallingConfigurationRepository.class, this.repository).addDependency(deploymentUnitServiceName.append(this.name, "expiration"), ScheduledExecutorService.class, this.scheduler).addDependency(deploymentUnitServiceName.append(this.name, "eviction"), Executor.class, this.executor).addDependency(ClusteringRequirement.COMMAND_DISPATCHER_FACTORY.getServiceName(this.support, containerName), CommandDispatcherFactory.class, this.dispatcherFactory).addDependency(ClusteringCacheRequirement.REGISTRY.getServiceName(this.support, containerName, BeanManagerFactoryBuilderConfiguration.CLIENT_MAPPINGS_CACHE_NAME), Registry.class, this.registry).addDependency(ClusteringCacheRequirement.NODE_FACTORY.getServiceName(this.support, containerName, BeanManagerFactoryBuilderConfiguration.CLIENT_MAPPINGS_CACHE_NAME), NodeFactory.class, this.nodeFactory).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NodeFactory(org.wildfly.clustering.group.NodeFactory) ServiceName(org.jboss.msc.service.ServiceName) CommandDispatcherFactory(org.wildfly.clustering.dispatcher.CommandDispatcherFactory) ValueService(org.jboss.msc.service.ValueService) KeyAffinityServiceFactory(org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory)

Example 2 with ValueService

use of org.jboss.msc.service.ValueService in project wildfly by wildfly.

the class ElectionPolicyBuilder method build.

@Override
public ServiceBuilder<SingletonElectionPolicy> build(ServiceTarget target) {
    Value<SingletonElectionPolicy> value = () -> this.preferences.isEmpty() ? this.getValue() : new PreferredSingletonElectionPolicy(this.getValue(), this.preferences);
    ServiceBuilder<SingletonElectionPolicy> builder = target.addService(this.getServiceName(), new ValueService<>(value)).setInitialMode(ServiceController.Mode.ON_DEMAND);
    this.dependencies.forEach(dependency -> dependency.register(builder));
    return builder;
}
Also used : SingletonElectionPolicy(org.wildfly.clustering.singleton.SingletonElectionPolicy) PreferredSingletonElectionPolicy(org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy) PreferredSingletonElectionPolicy(org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy) ValueService(org.jboss.msc.service.ValueService)

Example 3 with ValueService

use of org.jboss.msc.service.ValueService in project wildfly-swarm by wildfly-swarm.

the class RuntimeServer method start.

public Deployer start(boolean eagerOpen) throws Exception {
    UUID uuid = UUIDFactory.getUUID();
    System.setProperty("jboss.server.management.uuid", uuid.toString());
    File configurationFile;
    try {
        configurationFile = TempFileManager.INSTANCE.newTempFile("swarm-config-", ".xml");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    this.networkConfigurer.configure();
    List<ModelNode> bootstrapOperations = new ArrayList<>();
    BootstrapConfiguration bootstrapConfiguration = () -> bootstrapOperations;
    this.container = new SelfContainedContainer(new Bootstrap.ConfigurationPersisterFactory() {

        @Override
        public ExtensibleConfigurationPersister createConfigurationPersister(ServerEnvironment serverEnvironment, ExecutorService executorService) {
            return new BootstrapPersister(bootstrapConfiguration, configurationFile);
        }
    });
    try (AutoCloseable handle = Performance.time("pre-customizers")) {
        for (Customizer each : this.preCustomizers) {
            SwarmMessages.MESSAGES.callingPreCustomizer(each);
            each.customize();
        }
    }
    try (AutoCloseable handle = Performance.time("post-customizers")) {
        for (Customizer each : this.postCustomizers) {
            SwarmMessages.MESSAGES.callingPostCustomizer(each);
            each.customize();
        }
    }
    this.networkConfigurer.configure();
    try (AutoCloseable handle = Performance.time("configurable-manager rescan")) {
        this.configurableManager.rescan();
        this.configurableManager.log();
    }
    try (AutoCloseable handle = Performance.time("marshall DMR")) {
        this.dmrMarshaller.marshal(bootstrapOperations);
    }
    SwarmMessages.MESSAGES.wildflyBootstrap(bootstrapOperations.toString());
    Thread.currentThread().setContextClassLoader(RuntimeServer.class.getClassLoader());
    List<ServiceActivator> activators = new ArrayList<>();
    StreamSupport.stream(serviceActivators.spliterator(), false).filter(Objects::nonNull).forEach(activators::add);
    activators.add(new ContentRepositoryServiceActivator(this.contentRepository));
    try (AutoCloseable wildflyStart = Performance.time("WildFly start")) {
        ServiceContainer serviceContainer = null;
        try (AutoCloseable startWildflyItself = Performance.time("Starting WildFly itself")) {
            // serviceContainer = this.container.start(bootstrapOperations, this.contentProvider, activators);
            serviceContainer = this.container.start(bootstrapOperations, activators);
            this.containerStarted = true;
        }
        try (AutoCloseable checkFailedServices = Performance.time("Checking for failed services")) {
            for (ServiceName serviceName : serviceContainer.getServiceNames()) {
                ServiceController<?> serviceController = serviceContainer.getService(serviceName);
                /*
                    if (serviceController.getImmediateUnavailableDependencies().size() > 0) {
                        System.err.println("Service missing dependencies: " + serviceController.getName());
                        for (ServiceName name : serviceController.getImmediateUnavailableDependencies()) {
                            System.err.println("  - " + name);
                        }
                    }
                    */
                StartException exception = serviceController.getStartException();
                if (exception != null) {
                    throw exception;
                }
            }
        }
        /*
            for (ServiceName serviceName : serviceContainer.getServiceNames()) {
                System.err.println(" === " + serviceName);
            }
            */
        ModelController controller = (ModelController) serviceContainer.getService(Services.JBOSS_SERVER_CONTROLLER).getValue();
        Executor executor = Executors.newSingleThreadExecutor();
        try (AutoCloseable creatingControllerClient = Performance.time("Creating controller client")) {
            // Can't use controller.getClientFactory() due to non-public nature of that method.
            // noinspection deprecation
            this.client = controller.createClient(executor);
        }
        RuntimeDeployer deployer = this.deployer.get();
        try (AutoCloseable installDeployer = Performance.time("Installing deployer")) {
            serviceContainer.addService(ServiceName.of("swarm", "deployer"), new ValueService<>(new ImmediateValue<Deployer>(deployer))).install();
        }
        try (AutoCloseable configUserSpaceExt = Performance.time("Configure user-space extensions")) {
            configureUserSpaceExtensions();
        }
        try (AutoCloseable deployments = Performance.time("Implicit Deployments")) {
            for (Archive each : this.implicitDeployments) {
                if (each != null) {
                    deployer.deploy(each);
                }
            }
        }
        this.artifactDeployer.deploy();
        deployer.implicitDeploymentsComplete();
        return deployer;
    }
}
Also used : Archive(org.jboss.shrinkwrap.api.Archive) ContentRepositoryServiceActivator(org.wildfly.swarm.container.runtime.wildfly.ContentRepositoryServiceActivator) ArrayList(java.util.ArrayList) ValueService(org.jboss.msc.service.ValueService) ServiceContainer(org.jboss.msc.service.ServiceContainer) Executor(java.util.concurrent.Executor) ServerEnvironment(org.jboss.as.server.ServerEnvironment) StartException(org.jboss.msc.service.StartException) UUID(java.util.UUID) SelfContainedContainer(org.wildfly.swarm.internal.wildfly.SelfContainedContainer) BootstrapPersister(org.wildfly.swarm.container.runtime.xmlconfig.BootstrapPersister) Deployer(org.wildfly.swarm.container.internal.Deployer) BootstrapConfiguration(org.wildfly.swarm.container.runtime.xmlconfig.BootstrapConfiguration) IOException(java.io.IOException) ContentRepositoryServiceActivator(org.wildfly.swarm.container.runtime.wildfly.ContentRepositoryServiceActivator) ServiceActivator(org.jboss.msc.service.ServiceActivator) ServiceName(org.jboss.msc.service.ServiceName) ExecutorService(java.util.concurrent.ExecutorService) Customizer(org.wildfly.swarm.spi.api.Customizer) ModelNode(org.jboss.dmr.ModelNode) ModelController(org.jboss.as.controller.ModelController) File(java.io.File)

Example 4 with ValueService

use of org.jboss.msc.service.ValueService in project wildfly by wildfly.

the class EJB3SubsystemDefaultEntityBeanOptimisticLockingWriteHandler method updateOptimisticLocking.

void updateOptimisticLocking(final OperationContext context, final ModelNode model) throws OperationFailedException {
    final ModelNode enabled = EJB3SubsystemRootResourceDefinition.DEFAULT_ENTITY_BEAN_OPTIMISTIC_LOCKING.resolveModelAttribute(context, model);
    final ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
    ServiceController<?> existingService = serviceRegistry.getService(SERVICE_NAME);
    // if a default optimistic locking config is installed, remove it
    if (existingService != null) {
        context.removeService(existingService);
    }
    if (enabled.isDefined()) {
        final Service<Boolean> newDefaultPoolConfigService = new ValueService<Boolean>(new ImmediateValue<Boolean>(enabled.asBoolean()));
        ServiceController<?> newController = context.getServiceTarget().addService(SERVICE_NAME, newDefaultPoolConfigService).install();
    }
}
Also used : ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode) ValueService(org.jboss.msc.service.ValueService)

Example 5 with ValueService

use of org.jboss.msc.service.ValueService in project wildfly by wildfly.

the class ExceptionLoggingWriteHandler method updateOrCreateDefaultExceptionLoggingEnabledService.

void updateOrCreateDefaultExceptionLoggingEnabledService(final OperationContext context, final ModelNode model) throws OperationFailedException {
    final boolean enabled = EJB3SubsystemRootResourceDefinition.LOG_EJB_EXCEPTIONS.resolveModelAttribute(context, model).asBoolean();
    final ServiceName serviceName = LoggingInterceptor.LOGGING_ENABLED_SERVICE_NAME;
    final ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceController sc = registry.getService(serviceName);
    if (sc != null) {
        final AtomicBoolean value = (AtomicBoolean) sc.getValue();
        value.set(enabled);
    } else {
        // create and install the service
        final ValueService<AtomicBoolean> service = new ValueService<>(new ImmediateValue<>(new AtomicBoolean(enabled)));
        context.getServiceTarget().addService(serviceName, service).install();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ValueService(org.jboss.msc.service.ValueService)

Aggregations

ValueService (org.jboss.msc.service.ValueService)11 ServiceName (org.jboss.msc.service.ServiceName)6 ServiceTarget (org.jboss.msc.service.ServiceTarget)4 BinderService (org.jboss.as.naming.service.BinderService)3 ArrayList (java.util.ArrayList)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 ContextNames (org.jboss.as.naming.deployment.ContextNames)2 AbstractDeploymentChainStep (org.jboss.as.server.AbstractDeploymentChainStep)2 DeploymentProcessorTarget (org.jboss.as.server.DeploymentProcessorTarget)2 ModelNode (org.jboss.dmr.ModelNode)2 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)2 PathHandler (io.undertow.server.handlers.PathHandler)1 SessionIdGenerator (io.undertow.server.session.SessionIdGenerator)1 SessionListener (io.undertow.server.session.SessionListener)1 File (java.io.File)1 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Executor (java.util.concurrent.Executor)1