Beispiel #1
0
 /**
  * Returns the ExecutorConfig for the given name
  *
  * @param name name of the executor config
  * @return ExecutorConfig
  */
 public ExecutorConfig getExecutorConfig(String name) {
   String baseName = getBaseName(name);
   ExecutorConfig config = lookupByPattern(executorConfigs, baseName);
   if (config != null) {
     return config;
   }
   ExecutorConfig defConfig = executorConfigs.get("default");
   if (defConfig == null) {
     defConfig = new ExecutorConfig();
     defConfig.setName("default");
     addExecutorConfig(defConfig);
   }
   config = new ExecutorConfig(defConfig);
   config.setName(name);
   addExecutorConfig(config);
   return config;
 }
  @Test
  public void hazelcastInstanceAwareAndLocal() throws Exception {
    final Config config = new Config();
    config.addExecutorConfig(new ExecutorConfig("test", 1));
    final HazelcastInstance instance = createHazelcastInstance(config);
    IExecutorService executor = instance.getExecutorService("test");

    HazelcastInstanceAwareRunnable task = new HazelcastInstanceAwareRunnable();
    executor.submit(task).get();
    assertTrue("The setHazelcastInstance should have been called", task.initializeCalled);
  }
  @Test
  public void testManagedContextAndLocal() throws Exception {
    final Config config = new Config();
    config.addExecutorConfig(new ExecutorConfig("test", 1));
    config.setManagedContext(
        new ManagedContext() {
          @Override
          public Object initialize(Object obj) {
            if (obj instanceof RunnableWithManagedContext) {
              RunnableWithManagedContext task = (RunnableWithManagedContext) obj;
              task.initializeCalled = true;
            }
            return obj;
          }
        });

    final HazelcastInstance instance = createHazelcastInstance(config);
    IExecutorService executor = instance.getExecutorService("test");

    RunnableWithManagedContext task = new RunnableWithManagedContext();
    executor.submit(task).get();
    assertTrue(
        "The task should have been initialized by the ManagedContext", task.initializeCalled);
  }
 private IExecutorService createSingleNodeExecutorService(String name, int poolSize) {
   final Config config = new Config();
   config.addExecutorConfig(new ExecutorConfig(name, poolSize));
   final HazelcastInstance instance = createHazelcastInstance(config);
   return instance.getExecutorService(name);
 }