com.infoengine.SAK
Class BasicTasklet

java.lang.Object
  extended bycom.infoengine.object.factory.Task
      extended bycom.infoengine.SAK.BasicTasklet
All Implemented Interfaces:
Cloneable, Serializable, Tasklet

public abstract class BasicTasklet
extends Task
implements Cloneable, Tasklet

This abstract class defines the framework for dynamically compiled tasklets. The dynamic tasklet generator can define tasklets such that they extend this class and override its invoke() method.

See Also:
Serialized Form

Nested Class Summary
private  class BasicTasklet.TaskRunner
          Inner class for executing tasks in parallel.
private  class BasicTasklet.WebjectRunner
          Inner class for executing webjects in parallel.
 
Field Summary
protected  Hashtable attributes
           
private static String baseLogId
           
protected  CheckpointProcessor checkpointProcessor
           
private static String DELIMITERS
          Traverses a vector of String values and returns a delimiter character that does not occur in any of them.
protected  IeMultipartInputStream inputStream
           
private static String localHostAddress
           
protected  String logId
           
protected  StringBuffer outputBuffer
           
protected  OutputStream outputStream
           
private  String position
           
private  Stack positionStack
           
private static long sequenceNumber
           
protected  IeService service
           
protected  int taskType
           
protected  String uniqueIdentifier
           
 
Fields inherited from class com.infoengine.object.factory.Task
AUTH_MAP, CONTEXT, SOURCE, STATUS, TASKS, VDB, WEBJECTS
 
Constructor Summary
BasicTasklet()
          Constructs an initialized instance of the class.
 
Method Summary
 void addAttribute(String name, Object value)
          Adds a tasklet attribute value.
protected  void addError(Task task)
          Adds status and error messages from a subtask to this task.
 void addGroup(Group group)
          Adds a group to the task's VDB.
protected  void addOutputGroups(Task task)
          Adds the output groups produced by a tasklet to the VDB of this task.
 void addParam(String name, Object value)
          Adds a tasklet parameter value.
protected  void awaitThreads(Vector threads)
          Await completion of a set of threads in which webjects and/or tasks are running.
 void checkpoint(String position, boolean isResumable, Webject webject)
          Saves the current state of the tasklet if a checkpoint processor is defined.
protected  void executeSubtask(String uri)
          Executes a subtask.
 void finalize()
          Removes any state information that might have been saved for the tasklet.
 String generateLogId()
          Returns an identifier that can be used by this tasklet instance in writing log messages.
protected  void generateSOAPResponse(String returnType, String returnSubstition)
           
 Object getAttribute(String name)
          Returns the value of a tasklet attribute.
 Object getAttribute(String name, Object deflt)
          Returns the value of a tasklet attribute.
 Enumeration getAttributeNames()
          Returns the names of all tasklet attributes currently defined.
protected  Vector getAttributes(String name)
          Returns all of the values of an attribute.
 Group getGroup(String name)
          Returns a group from the task's VDB.
 Object getParam(String name)
          Returns the value of a tasklet parameter.
 Object getParam(String name, Object deflt)
          Returns the value of a tasklet parameter.
 Enumeration getParamNames()
          Returns the names of all tasklet parameters currently defined.
 Vector getParams(String name)
          Returns the values of a variable defined in the FORM context group.
protected  String getSafeDelimiter(Vector values)
           
 Object getServerParam(String name)
          Returns the value of a SERVER context group variable.
 Object getServerParam(String name, String deflt)
          Returns the value of a SERVER context group variable.
protected  Vector getServerParams(String name)
          Returns the values of a variable defined in the SERVER context group.
 IeService getService()
          Returns the server context associated with this tasklet.
 IeMultipartInputStream getTaskletInputStream()
          Returns the input stream from which the tasklet can read BLOB data.
 OutputStream getTaskletOutputStream()
          Returns the output stream associated with this tasklet.
 int getTaskType()
          Returns the task type currently associated with this tasklet.
 IeCollection getVdb()
          Returns the VDB collection associated with this tasklet.
abstract  int getVersion()
          Returns the version number of the task compiler that compiled the task most recently.
 void initialize()
          Initializes the tasklet.
protected  BasicTasklet.TaskRunner initiateTask(Task task)
          Initiates a task in a concurrent thread.
protected  BasicTasklet.WebjectRunner initiateWebject(Webject webject)
          Initiates a webject in a concurrent thread.
abstract  void invoke()
          Executes the tasklet.
 void invokeByProcessor(Vector processors)
          Executes the tasklet in a remote task processor.
 void mapCredentials()
          Creates the SERVER context group named AUTH_MAP by executing the Map-Credentials webject, passing a task URL and directory pathname as defined by the System properties com.infoengine.credentialsMapper and com.infoengine.credentialsFiles.
 int nextPosition()
          Returns the next position indicator from recovered position information.
protected  boolean processBranching(Webject webject, Task task)
          Processes task branching after a webject is executed.
 void pruneVdb(Webject webject)
          Replaces the current VDB with one that contains only groups specified in GROUP_OUT parameters of a specified webject.
 void pushPosition(int position)
          Pushes a position indicator onto the front of the position information such that it will be the next indicator returned by nextPosition().
 Webject recover()
          Recovers saved state information and initializes the internal position indicator.
 void registerException(Throwable exception)
          Registers the class name and message associated with an exception in the SERVER context group.
 void removeAttribute(String name)
          Removes a tasklet attribute.
 void removeGroup(String name)
          Removes a group from the task's VDB.
 void removeSavedState()
          Removes any state information that might have been saved for the tasklet.
 void setAttribute(String name, Object value)
          Sets the value of a tasklet attribute.
 void setCheckpointProcessor(String uniqueIdentifier, CheckpointProcessor checkpointProcessor)
          Sets the checkpoint processor associated with the tasklet.
 void setParam(String name, Object value)
          Sets the value of a tasklet parameter.
 void setService(IeService service)
          Sets the server context associated with this tasklet.
 void setTaskletInputStream(IeMultipartInputStream is)
          Sets the input stream from which the tasklet can read BLOB data.
 void setTaskletOutputStream(OutputStream os)
          Sets the output stream associated with this tasklet.
 void setTaskType(int taskType)
          Sets the task type context associated with this tasklet.
 void setVdb(IeCollection collection)
          Sets the VDB associated with this tasklet.
 String toString()
          Returns a string containing the output currently associated with this tasklet.
protected  Throwable unwrapThrowable(Throwable ex)
           
 void verifyResumable()
          Verifies that the tasklet can be resumed successfully after an interruption.
 void write(String s)
          Writes a string to the output stream associated with this tasklet.
 void write(String s, String encoding)
          Writes a string to the output stream associated with this tasklet.
 
Methods inherited from class com.infoengine.object.factory.Task
addContext, addError, addInput, addOutput, addOutput, addVdb, addVdb, bindParams, bindParams, checkWebjects, clearInput, deepClone, getAuthElement, getContext, getContext, getContextGroup, getDesc, getGroupIn, getGroupIn, getGroupOut, getGroupOut, getInput, getInput, getInputGroups, getInputs, getInputStream, getMessage, getMessages, getMimeInputStream, getName, getOutput, getOutput, getOutputGroups, getOutputStream, getPassword, getRequest, getSource, getStatus, getType, getUserName, getVariables, getVdb, getVdbIn, getVdbIn, getWebject, newStructure, printTree, removeInput, removeVdb, setContext, setDesc, setInput, setInputStream, setName, setOutputStream, setPassword, setSource, setType, setUserName, setWebject, subVariables
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.infoengine.SAK.Tasklet
getContext, setContext
 

Field Detail

attributes

protected Hashtable attributes

checkpointProcessor

protected CheckpointProcessor checkpointProcessor

inputStream

protected IeMultipartInputStream inputStream

logId

protected String logId

outputBuffer

protected StringBuffer outputBuffer

outputStream

protected OutputStream outputStream

service

protected IeService service

taskType

protected int taskType

uniqueIdentifier

protected String uniqueIdentifier

position

private String position

positionStack

private Stack positionStack

baseLogId

private static String baseLogId

localHostAddress

private static String localHostAddress

sequenceNumber

private static long sequenceNumber

DELIMITERS

private static final String DELIMITERS
Traverses a vector of String values and returns a delimiter character that does not occur in any of them.

See Also:
Constant Field Values
Constructor Detail

BasicTasklet

public BasicTasklet()
Constructs an initialized instance of the class.

Method Detail

getVersion

public abstract int getVersion()
Returns the version number of the task compiler that compiled the task most recently. If the version number of the current compiler does not match the number returned by this method, the compiler will recompile the task. This method must be overridden by subclasses.

Specified by:
getVersion in interface Tasklet
Returns:
The version number of the compiler that compiled the task most recently.

generateLogId

public String generateLogId()
Returns an identifier that can be used by this tasklet instance in writing log messages.

Returns:
The log identifier.

initialize

public void initialize()
                throws IEException
Initializes the tasklet.

Specified by:
initialize in interface Tasklet
Throws:
IEException - if the tasklet is not initialized successfully.

setTaskletInputStream

public void setTaskletInputStream(IeMultipartInputStream is)
Sets the input stream from which the tasklet can read BLOB data.

Specified by:
setTaskletInputStream in interface Tasklet
Parameters:
is - The Info*Engine multipart input stream from which the tasklet can read BLOB data.

getTaskletInputStream

public IeMultipartInputStream getTaskletInputStream()
Returns the input stream from which the tasklet can read BLOB data.

Specified by:
getTaskletInputStream in interface Tasklet
Returns:
The Info*Engine multipart input stream from which the tasklet can read BLOB data.

setTaskletOutputStream

public void setTaskletOutputStream(OutputStream os)
Sets the output stream associated with this tasklet.

Specified by:
setTaskletOutputStream in interface Tasklet
Parameters:
os - The new output stream.

getTaskletOutputStream

public OutputStream getTaskletOutputStream()
Returns the output stream associated with this tasklet.

Specified by:
getTaskletOutputStream in interface Tasklet
Returns:
The output stream associated with this tasklet.

write

public void write(String s)
           throws IOException
Writes a string to the output stream associated with this tasklet. The string is written using the default character encoding.

Specified by:
write in interface Tasklet
Parameters:
s - The string to write.
Throws:
IOException - if an I/O error occurs.

write

public void write(String s,
                  String encoding)
           throws IOException
Writes a string to the output stream associated with this tasklet. The string is written using a specified character encoding.

Specified by:
write in interface Tasklet
Parameters:
s - The string to write.
encoding - The character encoding to use.
Throws:
IOException - if an I/O error occurs.

toString

public String toString()
Returns a string containing the output currently associated with this tasklet. Usually, the output is generated as a result of calling the invoke method.

Specified by:
toString in interface Tasklet
Returns:
A String containing the output associated with the tasklet.

getTaskType

public int getTaskType()
Returns the task type currently associated with this tasklet.

Specified by:
getTaskType in interface Tasklet
Returns:
The current task type, usually one of Task.TYPE_NORMAL or Task.TYPE_CREDENTIALS_MAPPER

setTaskType

public void setTaskType(int taskType)
Sets the task type context associated with this tasklet.

Specified by:
setTaskType in interface Tasklet
Parameters:
taskType - The new task type, usually one of Task.TYPE_NORMAL or Task.TYPE_CREDENTIALS_MAPPER

getService

public IeService getService()
Returns the server context associated with this tasklet.

Specified by:
getService in interface Tasklet
Returns:
The server context

setService

public void setService(IeService service)
Sets the server context associated with this tasklet.

Specified by:
setService in interface Tasklet
Parameters:
service - The new server context.

getVdb

public IeCollection getVdb()
Returns the VDB collection associated with this tasklet.

Specified by:
getVdb in interface Tasklet
Overrides:
getVdb in class Task
Returns:
The collection of VDB groups

setVdb

public void setVdb(IeCollection collection)
Sets the VDB associated with this tasklet.

Specified by:
setVdb in interface Tasklet
Overrides:
setVdb in class Task
Parameters:
collection - The new collection of VDB groups.

setCheckpointProcessor

public void setCheckpointProcessor(String uniqueIdentifier,
                                   CheckpointProcessor checkpointProcessor)
Sets the checkpoint processor associated with the tasklet. The checkpoint processor is an object that is responsible for saving the state of the tasklet such that it can be restored to restart the tasklet after its execution is interrupted for some reason. Normally, this method is called by a task processor service that implements guaranteed task execution.

Specified by:
setCheckpointProcessor in interface Tasklet
Parameters:
uniqueIdentifier - The unique identifier assigned to the tasklet instance. This will be passed to the checkpoint processor object to aid it in associating saved state with a specific tasklet instance over time.
checkpointProcessor - The object that can be called to save a tasklet's state. If null, state information will not be saved for the tasklet.

checkpoint

public void checkpoint(String position,
                       boolean isResumable,
                       Webject webject)
                throws IEException
Saves the current state of the tasklet if a checkpoint processor is defined.

Parameters:
position - The current position of execution within the tasklet.
isResumable - true if execution can be resumed safely after interruption at this position, false if an exception should be thrown in case of task interruption at this position.
webject - A webject whose GROUP_OUT parameters define the current output groups of the tasklet.
Throws:
IEException - if tasklet state was not saved successfully

recover

public Webject recover()
Recovers saved state information and initializes the internal position indicator.

Returns:
A webject defining the recovered output group names of the tasklet. If no output group names were saved, null is returned.

removeSavedState

public void removeSavedState()
Removes any state information that might have been saved for the tasklet.

Throws:
IEException - if tasklet state was not removed successfully

nextPosition

public int nextPosition()
Returns the next position indicator from recovered position information.

Returns:
The next position indicator, or 0 if no recovered position information is available.

pushPosition

public void pushPosition(int position)
Pushes a position indicator onto the front of the position information such that it will be the next indicator returned by nextPosition().

Parameters:
position - The position indicator to push.

verifyResumable

public void verifyResumable()
                     throws IENotResumableException
Verifies that the tasklet can be resumed successfully after an interruption.

Throws:
IENotResumableException - if tasklet can not be resumed successfully.

setParam

public void setParam(String name,
                     Object value)
Sets the value of a tasklet parameter.

Specified by:
setParam in interface Tasklet
Parameters:
name - The name of the parameter to set.
value - The value to associate with the name.

addGroup

public void addGroup(Group group)
Adds a group to the task's VDB.

Specified by:
addGroup in interface Tasklet
Parameters:
group - the group to be added

removeGroup

public void removeGroup(String name)
Removes a group from the task's VDB.

Parameters:
name - the name of the group to be removed

getGroup

public Group getGroup(String name)
Returns a group from the task's VDB.

Specified by:
getGroup in interface Tasklet
Parameters:
name - the name of the group to be returned
Returns:
the group, or null if the group does not exist

addParam

public void addParam(String name,
                     Object value)
Adds a tasklet parameter value.

Specified by:
addParam in interface Tasklet
Parameters:
name - The name of the parameter to add.
value - The value to associate with the name.

getParam

public Object getParam(String name)
Returns the value of a tasklet parameter.

Specified by:
getParam in interface Tasklet
Parameters:
name - The name of the parameter to return.
Returns:
The value of the parameter, or null if the parameter is unknown. If the parameter is multivalued, the first value is returned.

getParam

public Object getParam(String name,
                       Object deflt)
Returns the value of a tasklet parameter. If the parameter is undefined, a specified default value is returned.

Specified by:
getParam in interface Tasklet
Parameters:
name - The name of the parameter to return.
deflt - The default value.
Returns:
The value of the parameter, or the default value. If the parameter is multivalued, the first value is returned.

getParams

public Vector getParams(String name)
Returns the values of a variable defined in the FORM context group.

Specified by:
getParams in interface Tasklet
Parameters:
name - The name of the form variable.
Returns:
The values of the specified form variable, or null if the form variable is unknown.

getParamNames

public Enumeration getParamNames()
Returns the names of all tasklet parameters currently defined.

Specified by:
getParamNames in interface Tasklet
Returns:
The names of all currently defined tasklet parameters.

getServerParam

public Object getServerParam(String name)
Returns the value of a SERVER context group variable.

Parameters:
name - The name of the variable to return.
Returns:
The value of the variable, or null if the variable is unknown.

getServerParam

public Object getServerParam(String name,
                             String deflt)
Returns the value of a SERVER context group variable. If the variable is undefined, a specified default value is returned.

Parameters:
name - The name of the variable to return.
deflt - The default value.
Returns:
The value of the variable, or the default value

getServerParams

protected Vector getServerParams(String name)
Returns the values of a variable defined in the SERVER context group.

Parameters:
name - The name of the server variable.
Returns:
The values of the specified server variable, or null if the server variable is unknown.

setAttribute

public void setAttribute(String name,
                         Object value)
Sets the value of a tasklet attribute.

Specified by:
setAttribute in interface Tasklet
Parameters:
name - The name of the attribute to set.
value - The value to associate with the name.

addAttribute

public void addAttribute(String name,
                         Object value)
Adds a tasklet attribute value.

Specified by:
addAttribute in interface Tasklet
Parameters:
name - The name of the attribute to add.
value - The value to associate with the name.

getAttribute

public Object getAttribute(String name)
Returns the value of a tasklet attribute.

Specified by:
getAttribute in interface Tasklet
Parameters:
name - The name of the attribute to return.
Returns:
The value of the attribute, or null if the parameter is unknown. If the attribute is multivalued, the first value is returned.

getAttribute

public Object getAttribute(String name,
                           Object deflt)
Returns the value of a tasklet attribute. If the attribute is undefined, a specified default value is returned.

Specified by:
getAttribute in interface Tasklet
Parameters:
name - The name of the attribute to return.
deflt - The default value.
Returns:
The value of the attribute, or the default value. If the attribute is multivalued, the first value is returned.

getAttributes

protected Vector getAttributes(String name)
Returns all of the values of an attribute.

Parameters:
name - The name of the attribute.
Returns:
The values of the specified attribute, or null if the attribute is unknown.

getAttributeNames

public Enumeration getAttributeNames()
Returns the names of all tasklet attributes currently defined.

Specified by:
getAttributeNames in interface Tasklet
Returns:
The names of all currently defined tasklet attributes.

removeAttribute

public void removeAttribute(String name)
Removes a tasklet attribute.

Specified by:
removeAttribute in interface Tasklet
Parameters:
name - The name of the attribute to remove.

invoke

public abstract void invoke()
                     throws IEException,
                            IOException
Executes the tasklet. This method must be overridden by subclasses.

Specified by:
invoke in interface Tasklet
Throws:
IEException - if an error other than an I/O error occurs during execution of the tasklet.
IOException - if an I/O error occurs.

invokeByProcessor

public void invokeByProcessor(Vector processors)
                       throws IEException,
                              IOException
Executes the tasklet in a remote task processor. The caller supplies a vector of task processor names. An attempt is made to connect to each task processor, one at a time, until a connection is made successfully. Then, a request object is sent and the result is incorporated into the local VDB.

Throws:
IEException - if an error other than an I/O error occurs during execution of the tasklet.
IOException - if an I/O error occurs.

mapCredentials

public void mapCredentials()
                    throws IEException
Creates the SERVER context group named AUTH_MAP by executing the Map-Credentials webject, passing a task URL and directory pathname as defined by the System properties com.infoengine.credentialsMapper and com.infoengine.credentialsFiles.

Throws:
IEException - if credentials can not be mapped

pruneVdb

public void pruneVdb(Webject webject)
              throws IEException
Replaces the current VDB with one that contains only groups specified in GROUP_OUT parameters of a specified webject.

Parameters:
webject - The webject whose GROUP_OUT parameters specify the groups to be kept in the task's VDB.
Throws:
IEException

registerException

public void registerException(Throwable exception)
Registers the class name and message associated with an exception in the SERVER context group.

Parameters:
exception - The exception to be registered

executeSubtask

protected void executeSubtask(String uri)
                       throws IEException,
                              IOException
Executes a subtask. This is usually called by generated code in order to process SUCCESS/FAILURE branching in webjects.

Parameters:
uri - The URI of the task to be executed.
Throws:
IEException - if an error other than an I/O error occurs.
IOException - if an I/O error occurs.

addError

protected void addError(Task task)
Adds status and error messages from a subtask to this task.

Parameters:
task - The subtask

processBranching

protected boolean processBranching(Webject webject,
                                   Task task)
Processes task branching after a webject is executed.

Parameters:
webject - The webject that was executed.
task - The task in which the webject is defined.
Returns:
true if a branch was taken or the branch action is "STOP"

initiateWebject

protected BasicTasklet.WebjectRunner initiateWebject(Webject webject)
Initiates a webject in a concurrent thread. This is usually called by generated code in order to process webjects within blocks.

Parameters:
webject - The webject to be executed.
Returns:
The webject runner in which the webject is executing.

initiateTask

protected BasicTasklet.TaskRunner initiateTask(Task task)
Initiates a task in a concurrent thread. This is usually called by generated code in order to process tasks within blocks.

Parameters:
task - The task to be executed.
Returns:
The task runner in which the task is executing.

awaitThreads

protected void awaitThreads(Vector threads)
Await completion of a set of threads in which webjects and/or tasks are running.

Parameters:
threads - The vector of webject threads for which to await completion.

addOutputGroups

protected void addOutputGroups(Task task)
Adds the output groups produced by a tasklet to the VDB of this task.


getSafeDelimiter

protected String getSafeDelimiter(Vector values)
                           throws IEException
Throws:
IEException

finalize

public void finalize()
              throws Throwable
Removes any state information that might have been saved for the tasklet.

Throws:
IEException - if tasklet state was not removed successfully
Throwable

unwrapThrowable

protected Throwable unwrapThrowable(Throwable ex)

generateSOAPResponse

protected void generateSOAPResponse(String returnType,
                                    String returnSubstition)
                             throws IEException
Throws:
IEException