use of com.hazelcast.core.ManagedContext in project hazelcast by hazelcast.
the class DurableExecutorServiceTest method testManagedContextAndLocal.
/* ############ submit runnable ############ */
@Test
public void testManagedContextAndLocal() throws Exception {
Config config = new Config();
config.addDurableExecutorConfig(new DurableExecutorConfig("test").setPoolSize(1));
final AtomicBoolean initialized = new AtomicBoolean();
config.setManagedContext(new ManagedContext() {
@Override
public Object initialize(Object obj) {
if (obj instanceof RunnableWithManagedContext) {
initialized.set(true);
}
return obj;
}
});
HazelcastInstance instance = createHazelcastInstance(config);
DurableExecutorService executor = instance.getDurableExecutorService("test");
RunnableWithManagedContext task = new RunnableWithManagedContext();
executor.submit(task).get();
assertTrue("The task should have been initialized by the ManagedContext", initialized.get());
}
use of com.hazelcast.core.ManagedContext in project hazelcast by hazelcast.
the class MultipleEntryOperation method innerBeforeRun.
@Override
public void innerBeforeRun() throws Exception {
super.innerBeforeRun();
final SerializationService serializationService = getNodeEngine().getSerializationService();
final ManagedContext managedContext = serializationService.getManagedContext();
managedContext.initialize(entryProcessor);
}
use of com.hazelcast.core.ManagedContext in project hazelcast by hazelcast.
the class AbstractCallableTaskOperation method beforeRun.
@Override
public final void beforeRun() throws Exception {
returnsResponse = false;
callable = getCallable();
ManagedContext managedContext = getManagedContext();
if (callable instanceof RunnableAdapter) {
RunnableAdapter adapter = (RunnableAdapter) callable;
Runnable runnable = (Runnable) managedContext.initialize(adapter.getRunnable());
adapter.setRunnable(runnable);
} else {
callable = (Callable) managedContext.initialize(callable);
}
}
use of com.hazelcast.core.ManagedContext in project hazelcast by hazelcast.
the class SpecificSetupTest method managedContext_mustInitializeRunnable.
@Test
public void managedContext_mustInitializeRunnable() throws Exception {
final AtomicBoolean initialized = new AtomicBoolean();
Config config = new Config().addExecutorConfig(new ExecutorConfig("test", 1)).setManagedContext(new ManagedContext() {
@Override
public Object initialize(Object obj) {
if (obj instanceof RunnableWithManagedContext) {
initialized.set(true);
}
return obj;
}
});
IExecutorService executor = createHazelcastInstance(config).getExecutorService("test");
executor.submit(new RunnableWithManagedContext()).get();
assertTrue("The task should have been initialized by the ManagedContext", initialized.get());
}
Aggregations