Search in sources :

Example 1 with ManagedContext

use of com.hazelcast.core.ManagedContext in project hazelcast by hazelcast.

the class PortableSerializer method readAndInitialize.

Portable readAndInitialize(BufferObjectDataInput in, int factoryId, int classId) throws IOException {
    Portable p = read(in, factoryId, classId);
    final ManagedContext managedContext = context.getManagedContext();
    return managedContext != null ? (Portable) managedContext.initialize(p) : p;
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) ManagedContext(com.hazelcast.core.ManagedContext)

Example 2 with ManagedContext

use of com.hazelcast.core.ManagedContext in project hazelcast by hazelcast.

the class PartitionWideEntryOperation method innerBeforeRun.

@Override
public void innerBeforeRun() throws Exception {
    super.innerBeforeRun();
    SerializationService serializationService = getNodeEngine().getSerializationService();
    ManagedContext managedContext = serializationService.getManagedContext();
    managedContext.initialize(entryProcessor);
}
Also used : SerializationService(com.hazelcast.spi.serialization.SerializationService) ManagedContext(com.hazelcast.core.ManagedContext)

Example 3 with ManagedContext

use of com.hazelcast.core.ManagedContext in project hazelcast by hazelcast.

the class DurableSpecificSetupTest method managedContext_mustInitializeRunnable.

@Test
public void managedContext_mustInitializeRunnable() throws Exception {
    final AtomicBoolean initialized = new AtomicBoolean();
    Config config = new Config().addDurableExecutorConfig(new DurableExecutorConfig("test").setPoolSize(1)).setManagedContext(new ManagedContext() {

        @Override
        public Object initialize(Object obj) {
            if (obj instanceof RunnableWithManagedContext) {
                initialized.set(true);
            }
            return obj;
        }
    });
    DurableExecutorService executor = createHazelcastInstance(config).getDurableExecutorService("test");
    executor.submit(new RunnableWithManagedContext()).get();
    assertTrue("The task should have been initialized by the ManagedContext", initialized.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Config(com.hazelcast.config.Config) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) ManagedContext(com.hazelcast.core.ManagedContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with ManagedContext

use of com.hazelcast.core.ManagedContext in project hazelcast by hazelcast.

the class ExecutorServiceTest method testManagedContextAndLocal.

@Test
public void testManagedContextAndLocal() throws Exception {
    Config config = new Config();
    config.addExecutorConfig(new ExecutorConfig("test", 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);
    IExecutorService executor = instance.getExecutorService("test");
    RunnableWithManagedContext task = new RunnableWithManagedContext();
    executor.submit(task).get();
    assertTrue("The task should have been initialized by the ManagedContext", initialized.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorConfig(com.hazelcast.config.ExecutorConfig) Config(com.hazelcast.config.Config) ManagedContext(com.hazelcast.core.ManagedContext) IExecutorService(com.hazelcast.core.IExecutorService) ExecutorConfig(com.hazelcast.config.ExecutorConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with ManagedContext

use of com.hazelcast.core.ManagedContext in project hazelcast by hazelcast.

the class EntryOperation method innerBeforeRun.

@Override
public void innerBeforeRun() throws Exception {
    super.innerBeforeRun();
    final SerializationService serializationService = getNodeEngine().getSerializationService();
    final ManagedContext managedContext = serializationService.getManagedContext();
    managedContext.initialize(entryProcessor);
}
Also used : InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) ManagedContext(com.hazelcast.core.ManagedContext)

Aggregations

ManagedContext (com.hazelcast.core.ManagedContext)9 Config (com.hazelcast.config.Config)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Test (org.junit.Test)4 SerializationService (com.hazelcast.spi.serialization.SerializationService)3 DurableExecutorConfig (com.hazelcast.config.DurableExecutorConfig)2 ExecutorConfig (com.hazelcast.config.ExecutorConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 IExecutorService (com.hazelcast.core.IExecutorService)2 RunnableAdapter (com.hazelcast.executor.impl.RunnableAdapter)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 Portable (com.hazelcast.nio.serialization.Portable)1