org.jboss.msc.service.Service Java Examples

The following examples show how to use org.jboss.msc.service.Service. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScheduledThreadPoolMetricsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void setResult(OperationContext context, final String attributeName, final Service<?> service)
        throws OperationFailedException {
    final ScheduledThreadPoolService pool = (ScheduledThreadPoolService) service;
    if(attributeName.equals(CommonAttributes.ACTIVE_COUNT)) {
        context.getResult().set(pool.getActiveCount());
    } else if(attributeName.equals(CommonAttributes.COMPLETED_TASK_COUNT)) {
        context.getResult().set(pool.getCompletedTaskCount());
    } else if (attributeName.equals(CommonAttributes.CURRENT_THREAD_COUNT)) {
        context.getResult().set(pool.getCurrentThreadCount());
    } else if (attributeName.equals(CommonAttributes.LARGEST_THREAD_COUNT)) {
        context.getResult().set(pool.getLargestThreadCount());
    } else if (attributeName.equals(CommonAttributes.TASK_COUNT)) {
        context.getResult().set(pool.getTaskCount());
    } else if (attributeName.equals(CommonAttributes.QUEUE_SIZE)) {
        context.getResult().set(pool.getQueueSize());
    } else {
        // Programming bug. Throw a RuntimeException, not OFE, as this is not a client error
        throw ThreadsLogger.ROOT_LOGGER.unsupportedScheduledThreadPoolMetric(attributeName);
    }
}
 
Example #2
Source File: BoundedQueueThreadPoolMetricsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void setResult(OperationContext context, final String attributeName, final Service<?> service)
        throws OperationFailedException {
    BoundedQueueThreadPoolService bounded = (BoundedQueueThreadPoolService) service;
    switch (attributeName) {
        case CommonAttributes.CURRENT_THREAD_COUNT:
            context.getResult().set(bounded.getCurrentThreadCount());
            break;
        case CommonAttributes.LARGEST_THREAD_COUNT:
            context.getResult().set(bounded.getLargestThreadCount());
            break;
        case CommonAttributes.REJECTED_COUNT:
            context.getResult().set(bounded.getRejectedCount());
            break;
        case CommonAttributes.QUEUE_SIZE:
            context.getResult().set(bounded.getQueueSize());
            break;
        default:
            // Programming bug. Throw a RuntimeException, not OFE, as this is not a client error
            throw ThreadsLogger.ROOT_LOGGER.unsupportedBoundedQueueThreadPoolMetric(attributeName);
    }
}
 
Example #3
Source File: QueuelessThreadPoolMetricsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void setResult(OperationContext context, final String attributeName, final Service<?> service)
        throws OperationFailedException {
    final QueuelessThreadPoolService pool = (QueuelessThreadPoolService) service;
    switch (attributeName) {
        case CommonAttributes.CURRENT_THREAD_COUNT:
            context.getResult().set(pool.getCurrentThreadCount());
            break;
        case CommonAttributes.LARGEST_THREAD_COUNT:
            context.getResult().set(pool.getLargestThreadCount());
            break;
        case CommonAttributes.REJECTED_COUNT:
            context.getResult().set(pool.getRejectedCount());
            break;
        case CommonAttributes.QUEUE_SIZE:
            context.getResult().set(pool.getRejectedCount());
            break;
        default:
            // Programming bug. Throw a RuntimeException, not OFE, as this is not a client error
            throw ThreadsLogger.ROOT_LOGGER.unsupportedQueuelessThreadPoolMetric(attributeName);
    }
}
 
Example #4
Source File: DeploymentCompleteServiceProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if(deploymentUnit.getParent() == null) {
        for(final DeploymentUnit subDeployment : deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS)) {
            deploymentUnit.addToAttachmentList(Attachments.DEPLOYMENT_COMPLETE_SERVICES, serviceName(subDeployment.getServiceName()));
        }
    }

    final ServiceBuilder<?> sb = phaseContext.getServiceTarget().addService(serviceName(deploymentUnit.getServiceName()), Service.NULL);
    final List<ServiceName> deploymentCompleteServices = deploymentUnit.getAttachmentList(Attachments.DEPLOYMENT_COMPLETE_SERVICES);
    if (deploymentCompleteServices != null) {
        for (final ServiceName deploymentCompleteService : deploymentCompleteServices) {
            sb.requires(deploymentCompleteService);
        }
    }
    sb.install();
}
 
Example #5
Source File: ThreadPoolManagementUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static <T> void installThreadPoolService(final Service<T> threadPoolService,
                                         final String threadPoolName,
                                         final ServiceName serviceNameBase,
                                         final String threadFactoryName,
                                         final ThreadFactoryResolver threadFactoryResolver,
                                         final Injector<ThreadFactory> threadFactoryInjector,
                                         final String handoffExecutorName,
                                         final HandoffExecutorResolver handoffExecutorResolver,
                                         final Injector<Executor> handoffExecutorInjector,
                                         final ServiceTarget target) {
    installThreadPoolService(threadPoolService, threadPoolName, null, null, serviceNameBase, threadFactoryName,
            threadFactoryResolver, threadFactoryInjector, handoffExecutorName, handoffExecutorResolver,
            handoffExecutorInjector, target);
}
 
Example #6
Source File: AddServerExecutorDependencyTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Tests that Services.requireServerExecutor's dependency injection works regardless of what
 * ServiceTarget API was used for creating the target ServiceBuilder.
 */
@SuppressWarnings("deprecation")
@Test
public void testDifferentServiceBuilderTypes() {
    ServiceTarget serviceTarget = container.subTarget();

    final Value<ExecutorService> value = new ImmediateValue<>(executorService);
    final Service<ExecutorService> mscExecutorService = new ValueService<>(value);

    ServiceController<?> executorController =
            serviceTarget.addService(ServerService.MANAGEMENT_EXECUTOR, mscExecutorService).install();

    //TestService legacy = new TestService();
    ServiceBuilder<?> legacyBuilder = serviceTarget.addService(ServiceName.of("LEGACY"));
    TestService legacy = new TestService(Services.requireServerExecutor(legacyBuilder));
    legacyBuilder.setInstance(legacy);
    ServiceController<?> legacyController = legacyBuilder.install();

    ServiceBuilder<?> currentBuilder = serviceTarget.addService(ServiceName.of("CURRENT"));
    TestService current = new TestService(Services.requireServerExecutor(currentBuilder));
    currentBuilder.setInstance(current);
    ServiceController<?> currentController = currentBuilder.install();

    try {
        container.awaitStability(60, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        Assert.fail("Interrupted");
    }

    Assert.assertEquals(ServiceController.State.UP, executorController.getState());
    Assert.assertEquals(ServiceController.State.UP, legacyController.getState());
    Assert.assertEquals(ServiceController.State.UP, currentController.getState());

    Assert.assertSame(executorService, legacy.getValue());
    Assert.assertSame(executorService, current.getValue());
}
 
Example #7
Source File: UnboundedQueueThreadPoolMetricsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void setResult(OperationContext context, final String attributeName, final Service<?> service)
        throws OperationFailedException {
    final UnboundedQueueThreadPoolService pool = (UnboundedQueueThreadPoolService) service;
    switch (attributeName) {
        case CommonAttributes.ACTIVE_COUNT:
            context.getResult().set(pool.getActiveCount());
            break;
        case CommonAttributes.COMPLETED_TASK_COUNT:
            context.getResult().set(pool.getCompletedTaskCount());
            break;
        case CommonAttributes.CURRENT_THREAD_COUNT:
            context.getResult().set(pool.getCurrentThreadCount());
            break;
        case CommonAttributes.LARGEST_THREAD_COUNT:
            context.getResult().set(pool.getLargestThreadCount());
            break;
        case CommonAttributes.REJECTED_COUNT:
            context.getResult().set(pool.getRejectedCount());
            break;
        case CommonAttributes.TASK_COUNT:
            context.getResult().set(pool.getTaskCount());
            break;
        case CommonAttributes.QUEUE_SIZE:
            context.getResult().set(pool.getQueueSize());
            break;
        default:
            // Programming bug. Throw a RuntimeException, not OFE, as this is not a client error
            throw ThreadsLogger.ROOT_LOGGER.unsupportedUnboundedQueueThreadPoolMetric(attributeName);
    }
}
 
Example #8
Source File: ThreadPoolMetricsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
    if (context.getRunningMode() == RunningMode.NORMAL) {
        ServiceController<?> serviceController = getService(context, operation);
        final Service<?> service = serviceController.getService();
        setResult(context, attributeName, service);
    }

    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
 
Example #9
Source File: ThreadPoolManagementUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static <T> void installThreadPoolService(final Service<T> threadPoolService,
                                         final String threadPoolName,
                                         final ServiceName serviceNameBase,
                                         final String threadFactoryName,
                                         final ThreadFactoryResolver threadFactoryResolver,
                                         final Injector<ThreadFactory> threadFactoryInjector,
                                         final ServiceTarget target) {
    installThreadPoolService(threadPoolService, threadPoolName, serviceNameBase,
            threadFactoryName, threadFactoryResolver, threadFactoryInjector,
            null, null, null,
            target);
}
 
Example #10
Source File: Seam2Processor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Lookup Seam integration resource loader.
 * @return the Seam integration resource loader
 * @throws DeploymentUnitProcessingException for any error
 */
protected synchronized ResourceRoot getSeamIntResourceRoot() throws DeploymentUnitProcessingException {
    try {
        if (seamIntResourceRoot == null) {
            final ModuleLoader moduleLoader = Module.getBootModuleLoader();
            Module extModule = moduleLoader.loadModule(EXT_CONTENT_MODULE);
            URL url = extModule.getExportedResource(SEAM_INT_JAR);
            if (url == null)
                throw ServerLogger.ROOT_LOGGER.noSeamIntegrationJarPresent(extModule);

            File file = new File(url.toURI());
            VirtualFile vf = VFS.getChild(file.toURI());
            final Closeable mountHandle = VFS.mountZip(file, vf, TempFileProviderService.provider());
            Service<Closeable> mountHandleService = new Service<Closeable>() {
                public void start(StartContext startContext) throws StartException {
                }

                public void stop(StopContext stopContext) {
                    VFSUtils.safeClose(mountHandle);
                }

                public Closeable getValue() throws IllegalStateException, IllegalArgumentException {
                    return mountHandle;
                }
            };
            ServiceBuilder<Closeable> builder = serviceTarget.addService(ServiceName.JBOSS.append(SEAM_INT_JAR),
                    mountHandleService);
            builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
            serviceTarget = null; // our cleanup service install work is done

            MountHandle dummy = MountHandle.create(null); // actual close is done by the MSC service above
            seamIntResourceRoot = new ResourceRoot(vf, dummy);
        }
        return seamIntResourceRoot;
    } catch (Exception e) {
        throw new DeploymentUnitProcessingException(e);
    }
}
 
Example #11
Source File: OperationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public <T> CapabilityServiceBuilder<T> addCapability(final RuntimeCapability<?> capability, final Service<T> service) throws IllegalArgumentException {
    if (capability.isDynamicallyNamed()){
        return addService(capability.getCapabilityServiceName(targetAddress), service);
    }else{
        return addService(capability.getCapabilityServiceName(), service);
    }
}
 
Example #12
Source File: OperationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public <T> ServiceBuilder<T> addServiceValue(final ServiceName name, final Value<? extends Service<T>> value) {
    final ServiceBuilder<T> realBuilder = super.getDelegate().addServiceValue(name, value);
    // If done() has been called we are no longer associated with a management op and should just
    // return the builder from delegate
    synchronized (this) {
        if (builderSupplier == null) {
            return realBuilder;
        }
        ContextServiceBuilder<T> csb = builderSupplier.getContextServiceBuilder(realBuilder, name);
        builders.add(csb);
        return csb;
    }
}
 
Example #13
Source File: RootResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    String osb = ATTRIBUTE.resolveModelAttribute(context, resource.getModel()).asString();
    Service<Void> service = new AbstractService<Void>() {};
    ServiceBuilder sb = context.getServiceTarget().addService(ServiceName.of("wfcore-1106"), service);
    sb.requires(context.getCapabilityServiceName("org.wildfly.network.outbound-socket-binding", osb, OutboundSocketBinding.class));
    sb.install();
}
 
Example #14
Source File: EnhancedQueueExecutorMetricsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void setResult(OperationContext context, final String attributeName, final Service<?> service) {
    final EnhancedQueueExecutorService pool = (EnhancedQueueExecutorService) service;
    switch (attributeName) {
        case CommonAttributes.ACTIVE_COUNT:
            context.getResult().set(pool.getActiveCount());
            break;
        case CommonAttributes.COMPLETED_TASK_COUNT:
            context.getResult().set(pool.getCompletedTaskCount());
            break;
        case CommonAttributes.CURRENT_THREAD_COUNT:
            context.getResult().set(pool.getCurrentThreadCount());
            break;
        case CommonAttributes.LARGEST_THREAD_COUNT:
            context.getResult().set(pool.getLargestThreadCount());
            break;
        case CommonAttributes.REJECTED_COUNT:
            context.getResult().set(pool.getRejectedCount());
            break;
        case CommonAttributes.TASK_COUNT:
            context.getResult().set(pool.getTaskCount());
            break;
        case CommonAttributes.QUEUE_SIZE:
            context.getResult().set(pool.getQueueSize());
            break;
        default:
            // Programming bug. Throw a RuntimeException, not OFE, as this is not a client error
            throw ThreadsLogger.ROOT_LOGGER.unsupportedEnhancedQueueExecutorMetric(attributeName);
    }
}
 
Example #15
Source File: CacheActivator.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    Service<Void> service = new AbstractService<Void>() { };
    context.getServiceTarget()
            .addService(ServiceName.of("thorntail", "cache-activator").append(this.cacheContainerName), service)
            .addDependency(this.type.serviceNameBase.append(this.cacheContainerName))
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .install();
}
 
Example #16
Source File: CertificateAuthorityDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static Service<CertificateAuthority> getCertificateAuthorityService(ServiceRegistry serviceRegistry, String certificateAuthorityName) {
    RuntimeCapability<Void> runtimeCapability = CERTIFICATE_AUTHORITY_RUNTIME_CAPABILITY.fromBaseCapability(certificateAuthorityName);
    ServiceName serviceName = runtimeCapability.getCapabilityServiceName();
    ServiceController<CertificateAuthority> serviceContainer = getRequiredService(serviceRegistry, serviceName, CertificateAuthority.class);
    return serviceContainer.getService();
}
 
Example #17
Source File: ThreadPoolManagementUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static <T> void installThreadPoolService(final Service<T> threadPoolService,
                                         final String threadPoolName,
                                         final RuntimeCapability<Void> cap,
                                         final PathAddress address,
                                         final ServiceName serviceNameBase,
                                         final String threadFactoryName,
                                         final ThreadFactoryResolver threadFactoryResolver,
                                         final Injector<ThreadFactory> threadFactoryInjector,
                                         final String handoffExecutorName,
                                         final HandoffExecutorResolver handoffExecutorResolver,
                                         final Injector<Executor> handoffExecutorInjector,
                                         final ServiceTarget target) {
    final ServiceName threadPoolServiceName;
    final ServiceName aliasServiceName;
    if(cap != null) {
        threadPoolServiceName = cap.getCapabilityServiceName(address);
        if(serviceNameBase != null) {
            aliasServiceName = serviceNameBase.append(threadPoolName);
        } else {
            aliasServiceName = null;
        }
    } else {
        threadPoolServiceName = serviceNameBase.append(threadPoolName);
        aliasServiceName = null;
    }
    final ServiceBuilder<?> serviceBuilder = target.addService(threadPoolServiceName, threadPoolService);
    if(aliasServiceName != null) {
        serviceBuilder.addAliases(aliasServiceName);
    }
    final ServiceName threadFactoryServiceName = threadFactoryResolver.resolveThreadFactory(threadFactoryName,
            threadPoolName, threadPoolServiceName, target);
    serviceBuilder.addDependency(threadFactoryServiceName, ThreadFactory.class, threadFactoryInjector);

    if (handoffExecutorInjector != null) {
        ServiceName handoffServiceName = handoffExecutorResolver.resolveHandoffExecutor(handoffExecutorName,
                threadPoolName, threadPoolServiceName, target);
        if (handoffServiceName != null) {
            serviceBuilder.addDependency(handoffServiceName, Executor.class, handoffExecutorInjector);
        }
    }

    serviceBuilder.install();

}
 
Example #18
Source File: ServiceModuleLoader.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void addService(final ServiceTarget serviceTarget, final Bootstrap.Configuration configuration) {
    final Service<ServiceModuleLoader> service = new ServiceModuleLoader(configuration.getModuleLoader());
    final ServiceBuilder<?> serviceBuilder = serviceTarget.addService(Services.JBOSS_SERVICE_MODULE_LOADER, service);
    serviceBuilder.install();
}
 
Example #19
Source File: NetworkInterfaceService.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static Service<NetworkInterfaceBinding> create(String name, ParsedInterfaceCriteria criteria) {
    return new NetworkInterfaceService(name, criteria.isAnyLocal(), criteria.getCriteria());
}
 
Example #20
Source File: OperationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public CapabilityServiceBuilder<T> setInstance(org.jboss.msc.Service service) {
    super.setInstance(service);
    return this;
}
 
Example #21
Source File: OperationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public <T> CapabilityServiceBuilder<T> addService(final ServiceName name, final Service<T> service) throws IllegalArgumentException {
    return new CapabilityServiceBuilderImpl<>(addServiceValue(name, new ImmediateValue<>(service)), targetAddress);
}
 
Example #22
Source File: ElytronDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void installService(ServiceName serviceName, Service<?> service, ServiceTarget serviceTarget) {
    serviceTarget.addService(serviceName, service)
        .setInitialMode(Mode.ACTIVE)
        .install();
}
 
Example #23
Source File: SpecifiedInterfaceAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Create a {@link NetworkInterfaceService}.
 *
 * @return the interface service
 */
private static Service<NetworkInterfaceBinding> createInterfaceService(String name, ParsedInterfaceCriteria criteria) {
    return NetworkInterfaceService.create(name, criteria);
}
 
Example #24
Source File: DeploymentUnitPhaseBuilder.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Builds a deployment phase.
 * @param target a service target
 * @param name the service name of the deployment phase
 * @param service the service providing the deployment phase
 * @return a service builder
 */
<T> ServiceBuilder<T> build(ServiceTarget target, ServiceName name, Service<T> service);
 
Example #25
Source File: CapabilityServiceTarget.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Gets a builder which can be used to add a capability service into this capability target.
 *
 * @param capability the capability to be installed
 * @param service the service implementing this capability
 * @return new capability builder instance
 * @throws IllegalArgumentException if capability does not provide a service
 * @deprecated use {@link #addCapability(RuntimeCapability)} method instead
 */
@Deprecated
<T> CapabilityServiceBuilder<T> addCapability(final RuntimeCapability<?> capability, final Service<T> service) throws IllegalArgumentException;
 
Example #26
Source File: ThreadPoolMetricsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 votes vote down vote up
protected abstract void setResult(OperationContext context, String attributeName, Service<?> service) throws OperationFailedException;