public abstract class XCommand<T> extends Object implements XCallable<T>
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_LOCK_TIMEOUT |
static String |
DEFAULT_REQUEUE_DELAY |
protected boolean |
dryrun |
protected static EventHandlerService |
eventService |
protected Instrumentation |
instrumentation |
static String |
INSTRUMENTATION_GROUP |
XLog |
LOG |
Constructor and Description |
---|
XCommand(String name,
String type,
int priority)
Create a command.
|
XCommand(String name,
String type,
int priority,
boolean dryrun) |
Modifier and Type | Method and Description |
---|---|
T |
call()
Implements the XCommand life-cycle.
|
T |
call(String callerEntityKey)
Call this command synchronously from its caller.
|
protected void |
eagerLoadState()
Load the necessary state to perform an eager precondition check.
|
protected void |
eagerVerifyPrecondition()
Verify the precondition for the command before obtaining a lock.
|
protected abstract T |
execute()
Command execution body.
|
protected void |
executeInterrupts()
Check for the existence of interrupts for the same lock key
Execute them if exist.
|
long |
getCreatedTime()
Returns the creation time of the command.
|
abstract String |
getEntityKey()
Return the entity key for the command.
|
protected Instrumentation |
getInstrumentation()
Return the
Instrumentation instance in use. |
String |
getKey()
Get command key
|
protected long |
getLockTimeOut()
Return the time out when acquiring a lock.
|
XLog |
getLog()
Get XLog log
|
String |
getName()
Return the command name.
|
int |
getPriority()
Return the priority of the command.
|
protected long |
getRequeueDelay()
Return the delay time for requeue
The value is loaded from the Oozie configuration, the property {link #DEFAULT_REQUEUE_DELAY}.
|
String |
getType()
Return the callable type.
|
boolean |
inInterruptMode() |
protected abstract boolean |
isLockRequired()
Indicate if the the command requires locking.
|
protected boolean |
isReQueueRequired()
Indicate if the the command requires to requeue itself if the lock is not acquired.
|
protected abstract void |
loadState()
Load the necessary state to perform the precondition check and to execute the command.
|
protected void |
queue(XCommand<?> command)
Queue a command for execution after the current command execution completes.
|
protected void |
queue(XCommand<?> command,
long msDelay)
Queue a command for delayed execution after the current command execution completes.
|
void |
resetUsed() |
void |
setInterruptMode(boolean mode)
set the mode of execution for the callable.
|
protected void |
setLogInfo()
Set the thread local logInfo with the context of this command and reset log prefix.
|
String |
toString()
String for the command - key
|
protected abstract void |
verifyPrecondition()
Verify the precondition for the command after a lock has been obtain, just before executing the command.
|
public static final String DEFAULT_LOCK_TIMEOUT
public static final String INSTRUMENTATION_GROUP
public static final String DEFAULT_REQUEUE_DELAY
protected boolean dryrun
protected Instrumentation instrumentation
protected static EventHandlerService eventService
public XCommand(String name, String type, int priority)
name
- command name.type
- command type.priority
- command priority.protected void setLogInfo()
public String getType()
CallableQueueService
.public int getPriority()
getPriority
in interface XCallable<T>
public long getCreatedTime()
getCreatedTime
in interface XCallable<T>
protected void queue(XCommand<?> command)
command
- command to queue.protected void queue(XCommand<?> command, long msDelay)
command
- command to queue.msDelay
- delay in milliseconds.public final T call() throws CommandException
call
in interface Callable<T>
Exception
- thrown if the command could not be executed.CommandException
public final T call(String callerEntityKey) throws CommandException
callerEntityKey
- CommandException
protected void executeInterrupts()
protected long getLockTimeOut()
protected abstract boolean isLockRequired()
true/false
public abstract String getEntityKey()
getEntityKey
in interface XCallable<T>
protected boolean isReQueueRequired()
true/false
protected void eagerLoadState() throws CommandException
CommandException
protected void eagerVerifyPrecondition() throws CommandException, PreconditionException
CommandException
- thrown if the precondition is not met.PreconditionException
protected abstract void loadState() throws CommandException
CommandException
protected abstract void verifyPrecondition() throws CommandException, PreconditionException
CommandException
- thrown if the precondition is not met.PreconditionException
protected abstract T execute() throws CommandException
CommandException
- thrown if the command execution failed.protected Instrumentation getInstrumentation()
Instrumentation
instance in use.Instrumentation
instance in use.public void resetUsed()
used
- set false to the usedprotected long getRequeueDelay()
public void setInterruptMode(boolean mode)
setInterruptMode
in interface XCallable<T>
public boolean inInterruptMode()
inInterruptMode
in interface XCallable<T>
Copyright © 2015 Apache Software Foundation. All Rights Reserved.