Class GridJobContextImpl
- java.lang.Object
-
- org.apache.ignite.internal.GridJobContextImpl
-
- All Implemented Interfaces:
Externalizable
,Serializable
,ComputeJobContext
,ComputeJobContinuation
public class GridJobContextImpl extends Object implements ComputeJobContext, Externalizable
Remote job context implementation.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description GridJobContextImpl()
Empty constructor required byExternalizable
.GridJobContextImpl(@Nullable GridKernalContext ctx, IgniteUuid jobId)
GridJobContextImpl(GridKernalContext ctx, IgniteUuid jobId, Map<? extends Serializable,? extends Serializable> attrs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
callcc()
Resumes job if it was held byComputeJobContinuation.holdcc()
method.<K,V>
VgetAttribute(K key)
Gets attribute from this job context.Map<Object,Object>
getAttributes()
Gets all attributes present in this job context.IgniteUuid
getJobId()
Gets ID of the job this context belongs to.boolean
heldcc()
Checks if job execution has been temporarily held (suspended).<T> T
holdcc()
Holds (suspends) a given job indefinitely untilComputeJobContinuation.callcc()
is called.<T> T
holdcc(long timeout)
Holds (suspends) a given job for specified timeout or untilComputeJobContinuation.callcc()
is called.void
job(GridJobWorker job)
void
readExternal(ObjectInput in)
void
setAttribute(Object key, @Nullable Object val)
Sets an attribute into this job context.void
setAttributes(Map<?,?> attrs)
Sets map of attributes into this job context.String
toString()
void
writeExternal(ObjectOutput out)
-
-
-
Constructor Detail
-
GridJobContextImpl
public GridJobContextImpl()
Empty constructor required byExternalizable
.
-
GridJobContextImpl
public GridJobContextImpl(@Nullable @Nullable GridKernalContext ctx, IgniteUuid jobId)
- Parameters:
ctx
- Kernal context.jobId
- Job ID.
-
GridJobContextImpl
public GridJobContextImpl(GridKernalContext ctx, IgniteUuid jobId, Map<? extends Serializable,? extends Serializable> attrs)
- Parameters:
ctx
- Kernal context.jobId
- Job ID.attrs
- Job attributes.
-
-
Method Detail
-
job
public void job(GridJobWorker job)
- Parameters:
job
- Job worker.
-
getJobId
public IgniteUuid getJobId()
Gets ID of the job this context belongs to.- Specified by:
getJobId
in interfaceComputeJobContext
- Returns:
- ID of the job this context belongs to.
-
setAttribute
public void setAttribute(Object key, @Nullable @Nullable Object val)
Sets an attribute into this job context.- Specified by:
setAttribute
in interfaceComputeJobContext
- Parameters:
key
- Attribute key.val
- Attribute value.
-
setAttributes
public void setAttributes(Map<?,?> attrs)
Sets map of attributes into this job context.- Specified by:
setAttributes
in interfaceComputeJobContext
- Parameters:
attrs
- Local attributes.
-
getAttribute
public <K,V> V getAttribute(K key)
Gets attribute from this job context.- Specified by:
getAttribute
in interfaceComputeJobContext
- Type Parameters:
K
- Type of the attribute key.V
- Type of the attribute value.- Parameters:
key
- Attribute key.- Returns:
- Attribute value (possibly
null
).
-
getAttributes
public Map<Object,Object> getAttributes()
Gets all attributes present in this job context.- Specified by:
getAttributes
in interfaceComputeJobContext
- Returns:
- All attributes.
-
heldcc
public boolean heldcc()
Checks if job execution has been temporarily held (suspended).If job has completed its execution, then
false
is always returned.- Specified by:
heldcc
in interfaceComputeJobContinuation
- Returns:
True
if job has been held.
-
holdcc
public <T> T holdcc()
Holds (suspends) a given job indefinitely untilComputeJobContinuation.callcc()
is called. Job will remain in active queue, but itsComputeJobContinuation.heldcc()
method will returntrue
. Implementations ofCollisionSpi
should check if jobs are held or not as needed.All jobs should stop their execution and return right after calling
'holdcc(..)'
method. For convenience, this method always returnsnull
, so you can hold and return in one line by calling'return holdcc()'
method.If job is not running or has completed its execution, then no-op.
The
'cc'
suffix stands for'current-continuation'
which is a pretty standard notation for this concept that originated from Scheme programming language. Basically, the job is held to be continued later, hence the name of the method.- Specified by:
holdcc
in interfaceComputeJobContinuation
- Type Parameters:
T
- Type of the job execution result.- Returns:
- Always returns
null
for convenience to be used in code with return statement.
-
holdcc
public <T> T holdcc(long timeout)
Holds (suspends) a given job for specified timeout or untilComputeJobContinuation.callcc()
is called. Holds (suspends) a given job for specified timeout or untilComputeJobContinuation.callcc()
is called. Job will remain in active queue, but itsComputeJobContinuation.heldcc()
method will returntrue
. Implementations ofCollisionSpi
should check if jobs are held or not as needed.All jobs should stop their execution and return right after calling
'holdcc(..)'
method. For convenience, this method always returnsnull
, so you can hold and return in one line by calling'return holdcc()'
.If job is not running or has completed its execution, then no-op.
The
'cc'
suffix stands for'current-continuation'
which is a fairly standard notation for this concept. Basically, the job is held to be continued later, hence the name of the method.- Specified by:
holdcc
in interfaceComputeJobContinuation
- Type Parameters:
T
- Type of the job execution result.- Parameters:
timeout
- Timeout in milliseconds after which job will be automatically resumed.- Returns:
- Always returns
null
for convenience to be used in code with return statement.
-
callcc
public void callcc()
Resumes job if it was held byComputeJobContinuation.holdcc()
method. Resuming job means thatComputeJob.execute()
method will be called again. It is user's responsibility to check, as needed, whether job is executing from scratch and has been resumed.Note that the job is resumed with exactly the same state as of when it was 'held' via the
ComputeJobContinuation.holdcc()
method.If job is not running, has not been suspended, or has completed its execution, then no-op.
The method is named after
'call-with-current-continuation'
design pattern, commonly abbreviated as'call/cc'
, which originated in Scheme programming language.- Specified by:
callcc
in interfaceComputeJobContinuation
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
-