public abstract class Offload extends CallStatus
Offloadable
.
The Offload is a CallStatus
designed when an offloaded operation
needs to offload the processing of the operation to a different system, e.g
a different thread and at some point in the future a response will be ready.
Offload instance can be created by Operations that require offloading, for
more information see the Operation.call()
.
If the operation 'offloads' some work, but doesn't send a response ever,
CallStatus.DONE_VOID
should be used instead.
init(NodeEngineImpl, Set)
is called, the original
OperationResponseHandler
of the offloaded operation is decorated with
one of designed for the offloading (see heartbeats for more info). This means
that sending a response for an offloaded operation, can be done using the
regular response handling mechanism
(see Operation.sendResponse(Object)
or
Operation.getOperationResponseHandler()
. But one should not modify
the response handler of an offloaded Operation because otherwise one could
e.g. run into a memory leak (the offloaded operation will not be removed
from the asynchronous operations).
There is an important difference with exception handling. With regular
operation when an exception is thrown, first the
Operation.onExecutionFailure(Throwable)
is called before the
Operation.sendResponse(Object)
is called. But with an offloaded
operation, typically the Operation.sendResponse(Object)
is called by
the implementation of the offloading logic. So if you need the
Operation.onExecutionFailure(Throwable)
to be executed, just as the
sendResponse call, the onExecuteFailure call is your own concern.
init(NodeEngineImpl, Set)
is called. And it is unregistered,
as soon as a response is send to the offloaded operation. This is done by
decorating updating the original response handler of the operation by wrapping
it in a decorating response handler that automatically deregisters on completion.Modifier and Type | Field and Description |
---|---|
protected ExecutionService |
executionService |
protected NodeEngine |
nodeEngine |
protected InternalOperationService |
operationService |
protected SerializationService |
serializationService |
DONE_RESPONSE, DONE_RESPONSE_ORDINAL, DONE_VOID, DONE_VOID_ORDINAL, OFFLOAD_ORDINAL, WAIT, WAIT_ORDINAL
Constructor and Description |
---|
Offload(Operation offloadedOperation)
Creates a new Offload instance.
|
Modifier and Type | Method and Description |
---|---|
void |
init(NodeEngineImpl nodeEngine,
Set<Operation> asyncOperations)
Initializes the Offload.
|
Operation |
offloadedOperation()
Returns the Operation that created this Offload.
|
abstract void |
start()
Starts the actual offloading.
|
ordinal
protected InternalOperationService operationService
protected NodeEngine nodeEngine
protected ExecutionService executionService
protected SerializationService serializationService
public Offload(Operation offloadedOperation)
offloadedOperation
- the Operation that is offloadedpublic final Operation offloadedOperation()
public final void init(NodeEngineImpl nodeEngine, Set<Operation> asyncOperations)
OperationResponseHandler
of
the offloaded Operation
is replaced by a decorated version that
takes care of automatic deregistration of the operation on completion.
This method is called before the start()
is called by the
Operation infrastructure. An implementor of the Offload
doesn't
need to deal with this method.nodeEngine
- the NodeEngineImpl
public abstract void start() throws Exception
Operation.call()
where this Offload instance was returned. So in
most cases you want to schedule some work and then return from this method ASAP so
that the thread is released.
This method is called after the Operation.afterRun()
is called.
It is allowed to call Operation.sendResponse(Object)
in the start
method if there is nothing to offload.Exception
- if something fails. If this happens, regular Operation
exception handling is triggered and normally the
exception is returned to the caller.Copyright © 2022 Hazelcast, Inc.. All Rights Reserved.