Search in sources :

Example 1 with OperationHostileThread

use of com.hazelcast.spi.impl.operationexecutor.OperationHostileThread 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;
}
Also used : OperationHostileThread(com.hazelcast.spi.impl.operationexecutor.OperationHostileThread) OperationRunner(com.hazelcast.spi.impl.operationexecutor.OperationRunner) OperationHostileThread(com.hazelcast.spi.impl.operationexecutor.OperationHostileThread)

Example 2 with OperationHostileThread

use of com.hazelcast.spi.impl.operationexecutor.OperationHostileThread in project hazelcast by hazelcast.

the class OperationExecutorImpl method isRunAllowed.

@Override
public boolean isRunAllowed(Operation op) {
    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;
    }
    int partitionId = op.getPartitionId();
    // TODO: do we want to allow non partition specific tasks to be run on a partitionSpecific operation thread?
    if (partitionId < 0) {
        return true;
    }
    // we are only allowed to execute partition aware actions on an OperationThread
    if (currentThread.getClass() != PartitionOperationThread.class) {
        return false;
    }
    PartitionOperationThread partitionThread = (PartitionOperationThread) currentThread;
    // to execute operations for this particular partitionId
    return toPartitionThreadIndex(partitionId) == partitionThread.threadId;
}
Also used : OperationHostileThread(com.hazelcast.spi.impl.operationexecutor.OperationHostileThread) OperationHostileThread(com.hazelcast.spi.impl.operationexecutor.OperationHostileThread)

Aggregations

OperationHostileThread (com.hazelcast.spi.impl.operationexecutor.OperationHostileThread)2 OperationRunner (com.hazelcast.spi.impl.operationexecutor.OperationRunner)1