Java Code Examples for org.jboss.msc.service.ServiceContainer#getService()

The following examples show how to use org.jboss.msc.service.ServiceContainer#getService() . 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: JBossSubsystemXMLTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testInstallSubsystemXmlPlatformPlugins() throws Exception {
  String subsystemXml = FileUtils.readFile(SUBSYSTEM_WITH_PROCESS_ENGINES_ELEMENT_ONLY);

  KernelServices services = createKernelServicesBuilder(null)
      .setSubsystemXml(subsystemXml)
      .build();

  ServiceContainer container = services.getContainer();
  ServiceController<?> serviceController = container.getService(ServiceNames.forBpmPlatformPlugins());
  assertNotNull(serviceController);
  Object platformPlugins = serviceController.getValue();
  assertTrue(platformPlugins instanceof BpmPlatformPlugins);
  assertNotNull(platformPlugins);
  List<BpmPlatformPlugin> plugins = ((BpmPlatformPlugins) platformPlugins).getPlugins();
  assertEquals(1, plugins.size());
  assertTrue(plugins.get(0) instanceof ExampleBpmPlatformPlugin);
}
 
Example 2
Source File: JBossSubsystemXMLTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testInstallSubsystemXmlPlatformPlugins() throws Exception {
  String subsystemXml = FileUtils.readFile(SUBSYSTEM_WITH_PROCESS_ENGINES_ELEMENT_ONLY);

  KernelServices services = createKernelServicesBuilder(null)
      .setSubsystemXml(subsystemXml)
      .build();

  ServiceContainer container = services.getContainer();
  ServiceController<?> serviceController = container.getService(PLATFORM_BPM_PLATFORM_PLUGINS_SERVICE_NAME);
  assertNotNull(serviceController);
  Object platformPlugins = serviceController.getValue();
  assertNotNull(platformPlugins);
  assertTrue(platformPlugins instanceof BpmPlatformPlugins);
  List<BpmPlatformPlugin> plugins = ((BpmPlatformPlugins) platformPlugins).getPlugins();
  assertEquals(1, plugins.size());
  assertTrue(plugins.get(0) instanceof ExampleBpmPlatformPlugin);
}
 
Example 3
Source File: BootstrapImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static SuspendController getSuspendController(ServiceContainer sc) {
    SuspendController result = null;
    if (sc != null && !sc.isShutdownComplete()) {
        final ServiceController serviceController = sc.getService(JBOSS_SUSPEND_CONTROLLER);
        if (serviceController != null && serviceController.getState() == ServiceController.State.UP) {
            result = (SuspendController) serviceController.getValue();
        }
    }
    return result;
}
 
Example 4
Source File: JBossSubsystemXMLTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testInstallSubsystemWithEnginesAndPropertiesXml() throws Exception {
  String subsystemXml = FileUtils.readFile(SUBSYSTEM_WITH_ENGINES_AND_PROPERTIES);

  KernelServices services = createKernelServicesBuilder(null)
      .setSubsystemXml(subsystemXml)
      .build();
  ServiceContainer container = services.getContainer();


  assertNotNull("platform service should be installed", container.getService(PLATFORM_SERVICE_NAME));
  assertNotNull("process engine service should be bound in JNDI", container.getService(processEngineServiceBindingServiceName));

  ServiceController<?> defaultEngineService = container.getService(ServiceNames.forManagedProcessEngine("__default"));

  assertNotNull("process engine controller for engine __default is installed ", defaultEngineService);

  ManagedProcessEngineMetadata metadata = ((MscManagedProcessEngineController) defaultEngineService.getService()).getProcessEngineMetadata();
  Map<String, String> configurationProperties = metadata.getConfigurationProperties();
  assertEquals("default", configurationProperties.get("job-name"));
  assertEquals("default", configurationProperties.get("job-acquisition"));
  assertEquals("default", configurationProperties.get("job-acquisition-name"));

  Map<String, String> foxLegacyProperties = metadata.getFoxLegacyProperties();
  assertTrue(foxLegacyProperties.isEmpty());

  assertNotNull("process engine controller for engine __test is installed ", container.getService(ServiceNames.forManagedProcessEngine("__test")));
  assertNotNull("process engine controller for engine __emptyPropertiesTag is installed ", container.getService(ServiceNames.forManagedProcessEngine("__emptyPropertiesTag")));
  assertNotNull("process engine controller for engine __noPropertiesTag is installed ", container.getService(ServiceNames.forManagedProcessEngine("__noPropertiesTag")));
}
 
Example 5
Source File: JBossSubsystemXMLTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testInstallSubsystemWithEnginesAndPropertiesXml() throws Exception {
  String subsystemXml = FileUtils.readFile(SUBSYSTEM_WITH_ENGINES_AND_PROPERTIES);

  KernelServices services = createKernelServicesBuilder(null)
      .setSubsystemXml(subsystemXml)
      .build();
  ServiceContainer container = services.getContainer();


  assertNotNull("platform service should be installed", container.getService(PLATFORM_SERVICE_NAME));
  assertNotNull("process engine service should be bound in JNDI", container.getService(PROCESS_ENGINE_SERVICE_BINDING_SERVICE_NAME));

  ServiceController<?> defaultEngineService = container.getService(ServiceNames.forManagedProcessEngine("__default"));

  assertNotNull("process engine controller for engine __default is installed ", defaultEngineService);

  ManagedProcessEngineMetadata metadata = ((MscManagedProcessEngineController) defaultEngineService.getService()).getProcessEngineMetadata();
  Map<String, String> configurationProperties = metadata.getConfigurationProperties();
  assertEquals("default", configurationProperties.get("job-name"));
  assertEquals("default", configurationProperties.get("job-acquisition"));
  assertEquals("default", configurationProperties.get("job-acquisition-name"));

  Map<String, String> foxLegacyProperties = metadata.getFoxLegacyProperties();
  assertTrue(foxLegacyProperties.isEmpty());

  assertNotNull("process engine controller for engine __test is installed ", container.getService(ServiceNames.forManagedProcessEngine("__test")));
  assertNotNull("process engine controller for engine __emptyPropertiesTag is installed ", container.getService(ServiceNames.forManagedProcessEngine("__emptyPropertiesTag")));
  assertNotNull("process engine controller for engine __noPropertiesTag is installed ", container.getService(ServiceNames.forManagedProcessEngine("__noPropertiesTag")));
}
 
Example 6
Source File: JBossSubsystemXMLTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testInstallSubsystemWithJobExecutorAndPropertiesXml() throws Exception {
  String subsystemXml = FileUtils.readFile(SUBSYSTEM_WITH_JOB_EXECUTOR_AND_PROPERTIES);

  KernelServices services = createKernelServicesBuilder(null)
      .setSubsystemXml(subsystemXml)
      .build();
  ServiceContainer container = services.getContainer();

  assertNotNull("platform service should be installed", container.getService(PLATFORM_SERVICE_NAME));
  assertNotNull("process engine service should be bound in JNDI", container.getService(processEngineServiceBindingServiceName));

  assertNotNull("platform jobexecutor service should be installed", container.getService(PLATFORM_JOBEXECUTOR_SERVICE_NAME));

  // "default" job acquisition ///////////////////////////////////////////////////////////
  ServiceController<?> defaultJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("default"));
  assertNotNull("platform job acquisition service 'default' should be installed", defaultJobAcquisitionService);

  Object value = defaultJobAcquisitionService.getValue();
  assertNotNull(value);
  assertTrue(value instanceof JobExecutor);

  JobExecutor defaultJobExecutor = (JobExecutor) value;
  assertEquals(300000, defaultJobExecutor.getLockTimeInMillis());
  assertEquals(5000, defaultJobExecutor.getWaitTimeInMillis());
  assertEquals(3, defaultJobExecutor.getMaxJobsPerAcquisition());

  // "anders" job acquisition /////////////////////////////////////////////////////////
  ServiceController<?> andersJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("anders"));
  assertNotNull("platform job acquisition service 'anders' should be installed", andersJobAcquisitionService);

  value = andersJobAcquisitionService.getValue();
  assertNotNull(value);
  assertTrue(value instanceof JobExecutor);

  JobExecutor andersJobExecutor = (JobExecutor) value;
  assertEquals(600000, andersJobExecutor.getLockTimeInMillis());
  assertEquals(10000, andersJobExecutor.getWaitTimeInMillis());
  assertEquals(5, andersJobExecutor.getMaxJobsPerAcquisition());

  // "mixed" job acquisition /////////////////////////////////////////////////////////
  ServiceController<?> mixedJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("mixed"));
  assertNotNull("platform job acquisition service 'mixed' should be installed", mixedJobAcquisitionService);

  value = mixedJobAcquisitionService.getValue();
  assertNotNull(value);
  assertTrue(value instanceof JobExecutor);

  JobExecutor mixedJobExecutor = (JobExecutor) value;
  assertEquals(500000, mixedJobExecutor.getLockTimeInMillis());
  // default values
  assertEquals(5000, mixedJobExecutor.getWaitTimeInMillis());
  assertEquals(3, mixedJobExecutor.getMaxJobsPerAcquisition());

}
 
Example 7
Source File: JBossSubsystemXMLTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testInstallSubsystemXmlWithEnginePropertiesPluginsAndJobExecutorWithExpressions() throws Exception {
  System.getProperties().putAll(EXPRESSION_PROPERTIES);
  try {
    String subsystemXml = FileUtils.readFile(SUBSYSTEM_WITH_ENGINES_PROPERTIES_PLUGINS_AND_JOB_EXECUTOR_WITH_EXPRESSIONS);
    KernelServices services = createKernelServicesBuilder(null)
        .setSubsystemXml(subsystemXml)
        .build();
    ServiceContainer container = services.getContainer();

    assertNotNull("platform service should be installed", container.getRequiredService(PLATFORM_SERVICE_NAME));
    assertNotNull("process engine service should be bound in JNDI", container.getRequiredService(processEngineServiceBindingServiceName));

    ServiceController<?> defaultEngineService = container.getService(ServiceNames.forManagedProcessEngine("__test"));

    assertNotNull("process engine controller for engine __test is installed ", defaultEngineService);

    ManagedProcessEngineMetadata metadata = ((MscManagedProcessEngineController) defaultEngineService.getService()).getProcessEngineMetadata();
    Map<String, String> configurationProperties = metadata.getConfigurationProperties();
    assertEquals("default", configurationProperties.get("job-acquisition-name"));

    Map<String, String> foxLegacyProperties = metadata.getFoxLegacyProperties();
    assertTrue(foxLegacyProperties.isEmpty());

    assertNotNull("process engine controller for engine __test is installed ", container.getRequiredService(ServiceNames.forManagedProcessEngine("__test")));

    // check we have parsed the plugin configurations
    List<ProcessEnginePluginXml> pluginConfigurations = metadata.getPluginConfigurations();
    
    assertEquals(1, pluginConfigurations.size());

    ProcessEnginePluginXml processEnginePluginXml = pluginConfigurations.get(0);
    assertEquals("org.camunda.bpm.identity.impl.ldap.plugin.LdapIdentityProviderPlugin", processEnginePluginXml.getPluginClass());
    Map<String, String> processEnginePluginXmlProperties = processEnginePluginXml.getProperties();
    assertEquals("abc", processEnginePluginXmlProperties.get("test"));
    assertEquals("123", processEnginePluginXmlProperties.get("number"));
    assertEquals("true", processEnginePluginXmlProperties.get("bool"));
    
    String persistedSubsystemXml = services.getPersistedSubsystemXml();
    compareXml(null, subsystemXml, persistedSubsystemXml);
    
  } finally {
    for (String key : EXPRESSION_PROPERTIES.keySet()) {
      System.clearProperty(key);
    }
  }
}
 
Example 8
Source File: JBossSubsystemXMLTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testInstallSubsystemWithJobExecutorAndPropertiesXml() throws Exception {
  String subsystemXml = FileUtils.readFile(SUBSYSTEM_WITH_JOB_EXECUTOR_AND_PROPERTIES);

  KernelServices services = createKernelServicesBuilder(null)
      .setSubsystemXml(subsystemXml)
      .build();
  ServiceContainer container = services.getContainer();

  commonSubsystemServicesAreInstalled(container);

  // "default" job acquisition ///////////////////////////////////////////////////////////
  ServiceController<?> defaultJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("default"));
  assertNotNull("platform job acquisition service 'default' should be installed", defaultJobAcquisitionService);

  Object value = defaultJobAcquisitionService.getValue();
  assertNotNull(value);
  assertTrue(value instanceof JobExecutor);

  JobExecutor defaultJobExecutor = (JobExecutor) value;
  assertEquals(300000, defaultJobExecutor.getLockTimeInMillis());
  assertEquals(5000, defaultJobExecutor.getWaitTimeInMillis());
  assertEquals(3, defaultJobExecutor.getMaxJobsPerAcquisition());

  // ServiceName: 'org.camunda.bpm.platform.job-executor.job-executor-tp'
  ServiceController<?> managedQueueExecutorServiceController = container.getService(ServiceNames.forManagedThreadPool(SubsystemAttributeDefinitons.DEFAULT_JOB_EXECUTOR_THREADPOOL_NAME));
  assertNotNull(managedQueueExecutorServiceController);
  Object managedQueueExecutorServiceObject = managedQueueExecutorServiceController.getValue();
  assertNotNull(managedQueueExecutorServiceObject);
  assertTrue(managedQueueExecutorServiceObject instanceof ManagedQueueExecutorService);
  ManagedQueueExecutorService managedQueueExecutorService = (ManagedQueueExecutorService) managedQueueExecutorServiceObject;
  assertEquals("Number of core threads is wrong", SubsystemAttributeDefinitons.DEFAULT_CORE_THREADS, managedQueueExecutorService.getCoreThreads());
  assertEquals("Number of max threads is wrong", SubsystemAttributeDefinitons.DEFAULT_MAX_THREADS, managedQueueExecutorService.getMaxThreads());
  assertEquals(SubsystemAttributeDefinitons.DEFAULT_KEEPALIVE_TIME, TimeUnit.NANOSECONDS.toSeconds(managedQueueExecutorService.getKeepAlive()));
  assertEquals(false, managedQueueExecutorService.isBlocking());
  assertEquals(SubsystemAttributeDefinitons.DEFAULT_ALLOW_CORE_TIMEOUT, managedQueueExecutorService.isAllowCoreTimeout());

  ServiceController<?> threadFactoryService = container.getService(ServiceNames.forThreadFactoryService(SubsystemAttributeDefinitons.DEFAULT_JOB_EXECUTOR_THREADPOOL_NAME));
  assertNotNull(threadFactoryService);
  assertTrue(threadFactoryService.getValue() instanceof ThreadFactory);

  // "anders" job acquisition /////////////////////////////////////////////////////////
  ServiceController<?> andersJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("anders"));
  assertNotNull("platform job acquisition service 'anders' should be installed", andersJobAcquisitionService);

  value = andersJobAcquisitionService.getValue();
  assertNotNull(value);
  assertTrue(value instanceof JobExecutor);

  JobExecutor andersJobExecutor = (JobExecutor) value;
  assertEquals(600000, andersJobExecutor.getLockTimeInMillis());
  assertEquals(10000, andersJobExecutor.getWaitTimeInMillis());
  assertEquals(5, andersJobExecutor.getMaxJobsPerAcquisition());

  // "mixed" job acquisition /////////////////////////////////////////////////////////
  ServiceController<?> mixedJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("mixed"));
  assertNotNull("platform job acquisition service 'mixed' should be installed", mixedJobAcquisitionService);

  value = mixedJobAcquisitionService.getValue();
  assertNotNull(value);
  assertTrue(value instanceof JobExecutor);

  JobExecutor mixedJobExecutor = (JobExecutor) value;
  assertEquals(500000, mixedJobExecutor.getLockTimeInMillis());
  // default values
  assertEquals(5000, mixedJobExecutor.getWaitTimeInMillis());
  assertEquals(3, mixedJobExecutor.getMaxJobsPerAcquisition());

}
 
Example 9
Source File: JBossSubsystemXMLTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testInstallSubsystemXmlWithAllOptionsWithExpressions() throws Exception {
  System.getProperties().putAll(EXPRESSION_PROPERTIES);
  try {
    String subsystemXml = FileUtils.readFile(SUBSYSTEM_WITH_ALL_OPTIONS_WITH_EXPRESSIONS);
    KernelServices services = createKernelServicesBuilder(null)
        .setSubsystemXml(subsystemXml)
        .build();
    ServiceContainer container = services.getContainer();

    assertNotNull("platform service should be installed", container.getRequiredService(PLATFORM_SERVICE_NAME));
    assertNotNull("process engine service should be bound in JNDI", container.getRequiredService(PROCESS_ENGINE_SERVICE_BINDING_SERVICE_NAME));

    ServiceController<?> defaultEngineService = container.getService(ServiceNames.forManagedProcessEngine("__test"));

    assertNotNull("process engine controller for engine __test is installed ", defaultEngineService);

    ManagedProcessEngineMetadata metadata = ((MscManagedProcessEngineController) defaultEngineService.getService()).getProcessEngineMetadata();
    Map<String, String> configurationProperties = metadata.getConfigurationProperties();
    assertEquals("default", configurationProperties.get("job-acquisition-name"));

    Map<String, String> foxLegacyProperties = metadata.getFoxLegacyProperties();
    assertTrue(foxLegacyProperties.isEmpty());

    assertNotNull("process engine controller for engine __test is installed ", container.getRequiredService(ServiceNames.forManagedProcessEngine("__test")));

    // check we have parsed the plugin configurations
    List<ProcessEnginePluginXml> pluginConfigurations = metadata.getPluginConfigurations();
    
    assertEquals(1, pluginConfigurations.size());

    ProcessEnginePluginXml processEnginePluginXml = pluginConfigurations.get(0);
    assertEquals("org.camunda.bpm.identity.impl.ldap.plugin.LdapIdentityProviderPlugin", processEnginePluginXml.getPluginClass());
    Map<String, String> processEnginePluginXmlProperties = processEnginePluginXml.getProperties();
    assertEquals("abc", processEnginePluginXmlProperties.get("test"));
    assertEquals("123", processEnginePluginXmlProperties.get("number"));
    assertEquals("true", processEnginePluginXmlProperties.get("bool"));
  } finally {
    for (String key : EXPRESSION_PROPERTIES.keySet()) {
      System.clearProperty(key);
    }
  }
}