use of com.hazelcast.spi.impl.operationexecutor.OperationRunner in project hazelcast by hazelcast.
the class OperationExecutorImpl method isInvocationAllowed.
@Override
public boolean isInvocationAllowed(Operation op, boolean isAsync) {
checkNotNull(op, "op can't be null");
Thread currentThread = Thread.currentThread();
// IO threads are not allowed to run any operation
if (currentThread instanceof OperationHostileThread) {
return false;
}
// if it is async we don't need to check if it is PartitionOperationThread or not
if (isAsync) {
return true;
}
// allowed to invoke non partition specific task
if (op.getPartitionId() < 0) {
return true;
}
// allowed to invoke from non PartitionOperationThreads (including GenericOperationThread)
if (currentThread.getClass() != PartitionOperationThread.class) {
return true;
}
PartitionOperationThread partitionThread = (PartitionOperationThread) currentThread;
OperationRunner runner = partitionThread.currentRunner;
if (runner != null) {
// in this case partitionId of both inner and outer operations have to match
return runner.getPartitionId() == op.getPartitionId();
}
return toPartitionThreadIndex(op.getPartitionId()) == partitionThread.threadId;
}
use of com.hazelcast.spi.impl.operationexecutor.OperationRunner in project hazelcast by hazelcast.
the class OperationExecutorImpl method initPartitionThreads.
private PartitionOperationThread[] initPartitionThreads(HazelcastProperties properties, HazelcastThreadGroup threadGroup, NodeExtension nodeExtension) {
int threadCount = properties.getInteger(PARTITION_OPERATION_THREAD_COUNT);
if (threadCount <= 0) {
// default partition operation thread count
int coreSize = Runtime.getRuntime().availableProcessors();
threadCount = Math.max(2, coreSize);
}
PartitionOperationThread[] threads = new PartitionOperationThread[threadCount];
for (int threadId = 0; threadId < threads.length; threadId++) {
String threadName = threadGroup.getThreadPoolNamePrefix("partition-operation") + threadId;
// the normalQueue will be a blocking queue. We don't want to idle, because there are many operation threads.
MPSCQueue<Object> normalQueue = new MPSCQueue<Object>(null);
OperationQueue operationQueue = new DefaultOperationQueue(normalQueue, new ConcurrentLinkedQueue<Object>());
PartitionOperationThread partitionThread = new PartitionOperationThread(threadName, threadId, operationQueue, logger, threadGroup, nodeExtension, partitionOperationRunners);
threads[threadId] = partitionThread;
normalQueue.setConsumerThread(partitionThread);
}
// we need to assign the PartitionOperationThreads to all OperationRunners they own
for (int partitionId = 0; partitionId < partitionOperationRunners.length; partitionId++) {
int threadId = getPartitionThreadId(partitionId, threadCount);
Thread thread = threads[threadId];
OperationRunner runner = partitionOperationRunners[partitionId];
runner.setCurrentThread(thread);
}
return threads;
}
use of com.hazelcast.spi.impl.operationexecutor.OperationRunner in project hazelcast by hazelcast.
the class OperationExecutorImpl method run.
@Override
public void run(Operation operation) {
checkNotNull(operation, "operation can't be null");
if (!isRunAllowed(operation)) {
throw new IllegalThreadStateException("Operation '" + operation + "' cannot be run in current thread: " + Thread.currentThread());
}
OperationRunner operationRunner = getOperationRunner(operation);
operationRunner.run(operation);
}
use of com.hazelcast.spi.impl.operationexecutor.OperationRunner in project hazelcast by hazelcast.
the class InterceptorRegistryTest method getPartitionOperationThread.
private PartitionOperationThread getPartitionOperationThread(OperationQueue queue) {
HazelcastThreadGroup threadGroup = new HazelcastThreadGroup("instanceName", LOGGER, getClass().getClassLoader());
NodeExtension nodeExtension = mock(NodeExtension.class);
OperationRunner operationRunner = mock(OperationRunner.class);
OperationRunner[] operationRunners = new OperationRunner[] { operationRunner };
return new PartitionOperationThread("threadName", 0, queue, LOGGER, threadGroup, nodeExtension, operationRunners);
}
use of com.hazelcast.spi.impl.operationexecutor.OperationRunner in project hazelcast by hazelcast.
the class OperationExecutorImpl_GetOperationRunnerTest method test_whenCallerIsNormalThread_andGenericOperation_thenReturnAdHocRunner.
@Test
public void test_whenCallerIsNormalThread_andGenericOperation_thenReturnAdHocRunner() {
initExecutor();
Operation op = new DummyOperation(-1);
OperationRunner operationRunner = executor.getOperationRunner(op);
DummyOperationRunnerFactory f = (DummyOperationRunnerFactory) handlerFactory;
assertSame(f.adhocHandler, operationRunner);
}
Aggregations