Java Code Examples for org.jboss.msc.service.ServiceName#append()

The following examples show how to use org.jboss.msc.service.ServiceName#append() . 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: LoggingConfigurationReadStepHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static ServiceName getServiceName(final OperationContext context) {
    String deploymentName = null;
    String subdeploymentName = null;
    final PathAddress address = context.getCurrentAddress();
    for (PathElement element : address) {
        if (ModelDescriptionConstants.DEPLOYMENT.equals(element.getKey())) {
            deploymentName = getRuntimeName(context, element);
            //deploymentName = element.getValue();
        } else if (ModelDescriptionConstants.SUBDEPLOYMENT.endsWith(element.getKey())) {
            subdeploymentName = element.getValue();
        }
    }
    if (deploymentName == null) {
        throw LoggingLogger.ROOT_LOGGER.deploymentNameNotFound(address);
    }
    final ServiceName result;
    if (subdeploymentName == null) {
        result = Services.deploymentUnitName(deploymentName);
    } else {
        result = Services.deploymentUnitName(deploymentName, subdeploymentName);
    }
    return result.append("logging", "configuration");
}
 
Example 2
Source File: ThreadPoolManagementUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void removeThreadPoolService(String threadPoolName,
        final RuntimeCapability<Void> cap,
        ServiceName serviceNameBase,
        String threadFactoryName,
        ThreadFactoryResolver threadFactoryResolver,
        String handoffExecutorName,
        HandoffExecutorResolver handoffExecutorResolver,
        OperationContext operationContext) {
    final ServiceName threadPoolServiceName;
    if (cap != null) {
        threadPoolServiceName = cap.getCapabilityServiceName(threadPoolName);
    } else {
        threadPoolServiceName = serviceNameBase.append(threadPoolName);
    }
    operationContext.removeService(threadPoolServiceName);
    threadFactoryResolver.releaseThreadFactory(threadFactoryName, threadPoolName, threadPoolServiceName, operationContext);
    if (handoffExecutorResolver != null) {
        handoffExecutorResolver.releaseHandoffExecutor(handoffExecutorName, threadPoolName, threadPoolServiceName, operationContext);
    }
}
 
Example 3
Source File: TestHostCapableExtension.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static ServiceName createServiceName(PathAddress address) {
    ServiceName name = ServiceName.JBOSS;
    name = name.append("test");
    for (PathElement element : address) {
        name = name.append(element.getKey(), element.getValue());
    }
    return name;
}
 
Example 4
Source File: DeploymentScannerRemove.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) {
    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String name = address.getLastElement().getValue();
    final ServiceName serviceName = DeploymentScannerService.getServiceName(name);
    final ServiceName pathServiceName = serviceName.append("path");

    context.removeService(serviceName);
    context.removeService(pathServiceName);
}
 
Example 5
Source File: CamelEndpointDeployerProcessor.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    CamelDeploymentSettings depSettings = deploymentUnit.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);

    if (!depSettings.isEnabled()) {
        return;
    }
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        /* ignore non-war deployments */
        CamelLogger.LOGGER.debug("{} ignores non-WAR deployment {}",
                CamelEndpointDeployerProcessor.class.getSimpleName(), deploymentUnit.getName());
        return;
    }

    final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit
            .getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
    final ModelNode node = deploymentResourceSupport.getDeploymentSubsystemModel(UndertowExtension.SUBSYSTEM_NAME);
    final String hostName = node.get(DeploymentDefinition.VIRTUAL_HOST.getName()).asString();
    final String serverName = node.get(DeploymentDefinition.SERVER.getName()).asString();
    final String path = node.get(DeploymentDefinition.CONTEXT_ROOT.getName()).asString();

    final ServiceName deploymentServiceName = UndertowService.deploymentServiceName(serverName, hostName, path);
    final ServiceName deploymentInfoServiceName = deploymentServiceName
            .append(UndertowDeploymentInfoService.SERVICE_NAME);
    final ServiceName hostServiceName = UndertowService.virtualHostName(serverName, hostName);

    CamelEndpointDeployerService.addService(deploymentUnit, phaseContext.getServiceTarget(),
            deploymentInfoServiceName, hostServiceName);
}
 
Example 6
Source File: SSLContextService.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static ServiceName createServiceName(final ServiceName parentService, final boolean trustOnly) {
    return parentService.append(trustOnly ? TRUST_ONLY_SERVICE_SUFFIX : SERVICE_SUFFIX);
}
 
Example 7
Source File: AbstractTrustManagerService.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static ServiceName createServiceName(final ServiceName parentService) {
    return parentService.append(SERVICE_SUFFIX);
}
 
Example 8
Source File: AbstractKeyManagerService.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static ServiceName createServiceName(final ServiceName parentService) {
    return parentService.append(SERVICE_SUFFIX);
}
 
Example 9
Source File: ServiceNameFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Parses a string into a {@link ServiceName} using the same algorithm as {@link ServiceName#parse(String)}
 * but also attempts to ensure that once parsing occurs if any other name that is
 * {@link ServiceName#equals(ServiceName) equal to} the parsed name or one of its
 * {@link ServiceName#getParent() ancestors} has been parsed previously that that previously parsed name
 * is used.
 *
 * @param toParse the string form of a service name. Cannot be {@code null}
 * @return a {@code ServiceName} instance
 */
public static ServiceName parseServiceName(String toParse) {
    ServiceName original = ServiceName.parse(toParse);

    // Try to use cached elements of the ServiceName chain

    // Cost of a duplicate ServiceName instance
    // 1) int for hashCode
    // 2) pointer to simple name
    // 3) pointer to canonical name
    // 4) pointer to parent
    // 5) the simple name (cost depends on string length but at least 2 pointers plus the char[] and the object)
    // 6) Possibly a long string for canonicalName

    // Cost of a ConcurrentHashMap Node where key == value
    // 1) int for hash code
    // 2) pointer to key
    // 3) pointer to value
    // 4) pointer to next
    // 5) ~ 1 pointer to the Node itself in the table (some table elements have > 1 Node but some are empty

    // Based on this, if there's roughly a > 50% chance of a name being duplicated, it's worthwhile
    // to intern it. As a heuristic for whether there is a > 50% chance, we'll intern all names
    // of 4 elements or less and for larger names, all but the last element

    int length = original.length();
    ServiceName[] ancestry = new ServiceName[length];
    ServiceName sn = original;
    for (int i = length - 1; i >= 0   ; i--) {
        ancestry[i] = sn;
        sn = sn.getParent();
    }

    int max = length > 4 ? length - 1 : length;
    for (int i = 0; i < max; i++) {
        ServiceName interned = cache.putIfAbsent(ancestry[i], ancestry[i]);
        if (interned != null && ancestry[i] != interned) {
            // Replace this one in the ancestry with the interned one
            ServiceName parent = ancestry[i] = interned;
            // Replace all descendants
            boolean checkCache = true;
            for (int j = i+1; j < length; j++) {
                parent = parent.append(ancestry[j].getSimpleName());
                if (checkCache && j < max) {
                    ServiceName cached = cache.get(parent);
                    if (cached != null) {
                        // Use what we already have
                        parent = cached;
                        // We don't need to recheck in the outer loop.
                        i = j;
                    } else {
                        // Assume we'll miss the rest of the way
                        checkCache = false;
                    }
                }
                ancestry[j] = parent;
            }
        }
    }
    return ancestry[length - 1];
}
 
Example 10
Source File: DeploymentCompleteServiceProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static ServiceName serviceName(final ServiceName deploymentUnitServiceName) {
    return deploymentUnitServiceName.append(SERVICE_NAME);
}
 
Example 11
Source File: DeploymentHandlerUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void doDeploy(final OperationContext context, final String deploymentUnitName, final String managementName,
                            final Resource deploymentResource, final ImmutableManagementResourceRegistration registration,
                            final ManagementResourceRegistration mutableRegistration, final AbstractVaultReader vaultReader, final ContentItem... contents) {

    final ServiceName deploymentUnitServiceName = Services.deploymentUnitName(deploymentUnitName);

    final ServiceTarget serviceTarget = context.getServiceTarget();
    final ServiceController<?> contentService;
    // TODO: overlay service
    final ServiceName contentsServiceName = deploymentUnitServiceName.append("contents");
    boolean isExplodedContent = false;
    if (contents[0].hash != null) {
        if (contents[0].isArchive) {
            contentService = ContentServitor.addService(serviceTarget, contentsServiceName, contents[0].hash);
        } else {
            isExplodedContent = true;
            contentService = ManagedExplodedContentServitor.addService(serviceTarget, contentsServiceName, managementName, contents[0].hash);
        }
    }
    else {
        final String path = contents[0].path;
        final String relativeTo = contents[0].relativeTo;
        contentService = PathContentServitor.addService(context, serviceTarget, contentsServiceName, path, relativeTo);
    }
    DeploymentOverlayIndex overlays = DeploymentOverlayIndex.createDeploymentOverlayIndex(context);

    final RootDeploymentUnitService service = new RootDeploymentUnitService(deploymentUnitName, managementName, null,
            registration, mutableRegistration, deploymentResource, context.getCapabilityServiceSupport(), vaultReader, overlays,
            isExplodedContent);
    final ServiceController<DeploymentUnit> deploymentUnitController = serviceTarget.addService(deploymentUnitServiceName, service)
            .addDependency(Services.JBOSS_DEPLOYMENT_CHAINS, DeployerChains.class, service.getDeployerChainsInjector())
            .addDependency(DeploymentMountProvider.SERVICE_NAME, DeploymentMountProvider.class, service.getServerDeploymentRepositoryInjector())
            .addDependency(context.getCapabilityServiceName("org.wildfly.management.path-manager", PathManager.class), PathManager.class, service.getPathManagerInjector())
            .addDependency(contentsServiceName, VirtualFile.class, service.getContentsInjector())
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .install();

    contentService.addListener(new LifecycleListener() {
        @Override
        public void handleEvent(final ServiceController<?> controller, final LifecycleEvent event) {
            if (event == LifecycleEvent.REMOVED) {
                deploymentUnitController.setMode(REMOVE);
            }
        }
    });
}
 
Example 12
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 13
Source File: CamelEndpointDeployerService.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
public static ServiceName deployerServiceName(ServiceName deploymentUnitServiceName) {
    return deploymentUnitServiceName.append(SERVICE_NAME);
}
 
Example 14
Source File: CamelEndpointDeploymentSchedulerService.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
public static ServiceName deploymentSchedulerServiceName(ServiceName deploymentUnitServiceName) {
    return deploymentUnitServiceName.append(SERVICE_NAME);
}
 
Example 15
Source File: ThreadFactoryResolver.java    From wildfly-core with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Installs a {@link ThreadFactoryService} whose service name is the service name of the thread pool with {@code thread-factory} appended.
 *
 * @param threadPoolName the name of the thread pool
 * @param threadPoolServiceName the full name of the {@link org.jboss.msc.service.Service} that provides the thread pool
 * @param serviceTarget service target that is installing the thread pool service; can be used to install
 *                      a {@link org.jboss.as.threads.ThreadFactoryService}
 * @return the {@link ServiceName} of the {@link ThreadFactoryService} the thread pool should use. Cannot be
 *         {@code null}
 */
private ServiceName resolveDefaultThreadFactory(String threadPoolName, ServiceName threadPoolServiceName,
                                                ServiceTarget serviceTarget) {
    final ServiceName threadFactoryServiceName = threadPoolServiceName.append("thread-factory");
    final ThreadFactoryService service = new ThreadFactoryService();
    service.setThreadGroupName(getThreadGroupName(threadPoolName));
    service.setNamePattern("%G - %t");
    serviceTarget.addService(threadFactoryServiceName, service).install();
    return threadFactoryServiceName;
}
 
Example 16
Source File: ThreadFactoryResolver.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
    * Removes any default thread factory installed in {@link #resolveDefaultThreadFactory(String, org.jboss.msc.service.ServiceName, org.jboss.msc.service.ServiceTarget)}.
    *
    * @param threadPoolServiceName the full name of the {@link org.jboss.msc.service.Service} that provides the thread pool
    * @param context the context of the current operation; can be used to perform any necessary
*                {@link OperationContext#removeService(ServiceName) service removals}
    */
   private void releaseDefaultThreadFactory(ServiceName threadPoolServiceName, OperationContext context) {
       final ServiceName threadFactoryServiceName = threadPoolServiceName.append("thread-factory");
       context.removeService(threadFactoryServiceName);
   }