|
Synapta Services Builder for IMS Version 3.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Contains method definitions to be implemented by all Task Beans.
Task Beans are standard Java beans that represent a particular task to be
performed. A task may require zero or more inputs that are represented as
"Read-Write" properties on the Task Bean and may provide zero or more outputs
that are represented as Read-Only properties. The properties are provided by
the specific bean implementation and are not part of the ITask interface. The
task may be executed either synchronously or asynchronously via the ITask
interface and provides status events via the ITaskListener
interface.
The typical way to use a Task Bean is:-
Different products provide their own implementations of Task Beans which represent client or server tasks such as screen navigation task, CICS transaction execution task etc. Task beans may be generated by a utility automatically based on predefined inputs or may be hand-coded as custom code.
Table data inputs or outputs of a task bean are represented by indexed properties.
A task bean may use back-end resources to execute the task such as a TCP/IP
session or a terminal session. Such a resource is represented in an abstract
form known as the "Context". Server implementations are typically optimized
to use "just-in-time" management of back-end resources. This causes the
resource to be allocated just before task execution and freed up immediately
after task completion. However, there are situations when it is necessary to
continue execution from one task bean to another using the same back-end
resource. The ITask interface provides the client the ability to preserve
the back-end resource context after the execution of the task using the
setPreserveContext
and
transferContext
methods.
Some task beans may also allow sharing the resource context by using
copyContext
.
The Context creation, back-end resource association/selection and destruction is handled by the task bean. A client program may only choose to transfer or copy the context to another task bean when the context is valid. The context validity depends on the status of the task and the various preserve modes as given in the following table.
Preserve Context Mode | TASK_CREATED | TASK_STARTED | TASK_SUCCESSFUL | TASK_CANCELED | TASK_FAILED | TASK_TIMEOUT |
---|---|---|---|---|---|---|
PRESERVE_ALWAYS | No | Yes | Yes | Yes | Yes | Yes |
PRESERVE_ON_ERROR | No | Yes | No | No | Yes | Yes |
PRESERVE_NEVER | No | Yes | No | No | No | No |
Implementation Notes:
begin
,
commit
and rollback
) will need to also implement
IConnectorLocalTransaction
.
Field Summary | |
static int |
PRESERVE_ALWAYS
Always preserve context after task execution |
static int |
PRESERVE_NEVER
Do not preserve context after task execution (default) |
static int |
PRESERVE_ON_ERROR
Preserve context on task execution errors only |
Method Summary | |
void |
addTaskListener(ITaskListener listener)
Adds a new task listener to this bean. |
void |
cancel()
Cancels the currently executing task and fires a task status change event with a TASK_CANCELED completion status. |
void |
clearContext()
Removes a context from a bean. |
void |
copyContext(ITask source)
Copies a context from one bean to another. |
void |
executeAsync()
Asynchronously executes the task using the current property settings. |
void |
executeSync()
Synchronously executes the task using the current property settings. |
java.lang.String |
getInstanceName()
Retrieves a user-defined instance name, such as an identifier for the bean on a web page or other bean container. |
java.lang.String |
getJobName()
Retrieves user-defined job name, such as a JSP web path. |
java.util.Locale |
getLocale()
Retrieves the locale property for the current instance of this bean. |
int |
getPreserveContext()
Retrieves the current preserve context mode. |
java.lang.String |
getResourceName()
Retrieves the name of the resource configuration in use by this bean |
TaskStatusChangeEvent |
getStatus()
Returns the current task execution status. |
long |
getTimeout()
Retrieves the current task timeout in milliseconds. |
java.lang.String |
getVersion()
Retrieves the version of the user's development environment or other user-specified version information, such as a date code. |
void |
removeTaskListener(ITaskListener listener)
Removes the specified task listener from this bean. |
void |
setInstanceName(java.lang.String name)
Sets a user-defined instance name, such as an identifier for the bean on a web page or other bean container. |
void |
setJobName(java.lang.String name)
Sets a user-defined job name, such as a JSP web path. |
void |
setLocale(java.util.Locale locale)
Sets the locale property for the current instance of this bean. |
void |
setPreserveContext(int mode)
Sets the preserve context mode. |
void |
setResourceName(java.lang.String name)
Sets the name of the resource to use with this bean. |
void |
setTimeout(long milliseconds)
Sets the task timeout in milliseconds. |
void |
transferContext(ITask source)
Transfers a context from one bean to another. |
Field Detail |
public static final int PRESERVE_NEVER
public static final int PRESERVE_ON_ERROR
public static final int PRESERVE_ALWAYS
Method Detail |
public void setPreserveContext(int mode) throws java.lang.IllegalArgumentException
execute
.
mode
- one of the preserve context mode constants.
PRESERVE_NEVER
-- Do not preserve context after task execution (default)PRESERVE_ON_ERROR
-- Preserve context on task execution errors onlyPRESERVE_ALWAYS
-- Always preserve context after task execution java.lang.IllegalArgumentException
- if mode
is out of rangegetPreserveContext( )
,
transferContext( ITask )
,
copyContext( ITask )
,
clearContext( )
public int getPreserveContext()
PRESERVE_NEVER
if not set.setPreserveContext( int )
,
transferContext( ITask )
,
copyContext( ITask )
,
clearContext( )
public void transferContext(ITask source) throws ResourceInUseException
bean1.execute( ); // context is auto-created bean2.transferContext( bean1 ); // transfer context from bean1 to bean2 bean2.execute( ); // execute bean2
A task bean may get its context from another bean or may generate its own
context. Typically, the context is automatically generated at when
executeSync
or executeAsync
is called.
Therefore this method may only be called following task execution.
source
- the bean to transfer the context from
ResourceInUseException
- if another task is using the contextcopyContext( ITask )
,
setPreserveContext( int )
,
clearContext( )
public void copyContext(ITask source) throws UnsupportedOperationException
A task bean may get its context from another bean or may generate its own
context. Typically, the context is automatically generated at when
executeSync
or executeAsync
is called.
Therefore this method may only be called following task execution.
source
- the bean to copy the context from
UnsupportedOperationException
- if the implementation does not support this method.transferContext( ITask )
,
setPreserveContext( int )
,
clearContext( )
public void clearContext() throws ResourceInUseException
The context is cleared automatically after execution by default unless the preserve mode indicates otherwise. This method has no effect if context has not been created.
Implementation Notes:
copyContext
, calling clearContext
on a given
task bean will end the use of the resources for that bean, but it should
have no effect on other beans still using the context. The context should
be completely reclaimed when clearContext
is called on the
last bean.
ResourceInUseException
- if the task is using the contexttransferContext( ITask )
,
copyContext( ITask )
,
setPreserveContext( int )
public void setTimeout(long milliseconds)
TASK_TIMEOUT
completion
status.
milliseconds
- the maximum time to wait for task execution to
complete. Default is Long.MAX_VALUE
.
If a task does not complete within the specified timeout starting from
the call to executeSync()
or executeAsync()
the
task bean will attempt to cancel the task execution. Due to a race
condition between the attempt to cancel and the completion of the task,
the cancel attempt may not necessarily succeed.
getTimeout( )
,
ITaskListener
,
TaskStatusChangeEvent
public TaskStatusChangeEvent getStatus()
event.status
-- one of the event status
constants defined in TaskStatusChangeEvent
event.exception
-- optional exception
information. May be null
.
TASK_CREATED
status if the task has never executed.public long getTimeout()
Long.MAX_VALUE
.
If a task does not complete within the specified timeout starting from
the call to executeSync()
or executeAsync()
the
task bean will attempt to cancel the task execution. Due to a race
condition between the attempt to cancel and the completion of the task,
the cancel attempt may not necessarily succeed.
setTimeout( long )
,
ITaskListener
,
TaskStatusChangeEvent
public void executeSync() throws ResourceInUseException
ResourceInUseException
- if task is already executingexecuteAsync( )
,
cancel( )
,
ITaskListener
,
TaskStatusChangeEvent
public void executeAsync() throws ResourceInUseException
executeSync
. This method returns
without waiting for the task to complete. Listeners will be notified of
task progress and completion status via the task status change events.
Uses the currently owned context, or creates one if none has been set.
ResourceInUseException
- if task is already executingexecuteSync( )
,
cancel( )
,
ITaskListener
,
TaskStatusChangeEvent
public void cancel()
TASK_CANCELED
completion status.
Due to a race condition between the attempt to cancel and the completion of the task, the cancel attempt may not necessarily succeed.
Implementation Notes:
cancel
must be able to
interrupt executeSync
.executeSync
blocks, cancel
must be
capable of being called from a separate thread.
executeSync( )
,
executeAsync( )
,
ITaskListener
,
TaskStatusChangeEvent
public void addTaskListener(ITaskListener listener)
listener
- the new listener to addpublic void removeTaskListener(ITaskListener listener)
listener
- the listener to removepublic java.lang.String getVersion()
public void setInstanceName(java.lang.String name)
A monitor or trace/log facility could display this string if lower level objects pass it through.
name
- optional instance namegetInstanceName( )
,
setResourceName( String )
,
setJobName( String )
public java.lang.String getInstanceName()
setInstanceName( String )
,
getResourceName( )
,
getJobName( )
public void setResourceName(java.lang.String name)
Implementation Notes:
name
- the name of the resource to usegetResourceName( )
,
setInstanceName( String )
,
setJobName( String )
public java.lang.String getResourceName()
setResourceName( String )
,
getInstanceName( )
,
getJobName( )
public void setJobName(java.lang.String name)
A monitor or tracing/log facility could display this string if lower level objects will pass it on through.
name
- user-defined job namegetJobName( )
,
setInstanceName( String )
,
setResourceName( String )
public java.lang.String getJobName()
setJobName( String )
,
getInstanceName( )
,
getResourceName( )
public void setLocale(java.util.Locale locale)
executeSync
and executeAsync
sample the locale on
method entry, and will use that value for that invocation.
locale
- the new locale settingpublic java.util.Locale getLocale()
|
Synapta Services Builder for IMS Version 3.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |