org.jboss.msc.service.ServiceController.Mode Java Examples

The following examples show how to use org.jboss.msc.service.ServiceController.Mode. 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: BindingAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static void installBindingService(OperationContext context, ModelNode config, String name)
        throws UnknownHostException, OperationFailedException {
    final CapabilityServiceTarget serviceTarget = context.getCapabilityServiceTarget();

    final ModelNode intfNode = AbstractSocketBindingResourceDefinition.INTERFACE.resolveModelAttribute(context, config);
    final String intf = intfNode.isDefined() ? intfNode.asString() : null;
    final int port = AbstractSocketBindingResourceDefinition.PORT.resolveModelAttribute(context, config).asInt();
    final boolean fixedPort = AbstractSocketBindingResourceDefinition.FIXED_PORT.resolveModelAttribute(context, config).asBoolean();
    final ModelNode mcastNode = AbstractSocketBindingResourceDefinition.MULTICAST_ADDRESS.resolveModelAttribute(context, config);
    final String mcastAddr = mcastNode.isDefined() ? mcastNode.asString() : null;
    final int mcastPort = AbstractSocketBindingResourceDefinition.MULTICAST_PORT.resolveModelAttribute(context, config).asInt(0);
    final InetAddress mcastInet = mcastAddr == null ? null : InetAddress.getByName(mcastAddr);
    final ModelNode mappingsNode = config.get(CLIENT_MAPPINGS);
    final List<ClientMapping> clientMappings = mappingsNode.isDefined() ? parseClientMappings(context, mappingsNode) : null;

    final CapabilityServiceBuilder<?> builder = serviceTarget.addCapability(SOCKET_BINDING_CAPABILITY);
    final Consumer<SocketBinding> sbConsumer = builder.provides(SOCKET_BINDING_CAPABILITY);
    final Supplier<NetworkInterfaceBinding> ibSupplier = intf != null ? builder.requiresCapability("org.wildfly.network.interface", NetworkInterfaceBinding.class, intf) : null;
    final Supplier<SocketBindingManager> sbSupplier = builder.requiresCapability("org.wildfly.management.socket-binding-manager", SocketBindingManager.class);
    final SocketBindingService service = new SocketBindingService(sbConsumer, ibSupplier, sbSupplier, name, port, fixedPort, mcastInet, mcastPort, clientMappings);
    builder.setInstance(service);
    builder.addAliases(SocketBinding.JBOSS_BINDING_NAME.append(name));
    builder.setInitialMode(Mode.ON_DEMAND);
    builder.install();
}
 
Example #2
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void deployServletProcessApplication(ServletProcessApplication processApplication) {

  ClassLoader contextClassloader = ClassLoaderUtil.getContextClassloader();
  String moduleName = ((ModuleClassLoader)contextClassloader).getModule().getIdentifier().toString();

  ServiceName serviceName = ServiceNames.forNoViewProcessApplicationStartService(moduleName);
  ServiceName paModuleService = ServiceNames.forProcessApplicationModuleService(moduleName);

  if(serviceContainer.getService(serviceName) == null) {

    ServiceController<ServiceTarget> requiredService = (ServiceController<ServiceTarget>) serviceContainer.getRequiredService(paModuleService);

    NoViewProcessApplicationStartService service = new NoViewProcessApplicationStartService(processApplication.getReference());
    requiredService.getValue()
      .addService(serviceName, service)
      .setInitialMode(Mode.ACTIVE)
      .install();

  }
}
 
Example #3
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void unregisterProcessEngine(ProcessEngine processEngine) {

  if(processEngine == null) {
    throw new ProcessEngineException("Cannot unregister process engine with Msc Runtime Container: process engine is 'null'");
  }

  ServiceName serviceName = ServiceNames.forManagedProcessEngine(processEngine.getName());

  // remove the service asynchronously
  ServiceController<ProcessEngine> service = (ServiceController<ProcessEngine>) serviceContainer.getService(serviceName);
  if(service != null && service.getService() instanceof MscManagedProcessEngine) {
    service.setMode(Mode.REMOVE);
  }

}
 
Example #4
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void registerProcessEngine(ProcessEngine processEngine) {

    if(processEngine == null) {
      throw new ProcessEngineException("Cannot register process engine with Msc Runtime Container: process engine is 'null'");
    }

    ServiceName serviceName = ServiceNames.forManagedProcessEngine(processEngine.getName());

    if(serviceContainer.getService(serviceName) == null) {
      MscManagedProcessEngine processEngineRegistration = new MscManagedProcessEngine(processEngine);

      // install the service asynchronously.
      childTarget.addService(serviceName, processEngineRegistration)
        .setInitialMode(Mode.ACTIVE)
        .addDependency(ServiceNames.forMscRuntimeContainerDelegate(), MscRuntimeContainerDelegate.class, processEngineRegistration.getRuntimeContainerDelegateInjector())
        .install();
    }

  }
 
Example #5
Source File: MscManagedProcessEngineController.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static void initializeServiceBuilder(ManagedProcessEngineMetadata processEngineConfiguration, MscManagedProcessEngineController service,
        ServiceBuilder<ProcessEngine> serviceBuilder, String jobExecutorName) {

  ContextNames.BindInfo datasourceBindInfo = ContextNames.bindInfoFor(processEngineConfiguration.getDatasourceJndiName());
  serviceBuilder.addDependency(ServiceName.JBOSS.append("txn").append("TransactionManager"), TransactionManager.class, service.getTransactionManagerInjector())
    .addDependency(datasourceBindInfo.getBinderServiceName(), DataSourceReferenceFactoryService.class, service.getDatasourceBinderServiceInjector())
    .addDependency(ServiceNames.forMscRuntimeContainerDelegate(), MscRuntimeContainerDelegate.class, service.getRuntimeContainerDelegateInjector())
    .addDependency(ServiceNames.forMscRuntimeContainerJobExecutorService(jobExecutorName), MscRuntimeContainerJobExecutor.class, service.getMscRuntimeContainerJobExecutorInjector())
    .addDependency(ServiceNames.forMscExecutorService())
    .setInitialMode(Mode.ACTIVE);

  if(processEngineConfiguration.isDefault()) {
    serviceBuilder.addAliases(ServiceNames.forDefaultProcessEngine());
  }

  JBossCompatibilityExtension.addServerExecutorDependency(serviceBuilder, service.getExecutorInjector(), false);

}
 
Example #6
Source File: JobExecutorAdd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void performRuntimeThreadPool(OperationContext context, ModelNode model, String name,
        ServiceName jobExecutorThreadPoolServiceName) throws OperationFailedException {

    ServiceTarget serviceTarget = context.getServiceTarget();

    ThreadFactoryService threadFactory = new ThreadFactoryService();
    threadFactory.setThreadGroupName(THREAD_POOL_GRP_NAME + name);

    ServiceName threadFactoryServiceName = ServiceNames.forThreadFactoryService(name);

    serviceTarget.addService(threadFactoryServiceName, threadFactory).install();

    final BoundedQueueThreadPoolService threadPoolService = new BoundedQueueThreadPoolService(
            SubsystemAttributeDefinitons.CORE_THREADS.resolveModelAttribute(context, model).asInt(),
            SubsystemAttributeDefinitons.MAX_THREADS.resolveModelAttribute(context, model).asInt(),
            SubsystemAttributeDefinitons.QUEUE_LENGTH.resolveModelAttribute(context, model).asInt(), false,
            new TimeSpec(TimeUnit.SECONDS,
                    SubsystemAttributeDefinitons.KEEPALIVE_TIME.resolveModelAttribute(context, model).asInt()),
            SubsystemAttributeDefinitons.ALLOW_CORE_TIMEOUT.resolveModelAttribute(context, model).asBoolean());

    serviceTarget.addService(jobExecutorThreadPoolServiceName, threadPoolService)
            .addDependency(threadFactoryServiceName, ThreadFactory.class,
                    threadPoolService.getThreadFactoryInjector())
            .setInitialMode(ServiceController.Mode.ACTIVE).install();
}
 
Example #7
Source File: JobExecutorAdd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model)
        throws OperationFailedException {

    String jobExecutorThreadPoolName =
            SubsystemAttributeDefinitons.THREAD_POOL_NAME.resolveModelAttribute(context, model).asString();
    ServiceName jobExecutorThreadPoolServiceName = ServiceNames.forManagedThreadPool(jobExecutorThreadPoolName);

    performRuntimeThreadPool(context, model, jobExecutorThreadPoolName, jobExecutorThreadPoolServiceName);

    MscExecutorService service = new MscExecutorService();
    ServiceController<MscExecutorService> serviceController =
            context.getServiceTarget().addService(ServiceNames.forMscExecutorService(), service)
                    .addDependency(jobExecutorThreadPoolServiceName, ManagedQueueExecutorService.class,
                            service.getManagedQueueInjector())
                    .setInitialMode(Mode.ACTIVE).install();
}
 
Example #8
Source File: JobAcquisitionAdd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {

  String acquisitionName = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();

  MscRuntimeContainerJobExecutor mscRuntimeContainerJobExecutor = new MscRuntimeContainerJobExecutor();

  if (model.hasDefined(SubsystemAttributeDefinitons.PROPERTIES.getName())) {
    List<Property> properties = SubsystemAttributeDefinitons.PROPERTIES.resolveModelAttribute(context, model).asPropertyList();
    for (Property property : properties) {
      PropertyHelper.applyProperty(mscRuntimeContainerJobExecutor, property.getName(), property.getValue().asString());
    }
  }

  // start new service for job executor
  ServiceController<RuntimeContainerJobExecutor> serviceController = context.getServiceTarget().addService(ServiceNames.forMscRuntimeContainerJobExecutorService(acquisitionName), mscRuntimeContainerJobExecutor)
    .addDependency(ServiceNames.forMscRuntimeContainerDelegate())
    .addDependency(ServiceNames.forMscExecutorService())
    .setInitialMode(Mode.ACTIVE)
    .install();
}
 
Example #9
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void deployServletProcessApplication(ServletProcessApplication processApplication) {

  ClassLoader contextClassloader = ClassLoaderUtil.getContextClassloader();
  String moduleName = ((ModuleClassLoader)contextClassloader).getModule().getIdentifier().toString();

  ServiceName serviceName = ServiceNames.forNoViewProcessApplicationStartService(moduleName);
  ServiceName paModuleService = ServiceNames.forProcessApplicationModuleService(moduleName);

  if(serviceContainer.getService(serviceName) == null) {

    ServiceController<ServiceTarget> requiredService = (ServiceController<ServiceTarget>) serviceContainer.getRequiredService(paModuleService);

    NoViewProcessApplicationStartService service = new NoViewProcessApplicationStartService(processApplication.getReference());
    requiredService.getValue()
      .addService(serviceName, service)
      .setInitialMode(Mode.ACTIVE)
      .install();

  }
}
 
Example #10
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void unregisterProcessEngine(ProcessEngine processEngine) {

  if(processEngine == null) {
    throw new ProcessEngineException("Cannot unregister process engine with Msc Runtime Container: process engine is 'null'");
  }

  ServiceName serviceName = ServiceNames.forManagedProcessEngine(processEngine.getName());

  // remove the service asynchronously
  ServiceController<ProcessEngine> service = (ServiceController<ProcessEngine>) serviceContainer.getService(serviceName);
  if(service != null && service.getService() instanceof MscManagedProcessEngine) {
    service.setMode(Mode.REMOVE);
  }

}
 
Example #11
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void registerProcessEngine(ProcessEngine processEngine) {

    if(processEngine == null) {
      throw new ProcessEngineException("Cannot register process engine with Msc Runtime Container: process engine is 'null'");
    }

    ServiceName serviceName = ServiceNames.forManagedProcessEngine(processEngine.getName());

    if(serviceContainer.getService(serviceName) == null) {
      MscManagedProcessEngine processEngineRegistration = new MscManagedProcessEngine(processEngine);

      // install the service asynchronously.
      childTarget.addService(serviceName, processEngineRegistration)
        .setInitialMode(Mode.ACTIVE)
        .addDependency(ServiceNames.forMscRuntimeContainerDelegate(), MscRuntimeContainerDelegate.class, processEngineRegistration.getRuntimeContainerDelegateInjector())
        .install();
    }

  }
 
Example #12
Source File: MscManagedProcessEngineController.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static void initializeServiceBuilder(ManagedProcessEngineMetadata processEngineConfiguration, MscManagedProcessEngineController service,
        ServiceBuilder<ProcessEngine> serviceBuilder, String jobExecutorName) {

  ContextNames.BindInfo datasourceBindInfo = ContextNames.bindInfoFor(processEngineConfiguration.getDatasourceJndiName());
  serviceBuilder.addDependency(ServiceName.JBOSS.append("txn").append("TransactionManager"), TransactionManager.class, service.getTransactionManagerInjector())
    .addDependency(datasourceBindInfo.getBinderServiceName(), DataSourceReferenceFactoryService.class, service.getDatasourceBinderServiceInjector())
    .addDependency(ServiceNames.forMscRuntimeContainerDelegate(), MscRuntimeContainerDelegate.class, service.getRuntimeContainerDelegateInjector())
    .addDependency(ServiceNames.forMscRuntimeContainerJobExecutorService(jobExecutorName), MscRuntimeContainerJobExecutor.class, service.getMscRuntimeContainerJobExecutorInjector())
    .addDependency(ServiceNames.forMscExecutorService())
    .setInitialMode(Mode.ACTIVE);

  if(processEngineConfiguration.isDefault()) {
    serviceBuilder.addAliases(ServiceNames.forDefaultProcessEngine());
  }

  JBossCompatibilityExtension.addServerExecutorDependency(serviceBuilder, service.getExecutorInjector(), false);

}
 
Example #13
Source File: JobExecutorAdd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model,
        ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers)
        throws OperationFailedException {
  
  if (!operation.hasDefined(THREAD_POOL_NAME)) {
    throw new ProcessEngineException("Unable to configure threadpool for ContainerJobExecutorService, missing element '" + THREAD_POOL_NAME + "' in JobExecutor configuration.");
  }
  
  String jobExecutorThreadPoolName = SubsystemAttributeDefinitons.THREAD_POOL_NAME.resolveModelAttribute(context, model).asString();

  MscExecutorService service = new MscExecutorService();
  ServiceController<MscExecutorService> serviceController = context.getServiceTarget().addService(ServiceNames.forMscExecutorService(), service)
      .addDependency(ThreadsServices.EXECUTOR.append(jobExecutorThreadPoolName), ManagedQueueExecutorService.class, service.getManagedQueueInjector())
      .addListener(verificationHandler)
      .setInitialMode(Mode.ACTIVE)
      .install();
  
  newControllers.add(serviceController);
  
}
 
Example #14
Source File: SecureServerDefinition.java    From keycloak with Apache License 2.0 6 votes vote down vote up
static void installCapability(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress pathAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
    String factoryName = pathAddress.getLastElement().getValue();
    ServiceName serviceName = context.getCapabilityServiceName(HTTP_SERVER_AUTHENTICATION_CAPABILITY, factoryName, HttpServerAuthenticationMechanismFactory.class);
    boolean publicClient = SecureServerDefinition.PUBLIC_CLIENT.resolveModelAttribute(context, operation).asBoolean(false);

    if (!publicClient) {
        throw new OperationFailedException("Only public clients are allowed to have their configuration exposed through the management interface");
    }

    KeycloakHttpAuthenticationFactoryService service = new KeycloakHttpAuthenticationFactoryService(factoryName);
    ServiceTarget serviceTarget = context.getServiceTarget();
    InjectedValue<ExtensibleHttpManagement> injectedValue = new InjectedValue<>();
    serviceTarget.addService(serviceName.append("http-management-context"), createHttpManagementConfigContextService(factoryName, injectedValue))
            .addDependency(context.getCapabilityServiceName(HTTP_MANAGEMENT_HTTP_EXTENSIBLE_CAPABILITY, ExtensibleHttpManagement.class), ExtensibleHttpManagement.class, injectedValue).setInitialMode(Mode.ACTIVE).install();
    serviceTarget.addService(serviceName, service).setInitialMode(Mode.ACTIVE).install();
}
 
Example #15
Source File: ModuleSpecProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void installAliases(final ModuleSpecification moduleSpecification, final ModuleIdentifier moduleIdentifier, final DeploymentUnit deploymentUnit, final DeploymentPhaseContext phaseContext) {

        ModuleLoader moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
        for (final ModuleIdentifier alias : moduleSpecification.getAliases()) {
            final ServiceName moduleSpecServiceName = ServiceModuleLoader.moduleSpecServiceName(alias);
            final ModuleSpec spec = ModuleSpec.buildAlias(alias, moduleIdentifier).create();

            HashSet<ModuleDependency> dependencies = new HashSet<>(moduleSpecification.getAllDependencies());
            //we need to add the module we are aliasing as a dependency, to make sure that it will be resolved
            dependencies.add(new ModuleDependency(moduleLoader, moduleIdentifier, false, false, false, false));
            ModuleDefinition moduleDefinition = new ModuleDefinition(alias, dependencies, spec);

            final ValueService<ModuleDefinition> moduleSpecService = new ValueService<>(new ImmediateValue<>(moduleDefinition));
            final ServiceBuilder sb = phaseContext.getServiceTarget().addService(moduleSpecServiceName, moduleSpecService);
            sb.requires(deploymentUnit.getServiceName());
            sb.requires(phaseContext.getPhaseServiceName());
            sb.setInitialMode(Mode.ON_DEMAND);
            sb.install();

            ModuleLoadService.installAliases(phaseContext.getServiceTarget(), alias, Collections.singletonList(moduleIdentifier));

            ModuleResolvePhaseService.installService(phaseContext.getServiceTarget(), moduleDefinition);
        }
    }
 
Example #16
Source File: VirtualSecurityDomainProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (deploymentUnit.getParent() != null || !isVirtualDomainRequired(deploymentUnit)) {
        return;  // Only interested in installation if this is really the root deployment.
    }

    ServiceName virtualDomainName = virtualDomainName(deploymentUnit);
    ServiceTarget serviceTarget = phaseContext.getServiceTarget();

    ServiceBuilder<?> serviceBuilder = serviceTarget.addService(virtualDomainName);

    final SecurityDomain virtualDomain = SecurityDomain.builder().build();
    final Consumer<SecurityDomain> consumer = serviceBuilder.provides(virtualDomainName);

    serviceBuilder.setInstance(Service.newInstance(consumer, virtualDomain));
    serviceBuilder.setInitialMode(Mode.ON_DEMAND);
    serviceBuilder.install();
}
 
Example #17
Source File: EmptyResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {

ServiceTarget serviceTarget = context.getServiceTarget();
RuntimeCapability<?> runtimeCapability = this.runtimeCapability.fromBaseCapability(context.getCurrentAddressValue());
ServiceName componentName = runtimeCapability.getCapabilityServiceName(valueType);

TrivialService<T> componentService = new TrivialService<T>(valueSupplier);

ServiceBuilder<T> componentBuilder = serviceTarget.addService(componentName, componentService);

commonDependencies(componentBuilder)
    .setInitialMode(Mode.LAZY)
    .install();
}
 
Example #18
Source File: CustomComponentDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {
    ServiceTarget serviceTarget = context.getServiceTarget();

    String address = context.getCurrentAddressValue();
    RuntimeCapability<?> primaryCapability = runtimeCapabilities[0];
    ServiceName primaryServiceName = toServiceName(primaryCapability, address);

    final String module = MODULE.resolveModelAttribute(context, model).asStringOrNull();
    final String className = CLASS_NAME.resolveModelAttribute(context, model).asString();

    final Map<String, String> configurationMap;
    configurationMap = CONFIGURATION.unwrap(context, model);

    ServiceBuilder<?> serviceBuilder = serviceTarget.addService(primaryServiceName);
    for (int i = 1; i < runtimeCapabilities.length; i++) {
        serviceBuilder.addAliases(toServiceName(runtimeCapabilities[i], address));
    }

    commonRequirements(serviceBuilder)
        .setInstance(new TrivialService<>(() -> createValue(module, className, configurationMap)))
        .setInitialMode(Mode.ACTIVE)
        .install();
}
 
Example #19
Source File: KeyStoreRealmDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {
    ServiceTarget serviceTarget = context.getServiceTarget();
    RuntimeCapability<Void> runtimeCapability = SECURITY_REALM_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName realmName = runtimeCapability.getCapabilityServiceName(SecurityRealm.class);

    final InjectedValue<KeyStore> keyStore = new InjectedValue<KeyStore>();
    TrivialService<SecurityRealm> keyStoreRealmService = new TrivialService<SecurityRealm>(() -> new KeyStoreBackedSecurityRealm(keyStore.getValue()));

    ServiceBuilder<SecurityRealm> serviceBuilder = serviceTarget.addService(realmName, keyStoreRealmService);

    String keyStoreCapabilityName = RuntimeCapability.buildDynamicCapabilityName(KEY_STORE_CAPABILITY, KEYSTORE.resolveModelAttribute(context, model).asString());
    ServiceName keyStoreServiceName = context.getCapabilityServiceName(keyStoreCapabilityName, KeyStore.class);
    KEY_STORE_UTIL.addInjection(serviceBuilder, keyStore, keyStoreServiceName);
    commonDependencies(serviceBuilder)
        .setInitialMode(Mode.ACTIVE)
        .install();
}
 
Example #20
Source File: AggregateComponentDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {
    ServiceTarget serviceTarget = context.getServiceTarget();
    RuntimeCapability<?> instanceRuntimeCapability = runtimeCapability.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName componentName = instanceRuntimeCapability.getCapabilityServiceName(aggregationType);

    AggregateComponentService<T> aggregateComponentService = new AggregateComponentService<T>(aggregationType, aggregator);

    ServiceBuilder<T> serviceBuilder = serviceTarget.addService(componentName, aggregateComponentService);

    List<String> aggregates = aggregateReferences.unwrap(context, model);

    String baseCapabilityName = runtimeCapability.getName();
    for (String current : aggregates) {
        String runtimeCapabilityName = RuntimeCapability.buildDynamicCapabilityName(baseCapabilityName, current);
        ServiceName realmServiceName = context.getCapabilityServiceName(runtimeCapabilityName, aggregationType);

        serviceBuilder.addDependency(realmServiceName, aggregationType, aggregateComponentService.newInjector());
    }

    commonDependencies(serviceBuilder, true, dependOnProviderRegistration)
        .setInitialMode(Mode.LAZY)
        .install();
}
 
Example #21
Source File: RoleDecoderDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {
    ServiceTarget serviceTarget = context.getServiceTarget();
    RuntimeCapability<Void> runtimeCapability = ROLE_DECODER_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName roleDecoderName = runtimeCapability.getCapabilityServiceName(RoleDecoder.class);

    final String attribute = ATTRIBUTE.resolveModelAttribute(context, model).asString();
    TrivialService<RoleDecoder> roleDecoderService = new TrivialService<RoleDecoder>(() -> RoleDecoder.simple(attribute));

    ServiceBuilder<RoleDecoder> roleDecoderBuilderBuilder = serviceTarget.addService(roleDecoderName, roleDecoderService);

    commonDependencies(roleDecoderBuilderBuilder)
        .setInitialMode(Mode.LAZY)
        .install();
}
 
Example #22
Source File: RoleDecoderDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {
    ServiceTarget serviceTarget = context.getServiceTarget();
    RuntimeCapability<Void> runtimeCapability = ROLE_DECODER_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName roleDecoderName = runtimeCapability.getCapabilityServiceName(RoleDecoder.class);
    final String sourceAddress = SOURCE_ADDRESS.resolveModelAttribute(context, model).asStringOrNull();
    final String pattern = PATTERN.resolveModelAttribute(context, model).asStringOrNull();
    final List<String> roles = ROLES.unwrap(context, model);

    TrivialService<RoleDecoder> roleDecoderService;
    // one of 'source-address' or 'pattern' must be specified
    if (sourceAddress != null) {
        roleDecoderService = new TrivialService<>(() -> new SourceAddressRoleDecoder(sourceAddress, Roles.fromSet(new HashSet<>(roles))));
    } else {
        roleDecoderService = new TrivialService<>(() -> new SourceAddressRoleDecoder(Pattern.compile(pattern), Roles.fromSet(new HashSet<>(roles))));
    }

    ServiceBuilder<RoleDecoder> roleDecoderBuilderBuilder = serviceTarget.addService(roleDecoderName, roleDecoderService);

    commonDependencies(roleDecoderBuilderBuilder)
            .setInitialMode(Mode.LAZY)
            .install();
}
 
Example #23
Source File: JobAcquisitionAdd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model,
        ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers)
        throws OperationFailedException {

  String acquisitionName = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();

  MscRuntimeContainerJobExecutor mscRuntimeContainerJobExecutor = new MscRuntimeContainerJobExecutor();

  if (model.hasDefined(PROPERTIES)) {

    List<Property> properties = SubsystemAttributeDefinitons.PROPERTIES.resolveModelAttribute(context, model).asPropertyList();

    for (Property property : properties) {
      String name = property.getName();
      String value = property.getValue().asString();
      PropertyHelper.applyProperty(mscRuntimeContainerJobExecutor, name, value);
    }

  }

  // start new service for job executor
  ServiceController<RuntimeContainerJobExecutor> serviceController = context.getServiceTarget().addService(ServiceNames.forMscRuntimeContainerJobExecutorService(acquisitionName), mscRuntimeContainerJobExecutor)
    .addDependency(ServiceNames.forMscRuntimeContainerDelegate())
    .addDependency(ServiceNames.forMscExecutorService())
    .addListener(verificationHandler)
    .setInitialMode(Mode.ACTIVE)
    .install();

  newControllers.add(serviceController);

}
 
Example #24
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Supplier<CallbackHandlerService> addUsersService(OperationContext context, ModelNode users, String realmName, ServiceTarget serviceTarget,
                             ServiceBuilder<?> realmBuilder) throws OperationFailedException {
    final ServiceName usersServiceName = UserDomainCallbackHandler.ServiceUtil.createServiceName(realmName);
    final ServiceBuilder<?> builder = serviceTarget.addService(usersServiceName);
    final Consumer<CallbackHandlerService> chsConsumer = builder.provides(usersServiceName);
    builder.setInstance(new UserDomainCallbackHandler(chsConsumer, unmaskUsersCredentials(context, builder, users.clone()), realmName, unmaskUsersPasswords(context, users)));
    builder.setInitialMode(ServiceController.Mode.ON_DEMAND);
    builder.install();

    return CallbackHandlerService.ServiceUtil.requires(realmBuilder, usersServiceName);
}
 
Example #25
Source File: TrivialAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
TrivialAddHandler(Class<T> serviceType, Mode initialMode, Mode adminOnlyInitialMode, AttributeDefinition[] attributes, RuntimeCapability<?> runtimeCapability) {
    super(new HashSet<>(Collections.singletonList(checkNotNullParam("runtimeCapabilities", runtimeCapability))), attributes);
    this.runtimeCapability = runtimeCapability;
    checkNotNullParam("serviceType", serviceType);
    this.initialMode = checkNotNullParam("initialMode", initialMode);
    this.adminOnlyInitialMode = checkNotNullParam("adminOnlyInitialMode", adminOnlyInitialMode);
}
 
Example #26
Source File: RealmMapperDefinitions.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, ModelNode model)
        throws OperationFailedException {
    ServiceTarget serviceTarget = context.getServiceTarget();
    RuntimeCapability<Void> runtimeCapability = REALM_MAPPER_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName realmMapperName = runtimeCapability.getCapabilityServiceName(RealmMapper.class);

    final String pattern = PATTERN_CAPTURE_GROUP.resolveModelAttribute(context, model).asString();
    String delegateRealmMapper = DELEGATE_REALM_MAPPER.resolveModelAttribute(context, model).asStringOrNull();

    final InjectedValue<RealmMapper> delegateRealmMapperInjector = new InjectedValue<RealmMapper>();

    TrivialService<RealmMapper> realmMapperService = new TrivialService<RealmMapper>(() -> {
        RealmMapper delegate = delegateRealmMapperInjector.getOptionalValue();
        Pattern compiledPattern = Pattern.compile(pattern);
        if (delegate == null) {
            return new SimpleRegexRealmMapper(compiledPattern);
        } else {
            return new SimpleRegexRealmMapper(compiledPattern, delegate);
        }
    });

    ServiceBuilder<RealmMapper> realmMapperBuilder = serviceTarget.addService(realmMapperName, realmMapperService);

    if (delegateRealmMapper != null) {
        String delegateCapabilityName = RuntimeCapability.buildDynamicCapabilityName(REALM_MAPPER_CAPABILITY, delegateRealmMapper);
        ServiceName delegateServiceName = context.getCapabilityServiceName(delegateCapabilityName, RealmMapper.class);

        realmMapperBuilder.addDependency(delegateServiceName, RealmMapper.class, delegateRealmMapperInjector);
    }

    commonDependencies(realmMapperBuilder)
        .setInitialMode(Mode.LAZY)
        .install();
}
 
Example #27
Source File: BpmPlatformSubsystemAdd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {

  // add deployment processors
  context.addStep(new AbstractDeploymentChainStep() {
    public void execute(DeploymentProcessorTarget processorTarget) {
      processorTarget.addDeploymentProcessor(ModelConstants.SUBSYSTEM_NAME, Phase.PARSE, ProcessApplicationProcessor.PRIORITY, new ProcessApplicationProcessor());
      processorTarget.addDeploymentProcessor(ModelConstants.SUBSYSTEM_NAME, Phase.DEPENDENCIES, ModuleDependencyProcessor.PRIORITY, new ModuleDependencyProcessor());
      processorTarget.addDeploymentProcessor(ModelConstants.SUBSYSTEM_NAME, Phase.POST_MODULE, ProcessesXmlProcessor.PRIORITY, new ProcessesXmlProcessor());
      processorTarget.addDeploymentProcessor(ModelConstants.SUBSYSTEM_NAME, Phase.INSTALL, ProcessEngineStartProcessor.PRIORITY, new ProcessEngineStartProcessor());
      processorTarget.addDeploymentProcessor(ModelConstants.SUBSYSTEM_NAME, Phase.INSTALL, ProcessApplicationDeploymentProcessor.PRIORITY, new ProcessApplicationDeploymentProcessor());
    }
  }, OperationContext.Stage.RUNTIME);

  // create and register the MSC container delegate.
  final MscRuntimeContainerDelegate processEngineService = new MscRuntimeContainerDelegate();

  final ServiceController<MscRuntimeContainerDelegate> controller = context.getServiceTarget()
          .addService(ServiceNames.forMscRuntimeContainerDelegate(), processEngineService)
          .setInitialMode(Mode.ACTIVE)
          .install();

  // discover and register bpm platform plugins
  BpmPlatformPlugins plugins = BpmPlatformPlugins.load(getClass().getClassLoader());
  MscBpmPlatformPlugins managedPlugins = new MscBpmPlatformPlugins(plugins);

  ServiceController<BpmPlatformPlugins> serviceController = context.getServiceTarget()
    .addService(ServiceNames.forBpmPlatformPlugins(), managedPlugins)
    .setInitialMode(Mode.ACTIVE)
    .install();
}
 
Example #28
Source File: SaslServerDefinitions.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, ModelNode model)
        throws OperationFailedException {
    RuntimeCapability<Void> runtimeCapability = SASL_SERVER_FACTORY_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName saslServerFactoryName = runtimeCapability.getCapabilityServiceName(SaslServerFactory.class);

    commonDependencies(installService(context, saslServerFactoryName, model))
        .setInitialMode(Mode.ACTIVE)
        .install();
}
 
Example #29
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void addPlugInLoaderService(String realmName, ModelNode plugInModel, ServiceTarget serviceTarget) {
    final ServiceName plugInLoaderName = PlugInLoaderService.ServiceUtil.createServiceName(realmName);
    final List<Property> plugIns = plugInModel.asPropertyList();
    final ArrayList<String> knownNames = new ArrayList<String>(plugIns.size());
    for (Property current : plugIns) {
        knownNames.add(current.getName());
    }
    final ServiceBuilder<?> builder = serviceTarget.addService(plugInLoaderName);
    final Consumer<PlugInLoaderService> pilsConsumer = builder.provides(plugInLoaderName);
    builder.setInstance(new PlugInLoaderService(pilsConsumer, Collections.unmodifiableList(knownNames)));
    builder.setInitialMode(Mode.ON_DEMAND);
    builder.install();
}
 
Example #30
Source File: BpmPlatformSubsystemAdd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model, ServiceVerificationHandler verificationHandler,
        List<ServiceController< ? >> newControllers) throws OperationFailedException {

  // add deployment processors
  context.addStep(new AbstractDeploymentChainStep() {
    public void execute(DeploymentProcessorTarget processorTarget) {
      processorTarget.addDeploymentProcessor(ModelConstants.SUBSYSTEM_NAME, Phase.PARSE, ProcessApplicationProcessor.PRIORITY, new ProcessApplicationProcessor());
      processorTarget.addDeploymentProcessor(ModelConstants.SUBSYSTEM_NAME, Phase.DEPENDENCIES, ModuleDependencyProcessor.PRIORITY, new ModuleDependencyProcessor());
      processorTarget.addDeploymentProcessor(ModelConstants.SUBSYSTEM_NAME, Phase.POST_MODULE, ProcessesXmlProcessor.PRIORITY, new ProcessesXmlProcessor());
      processorTarget.addDeploymentProcessor(ModelConstants.SUBSYSTEM_NAME, Phase.INSTALL, ProcessEngineStartProcessor.PRIORITY, new ProcessEngineStartProcessor());
      processorTarget.addDeploymentProcessor(ModelConstants.SUBSYSTEM_NAME, Phase.INSTALL, ProcessApplicationDeploymentProcessor.PRIORITY, new ProcessApplicationDeploymentProcessor());
    }
  }, OperationContext.Stage.RUNTIME);

  // create and register the MSC container delegate.
  final MscRuntimeContainerDelegate processEngineService = new MscRuntimeContainerDelegate();

  final ServiceController<MscRuntimeContainerDelegate> controller = context.getServiceTarget()
          .addService(ServiceNames.forMscRuntimeContainerDelegate(), processEngineService)
          .addListener(verificationHandler)
          .setInitialMode(Mode.ACTIVE)
          .install();

  newControllers.add(controller);

  // discover and register bpm platform plugins
  BpmPlatformPlugins plugins = BpmPlatformPlugins.load(getClass().getClassLoader());
  MscBpmPlatformPlugins managedPlugins = new MscBpmPlatformPlugins(plugins);

  ServiceController<BpmPlatformPlugins> serviceController = context.getServiceTarget()
    .addService(ServiceNames.forBpmPlatformPlugins(), managedPlugins)
    .addListener(verificationHandler)
    .setInitialMode(Mode.ACTIVE)
    .install();

  newControllers.add(serviceController);
}