public final class OperationExecutorImpl extends Object implements OperationExecutor, MetricsProvider
OperationExecutor
that schedules:
execute(Object, int, boolean)
accepts an Object instead of a runnable to prevent needing to
create wrapper runnables around tasks. This is done to reduce the amount of object litter and therefor
reduce pressure on the GC.
There are 2 category of operation threads:
Modifier and Type | Field and Description |
---|---|
static HazelcastProperty |
IDLE_STRATEGY |
Constructor and Description |
---|
OperationExecutorImpl(HazelcastProperties properties,
LoggingService loggerService,
Address thisAddress,
OperationRunnerFactory runnerFactory,
NodeExtension nodeExtension,
String hzName,
ClassLoader configClassLoader) |
Modifier and Type | Method and Description |
---|---|
void |
accept(Packet packet)
Performs this operation on the given argument.
|
void |
execute(Operation op)
Executes the given
Operation at some point in the future. |
void |
execute(PartitionSpecificRunnable task)
Executes the given
PartitionSpecificRunnable at some point in the
future. |
void |
executeOnPartitions(PartitionTaskFactory taskFactory,
BitSet partitions)
Executes a task from the taskFactory for each of the given partitions.
|
void |
executeOnPartitionThreads(Runnable task)
Executes the task on every partition thread.
|
long |
getExecutedOperationCount()
Returns the number of executed operations.
|
OperationRunner[] |
getGenericOperationRunners()
Gets all the generic operation handlers.
|
int |
getGenericThreadCount()
Returns the number of generic threads.
|
OperationRunner[] |
getPartitionOperationRunners()
Gets all the operation handlers for the partitions.
|
int |
getPartitionThreadCount()
Returns the number of partition threads.
|
int |
getPartitionThreadId(int partitionId)
Returns the ID of the partitionThread assigned to handle partition
with given partitionId
|
int |
getPriorityQueueSize() |
int |
getQueueSize() |
int |
getRunningOperationCount() |
boolean |
isInvocationAllowed(Operation op,
boolean isAsync)
Checks if the
Operation is allowed to be invoked from the current
thread. |
boolean |
isRunAllowed(Operation op)
Checks if the
Operation is allowed to run on the current thread. |
void |
populate(LiveOperations liveOperations)
Populate the LiveOperations
|
void |
provideMetrics(MetricsRegistry registry) |
void |
run(Operation operation)
Runs the
Operation on the calling thread. |
void |
runOrExecute(Operation op)
Tries to run the
Operation on the calling thread if allowed. |
void |
shutdown()
Shuts down this OperationExecutor.
|
void |
start()
Starts this OperationExecutor.
|
int |
toPartitionThreadIndex(int partitionId) |
String |
toString() |
public static final HazelcastProperty IDLE_STRATEGY
public OperationExecutorImpl(HazelcastProperties properties, LoggingService loggerService, Address thisAddress, OperationRunnerFactory runnerFactory, NodeExtension nodeExtension, String hzName, ClassLoader configClassLoader)
public void provideMetrics(MetricsRegistry registry)
provideMetrics
in interface MetricsProvider
public OperationRunner[] getPartitionOperationRunners()
OperationExecutor
getPartitionOperationRunners
in interface OperationExecutor
public OperationRunner[] getGenericOperationRunners()
OperationExecutor
getGenericOperationRunners
in interface OperationExecutor
public void populate(LiveOperations liveOperations)
LiveOperationsTracker
populate
in interface LiveOperationsTracker
liveOperations
- the LiveOperations to populate.public int getRunningOperationCount()
getRunningOperationCount
in interface OperationExecutor
public int getQueueSize()
getQueueSize
in interface OperationExecutor
public int getPriorityQueueSize()
getPriorityQueueSize
in interface OperationExecutor
public long getExecutedOperationCount()
OperationExecutor
getExecutedOperationCount
in interface OperationExecutor
public int getPartitionThreadCount()
OperationExecutor
getPartitionThreadCount
in interface OperationExecutor
public int getGenericThreadCount()
OperationExecutor
getGenericThreadCount
in interface OperationExecutor
public int getPartitionThreadId(int partitionId)
OperationExecutor
getPartitionThreadId
in interface OperationExecutor
partitionId
- given partitionIdpublic void execute(Operation op)
OperationExecutor
Operation
at some point in the future.execute
in interface OperationExecutor
op
- the operation to execute.public void executeOnPartitions(PartitionTaskFactory taskFactory, BitSet partitions)
OperationExecutor
OperationExecutor.execute(Operation)
would be called in a loop.
The consequence of this bubble is that no other operations can interleave
and this can lead to very bad latency for the other operations.
This method can be used to create Operations and Runnable's to be executed
on a partition thread.
No check is done if the partition is actually local or not!executeOnPartitions
in interface OperationExecutor
taskFactory
- the PartitionTaskFactory
responsible for creating
tasks.partitions
- the partitions to execute tasks on. This BitSet should not
modified after this method is called. For each of the
partitions there is a bit indicating if a task should be
executed on the partition.public void execute(PartitionSpecificRunnable task)
OperationExecutor
PartitionSpecificRunnable
at some point in the
future.execute
in interface OperationExecutor
task
- the task the execute.public void accept(Packet packet)
Consumer
public void executeOnPartitionThreads(Runnable task)
OperationExecutor
executeOnPartitionThreads
in interface OperationExecutor
task
- the task the execute.public void run(Operation operation)
OperationExecutor
Operation
on the calling thread.run
in interface OperationExecutor
operation
- the Operation
to run.public void runOrExecute(Operation op)
OperationExecutor
Operation
on the calling thread if allowed.
Otherwise the operation is submitted for executing using
OperationExecutor.execute(Operation)
.runOrExecute
in interface OperationExecutor
op
- the Operation
to run or execute.public boolean isRunAllowed(Operation op)
OperationExecutor
Operation
is allowed to run on the current thread.isRunAllowed
in interface OperationExecutor
op
- the Operation
to checkpublic boolean isInvocationAllowed(Operation op, boolean isAsync)
OperationExecutor
Operation
is allowed to be invoked from the current
thread. Invoking means that the operation can be executed on another thread,
but that one is going to block for completion using the future.get/join etc.
Blocking for completion can cause problems, e.g. when you hog a partition
thread or deadlocks.isInvocationAllowed
in interface OperationExecutor
op
- the Operation
to checkisAsync
- is the invocation async, if false invocation does not return
a future to block onpublic int toPartitionThreadIndex(int partitionId)
public void start()
OperationExecutor
start
in interface OperationExecutor
public void shutdown()
OperationExecutor
shutdown
in interface OperationExecutor
Copyright © 2020 Hazelcast, Inc.. All Rights Reserved.