public abstract class Operation extends Object implements DataSerializable
Modifier and Type | Field and Description |
---|---|
static int |
GENERIC_PARTITION_ID
Marks an
Operation as non-partition-specific. |
Modifier | Constructor and Description |
---|---|
protected |
Operation() |
Modifier and Type | Method and Description |
---|---|
void |
afterRun()
Is executed called after
run() or call() method completes normally and the operation is not
blocked, see CallStatus.WAIT . |
void |
beforeRun()
|
CallStatus |
call()
Call the operation and returns the CallStatus.
|
boolean |
executedLocally()
Returns
true if local member is the caller. |
Address |
getCallerAddress() |
String |
getCallerUuid() |
long |
getCallId()
Gets the call ID of this operation.
|
long |
getCallTimeout()
Gets the call timeout in milliseconds.
|
Connection |
getConnection() |
long |
getInvocationTime()
Gets the time in milliseconds when this invocation started.
|
protected ILogger |
getLogger() |
NodeEngine |
getNodeEngine() |
OperationResponseHandler |
getOperationResponseHandler()
Gets the
OperationResponseHandler tied to this Operation. |
int |
getPartitionId()
Returns the ID of the partition that this Operation will be executed on.
|
int |
getReplicaIndex() |
Object |
getResponse()
|
<T> T |
getService() |
String |
getServiceName() |
long |
getWaitTimeout()
Returns the wait timeout in millis.
|
boolean |
isUrgent() |
void |
logError(Throwable e)
Logs Exception/Error thrown during operation execution.
|
void |
onExecutionFailure(Throwable e)
Called when an Exception/Error is thrown during
operation execution.
|
ExceptionAction |
onInvocationException(Throwable throwable)
Called when an Exception/Error is thrown
during an invocation.
|
protected void |
onSetCallId(long callId)
Called every time a new callId is set on the operation.
|
void |
readData(ObjectDataInput in)
Reads fields from the input stream
|
protected void |
readInternal(ObjectDataInput in) |
protected boolean |
requiresExplicitServiceName()
Returns
true to force the explicit service name serialization
for this operation, false otherwise. |
boolean |
returnsResponse()
Method is intended to be overridden.
|
void |
run()
Runs the operation.
|
void |
sendResponse(Object value) |
Operation |
setCallerUuid(String callerUuid) |
Operation |
setNodeEngine(NodeEngine nodeEngine) |
Operation |
setOperationResponseHandler(OperationResponseHandler responseHandler)
Sets the
OperationResponseHandler . |
Operation |
setPartitionId(int partitionId)
Sets the partition ID.
|
Operation |
setReplicaIndex(int replicaIndex) |
Operation |
setService(Object service) |
Operation |
setServiceName(String serviceName) |
Operation |
setValidateTarget(boolean validateTarget) |
void |
setWaitTimeout(long timeout)
Sets the wait timeout in millis.
|
String |
toString() |
protected void |
toString(StringBuilder sb)
A template method allows for additional information to be passed into
the
toString() method. |
boolean |
validatesTarget() |
void |
writeData(ObjectDataOutput out)
Writes object fields to output stream
|
protected void |
writeInternal(ObjectDataOutput out) |
public static final int GENERIC_PARTITION_ID
Operation
as non-partition-specific.public boolean executedLocally()
true
if local member is the caller.
Note: On the caller member this method always returns true
. It's meant to be used on target member to determine if the
execution is local.
public boolean isUrgent()
public void beforeRun() throws Exception
run()
or the call()
method is called.
runs before wait-supportException
public void run() throws Exception
public CallStatus call() throws Exception
run()
methods will be replaced by call
methods.
The call method looks very much like the run()
method and it is
very close to Runnable.run()
and Callable.call()
.
The main difference between a run and call, is that the returned
CallStatus from the call can tell something about the actual execution.
For example it could tell that some waiting is required in case of a
BlockingOperation
. Or that the actual execution work is
offloaded to some executor in case of an
Offloadable
EntryOperation
.
In the future new types of CallStatus are expected to be added, e.g. for
interleaving.
In the future it is very likely that for regular Operation that want to
return a concrete response, the actual response can be returned directly.
In this case we'll change the return type to Object
to prevent
forcing the response to be wrapped in a CallStatus.DONE_RESPONSE
monad since that would force additional litter to be created.public void afterRun() throws Exception
run()
or call()
method completes normally and the operation is not
blocked, see CallStatus.WAIT
.
Runs after backups, before wait-notify.Exception
public boolean returnsResponse()
true
,
getResponse()
will be called right after run()
method.
If it returns false
, sendResponse(Object)
must be
called later to finish the operation.
In other words, true
is for synchronous operation and
false
is for asynchronous one.
Default implementation is synchronous operation (true
).
public Object getResponse()
public String getServiceName()
public final int getPartitionId()
setPartitionId(int)
public final Operation setPartitionId(int partitionId)
partitionId
- the ID of the partition.getPartitionId()
public final int getReplicaIndex()
public final Operation setReplicaIndex(int replicaIndex)
public final long getCallId()
deactivate()
d,
and the call ID is negated.protected void onSetCallId(long callId)
By default this is a no-op method. Operation implementations which want to get notified on callId changes can override it.
For example an operation can distinguish the first invocation and invocation retries by keeping the initial callId.
callId
- the new call ID that was set on the operationpublic boolean validatesTarget()
public final Operation setValidateTarget(boolean validateTarget)
public final NodeEngine getNodeEngine()
public final Operation setNodeEngine(NodeEngine nodeEngine)
public final <T> T getService()
public final Address getCallerAddress()
public final Connection getConnection()
public final OperationResponseHandler getOperationResponseHandler()
OperationResponseHandler
tied to this Operation. The
returned value can be null.OperationResponseHandler
public final Operation setOperationResponseHandler(OperationResponseHandler responseHandler)
OperationResponseHandler
. Value is allowed to be null.responseHandler
- the OperationResponseHandler
to set.public final void sendResponse(Object value)
public final long getInvocationTime()
ClusterClock.getClusterTime()
.public final long getCallTimeout()
GroupProperty.OPERATION_CALL_TIMEOUT_MILLIS
setCallTimeout(long)
,
OperationAccessor.setCallTimeout(Operation, long)
public final long getWaitTimeout()
BlockingOperation
is
allowed to be parked in the
OperationParker
.
Examples:
public final void setWaitTimeout(long timeout)
timeout
- the wait timeout.for more detail.
public ExceptionAction onInvocationException(Throwable throwable)
throwable
- Exception/Error thrown during
invocationpublic String getCallerUuid()
protected final ILogger getLogger()
public void onExecutionFailure(Throwable e)
e
- Exception/Error thrown during operation executionpublic void logError(Throwable e)
e
- Exception/Error thrown during operation executionpublic final void writeData(ObjectDataOutput out) throws IOException
DataSerializable
writeData
in interface DataSerializable
out
- outputIOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
output stream has been closed.public final void readData(ObjectDataInput in) throws IOException
DataSerializable
readData
in interface DataSerializable
in
- inputIOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
input stream has been closed.protected boolean requiresExplicitServiceName()
true
to force the explicit service name serialization
for this operation, false
otherwise.
Usually, the method should be overridden if getServiceName()
is
also overridden, but it was not overridden in the previous HZ version,
i.e. the service name was provided using an explicit external call to
setServiceName(java.lang.String)
. This mechanism is required to maintain the
backward compatibility of the serialized representation of the operation
since the service name is not serialized if it matches the one returned
by getServiceName()
.
protected void writeInternal(ObjectDataOutput out) throws IOException
IOException
protected void readInternal(ObjectDataInput in) throws IOException
IOException
protected void toString(StringBuilder sb)
toString()
method. So an Operation subclass can override
this method and add additional debugging content. The default
implementation does nothing so one is not forced to provide an empty
implementation.
It is a good practice to always call the super.toString(stringBuffer)
when implementing this method to make sure that the super class can
inject content if needed.sb
- the StringBuilder to add the debug info to.Copyright © 2022 Hazelcast, Inc.. All Rights Reserved.