private void execute(Object task, int partitionId, boolean priority) { if (partitionId < 0) { genericQueue.add(task, priority); } else { OperationThread partitionThread = partitionThreads[toPartitionThreadIndex(partitionId)]; partitionThread.queue.add(task, priority); } }
private void execute(Object task, int partitionId, boolean priority) { if (partitionId < 0) { genericQueue.add(task, priority); } else { OperationThread partitionThread = partitionThreads[toPartitionThreadIndex(partitionId)]; partitionThread.queue.add(task, priority); } }
@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; // so it's a partition operation thread, now we need to make sure that this operation thread is allowed // to execute operations for this particular partitionId return toPartitionThreadIndex(partitionId) == partitionThread.threadId; }
@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; // so it's a partition operation thread, now we need to make sure that this operation thread is allowed // to execute operations for this particular partitionId return toPartitionThreadIndex(partitionId) == partitionThread.threadId; }
@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) { // non null runner means it's a nested call // in this case partitionId of both inner and outer operations have to match return runner.getPartitionId() == op.getPartitionId(); } return toPartitionThreadIndex(op.getPartitionId()) == partitionThread.threadId; }
@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) { // non null runner means it's a nested call // in this case partitionId of both inner and outer operations have to match return runner.getPartitionId() == op.getPartitionId(); } return toPartitionThreadIndex(op.getPartitionId()) == partitionThread.threadId; }