Search in sources :

Example 6 with PartitionSpecificRunnable

use of com.hazelcast.spi.impl.PartitionSpecificRunnable in project hazelcast by hazelcast.

the class OperationExecutorImpl_ExecutePartitionSpecificRunnableTest method whenGeneric.

@Test
public void whenGeneric() {
    initExecutor();
    final AtomicReference<Thread> executingThead = new AtomicReference<Thread>();
    PartitionSpecificRunnable task = new PartitionSpecificRunnable() {

        @Override
        public void run() {
            executingThead.set(Thread.currentThread());
        }

        @Override
        public int getPartitionId() {
            return -1;
        }
    };
    executor.execute(task);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertInstanceOf(GenericOperationThread.class, executingThead.get());
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) AtomicReference(java.util.concurrent.atomic.AtomicReference) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with PartitionSpecificRunnable

use of com.hazelcast.spi.impl.PartitionSpecificRunnable in project hazelcast by hazelcast.

the class OperationThread method process.

private void process(Object task) {
    try {
        if (task.getClass() == Packet.class) {
            Packet packet = (Packet) task;
            currentRunner = getOperationRunner(packet.getPartitionId());
            currentRunner.run(packet);
            completedPacketCount.inc();
        } else if (task instanceof Operation) {
            Operation operation = (Operation) task;
            currentRunner = getOperationRunner(operation.getPartitionId());
            currentRunner.run(operation);
            completedOperationCount.inc();
        } else if (task instanceof PartitionSpecificRunnable) {
            PartitionSpecificRunnable runnable = (PartitionSpecificRunnable) task;
            currentRunner = getOperationRunner(runnable.getPartitionId());
            currentRunner.run(runnable);
            completedPartitionSpecificRunnableCount.inc();
        } else if (task instanceof Runnable) {
            Runnable runnable = (Runnable) task;
            runnable.run();
            completedRunnableCount.inc();
        } else {
            throw new IllegalStateException("Unhandled task type for task:" + task);
        }
        completedTotalCount.inc();
    } catch (Throwable t) {
        errorCount.inc();
        inspectOutOfMemoryError(t);
        logger.severe("Failed to process packet: " + task + " on " + getName(), t);
    } finally {
        currentRunner = null;
    }
}
Also used : Packet(com.hazelcast.nio.Packet) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) Operation(com.hazelcast.spi.Operation) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable)

Aggregations

PartitionSpecificRunnable (com.hazelcast.spi.impl.PartitionSpecificRunnable)7 AssertTask (com.hazelcast.test.AssertTask)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 Operation (com.hazelcast.spi.Operation)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Packet (com.hazelcast.nio.Packet)2 Data (com.hazelcast.nio.serialization.Data)1 OperationRunner (com.hazelcast.spi.impl.operationexecutor.OperationRunner)1 OperationRunnerFactory (com.hazelcast.spi.impl.operationexecutor.OperationRunnerFactory)1 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)1 MigrationEndpoint (com.hazelcast.spi.partition.MigrationEndpoint)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1