Class ExecutionEnvironment
- java.lang.Object
-
- de.aristaflow.adept2.core.runtimemanager.executionenvironments.ExecutionEnvironment
-
- All Implemented Interfaces:
ExecutableComponent
- Direct Known Subclasses:
AbstractWebResourceComponent,IDExecutionEnvironment,NullExecution,SystemExecutionEnvironment
public abstract class ExecutionEnvironment extends Object implements ExecutableComponent
This abstract execution environment is for easy development of new execution environments. It provides default implementations for most of the methods ofExecutableComponent: state changes are refused or ignored exceptrun()which has to be provided by subclasses. Transaction handling is also refused.
Additionally this execution environment provides methods for retrieval of input parameter types and values as well as writing the values of output parameters. Parameters of user-defined data type are mapped toObjects.For a convenient access to the activity instance and the data context
actDatashould be used. Do not use it before callinginit(SessionContext)on this class. If a subclass needs methods fromActivityDatato be overridden, be careful to also overridecreateActivityData(ActivityInstance, DataContext, Logger).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface de.aristaflow.adept2.model.runtimeenvironment.ExecutableComponent
ExecutableComponent.Signals
-
-
Field Summary
Fields Modifier and Type Field Description protected ActivityDataactDataThe activity instance and data context wrapper for this execution.protected ActivityInstanceactivityInstanceThe activity (instance) which is encapsulated by this execution environment.protected Cleanup<RuntimeException>cleanupThe clean-up called after as post-mortem action of thisExecutionEnvironment.protected ActivityInstancelocalisedActInstThe localised activity (instance) which is encapsulated by this execution environment.protected LoggerloggerThe logger for execution environments.protected SessionContextsessionContextThe session context for this execution.static StringSUSPEND_SAVEPOINTThe name of the savepoint that will be used to store the state of the environment when suspending.-
Fields inherited from interface de.aristaflow.adept2.model.runtimeenvironment.ExecutableComponent
CONF_DATA_DIRECTORY, CONF_LIB_DIRECTORY, CONF_LOG_DIRECTORY, UNLOADING_CLASS_METHOD
-
-
Constructor Summary
Constructors Constructor Description ExecutionEnvironment(ActivityInstance activityInstance)Creates a newExecutionEnvironmentfor the designated activity.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcleanup()Performs all necessary cleanup of thisExecutableComponent.booleanclose()Returns false - overwrite this method to support closing.voidcommit()Throws anIsNotSupportedException- overwrite this method to support committing.protected ActivityDatacreateActivityData(ActivityInstance actInst, DataContext dataCont, Logger adLogger)Creates new activity data based on the designated information.protected SerializablegetApplicationState()Gets the application state stored for last savepoint as object.protected SerializablegetApplicationState(String savepoint)Gets the application state stored for the designated savepoint as object.protected byte[]getRawApplicationState()Gets the raw application state stored for last savepoint.protected byte[]getRawApplicationState(String savepoint)Gets the raw application state stored for designated savepoint as object.voidinit(SessionContext sessContext)Initialises thisExecutionEnvironmentby setting the session context, the logger field and the activity data.voidinitResume(String savepointId, SessionContext sessContext)Does nothing - overwrite this method to support resuming.booleankill()Returns false - overwrite this method to support killing.VoteprepareCommit()Throws anIsNotSupportedException- overwrite this method to support Two-phase-commit.protected <T extends GUIContext>
TrequireGUIContext(Class<T> guiContextType)Returns the required GUI context or throws an exception if it is not available.booleanreset()Returns false - overwrite this method to support reset.booleanrollback()Throws anIsNotSupportedException- overwrite this method to support rolling back.abstract voidrun()Resemblesexcept that this method is expected to throw exceptions indicating that the environment was unexpected or an internal failure occurred.Runnable.run()protected voidsetApplicationState(Serializable appState)Stores the application state as serialised Java object for the next savepoint.protected voidsetApplicationState(String savepoint, Serializable appState)Stores the application state for the designated savepoint as object.protected voidsetRawApplicationState(byte[] appState)Stores the raw application state for the next savepoint.protected voidsetRawApplicationState(String savepoint, byte[] appState)Stores the raw application state for the designated savepoint.booleansignal(int signal)Returns false - overwrite this method to support signalling.booleansuspend()Returns false - overwrite this method to support suspending.
-
-
-
Field Detail
-
SUSPEND_SAVEPOINT
public static final String SUSPEND_SAVEPOINT
The name of the savepoint that will be used to store the state of the environment when suspending.- See Also:
- Constant Field Values
-
logger
protected Logger logger
The logger for execution environments. It is protected for extensibility. Note that this will not be set until initialised.
-
activityInstance
protected final ActivityInstance activityInstance
The activity (instance) which is encapsulated by this execution environment.
-
localisedActInst
protected ActivityInstance localisedActInst
The localised activity (instance) which is encapsulated by this execution environment.
-
sessionContext
protected SessionContext sessionContext
The session context for this execution.
-
actData
protected ActivityData actData
-
cleanup
protected final Cleanup<RuntimeException> cleanup
The clean-up called after as post-mortem action of thisExecutionEnvironment. Since this is the same logic, it is also used bycleanup().
-
-
Constructor Detail
-
ExecutionEnvironment
public ExecutionEnvironment(ActivityInstance activityInstance)
Creates a newExecutionEnvironmentfor the designated activity. The constructor just sets the activity and the logger.- Parameters:
activityInstance- The activity instance for thisExecutionEnvironment.
-
-
Method Detail
-
init
public void init(SessionContext sessContext)
Initialises thisExecutionEnvironmentby setting the session context, the logger field and the activity data. These fields are not available before! Therefore you should call this method very early when initialising or initialising for resume.Initialises and prepares the execution of the application and provides all necessary data which maybe necessary for this. This method or
ExecutableComponent.initResume(String, SessionContext)is only called once in the lifetime of an executable component. One of these methods is guaranteed to be called before calling any other method.When leaving this method the execution has to be completely prepared. This includes for instance the availability of the GUI in the GUI context, which is necessary for Web applications with HTML-UI.
- Specified by:
initin interfaceExecutableComponent- Parameters:
sessContext- The session context to associate with thisExecutionEnvironment.
-
initResume
public void initResume(String savepointId, SessionContext sessContext)
Does nothing - overwrite this method to support resuming.
Note that this does neither set the session context nor the logger.Initialises and prepares the resuming of the application and provides all necessary data which maybe necessary for this. This method or
ExecutableComponent.init(SessionContext)is only called once in the lifetime of an executable component. One of these methods is guaranteed to be called before calling any other method.When leaving this method the execution has to be completely prepared for resuming. That is, the state of the application has to be restored. This includes the GUI.
Usually this method will delegate also call
ExecutableComponent.init(SessionContext).- Specified by:
initResumein interfaceExecutableComponent- Parameters:
savepointId- The identifier of the savepoint at which the application should resume. This must not benull, but it may be the empty string.sessContext- The session context in which the component is to be executed.
-
createActivityData
protected ActivityData createActivityData(ActivityInstance actInst, DataContext dataCont, Logger adLogger)
Creates new activity data based on the designated information. Override this factory method if you need to overrideActivityData. This method will usually be called just once in an early initialisation phase of an execution environment.- Parameters:
actInst- The activity (instance) which is encapsulated by this execution environment.dataCont- The context providing the activity data.adLogger- The logger for logging messages having additional information in case of problems when handling parameters or configuration values.- Returns:
- The newly created activity data. The caller is responsible for closing.
-
run
public abstract void run()
Description copied from interface:ExecutableComponentResemblesexcept that this method is expected to throw exceptions indicating that the environment was unexpected or an internal failure occurred. Both exceptions as well asRunnable.run()will set the corresponding process activity toRuntimeExceptionFAILED.- Specified by:
runin interfaceExecutableComponent
-
close
public boolean close()
Returns false - overwrite this method to support closing.Instructs the component to terminate. Within this method the component should deallocate all allocated resources.
- Specified by:
closein interfaceExecutableComponent- Returns:
false
-
reset
public boolean reset()
Returns false - overwrite this method to support reset.Instructs the component to reset. This is quite similar to
ExecutableComponent.kill()but the application does not fail but terminate normally (by callingRuntimeEnvironment.applicationReset(). The component will be re-initialised and executed again later.- Specified by:
resetin interfaceExecutableComponent- Returns:
false
-
signal
public boolean signal(int signal)
Returns false - overwrite this method to support signalling.Signals an event to the application.
- Specified by:
signalin interfaceExecutableComponent- Parameters:
signal- Ignored.- Returns:
false- See Also:
for possible signals. Usually the ones that have corresponding methods, e. g. or , will not be signaled via this method.
-
suspend
public boolean suspend()
Returns false - overwrite this method to support suspending.Instructs the component to store its internal state to the data context and to terminate at once. The application should be able to continue its job later when resuming.
- Specified by:
suspendin interfaceExecutableComponent- Returns:
false
-
kill
public boolean kill()
Returns false - overwrite this method to support killing.Enforces the application to abort its execution at once. In the case of running a internal transaction application should abort the transaction and should rollback. Within this method the component should deallocate all allocated resources.
- Specified by:
killin interfaceExecutableComponent- Returns:
false
-
prepareCommit
public Vote prepareCommit() throws IsNotSupportedException
Throws anIsNotSupportedException- overwrite this method to support Two-phase-commit.Instructs the component to vote for Commit or Abort of the distributed transaction it participates in and to prepare a commit.
- Specified by:
prepareCommitin interfaceExecutableComponent- Returns:
- Nothing, since an
IsNotSupportedExceptionis always thrown. - Throws:
IsNotSupportedException- This exception is always thrown.
-
commit
public void commit() throws IsNotSupportedExceptionThrows anIsNotSupportedException- overwrite this method to support committing.Instructs the component to commit its modifications not managed by ADEPT.
- Specified by:
commitin interfaceExecutableComponent- Throws:
IsNotSupportedException- This exception is always thrown.
-
rollback
public boolean rollback() throws IsNotSupportedExceptionThrows anIsNotSupportedException- overwrite this method to support rolling back.Instructs the component to undo all its modifications done within the current transaction. This method has to be implemented in case the application is
resettable.- Specified by:
rollbackin interfaceExecutableComponent- Returns:
- Nothing, since an
IsNotSupportedExceptionis always thrown. - Throws:
IsNotSupportedException- This exception is always thrown.
-
cleanup
public void cleanup()
Description copied from interface:ExecutableComponentPerforms all necessary cleanup of thisExecutableComponent. This will be called after the executing thread has leftExecutableComponent.run().- Specified by:
cleanupin interfaceExecutableComponent
-
getApplicationState
protected Serializable getApplicationState() throws IOException
Gets the application state stored for last savepoint as object. Note that this will only work, if you usedsetApplicationState(Serializable)orsetApplicationState(String, Serializable)for storing the application state.- Returns:
- An object representing the application state for the last
savepoint. This will be
nullin case no application state has been stored for the last savepoint (and of course ifnullhas been explicitly stored for the last savepoint). - Throws:
IOException- If there are problems deserialising the application state, anIOExceptionwill be thrown.
-
getRawApplicationState
protected byte[] getRawApplicationState()
Gets the raw application state stored for last savepoint. Note that this will only work, if you usedsetRawApplicationState(byte[])orsetRawApplicationState(String, byte[])for storing the application state.- Returns:
- The raw application state for the last savepoint. This will be
nullin case no application state has been stored for the last savepoint (and of course ifnullhas been explicitly stored for the last savepoint).
-
getApplicationState
protected Serializable getApplicationState(String savepoint) throws IOException
Gets the application state stored for the designated savepoint as object. Note that this will only work, if you usedsetApplicationState(String, Serializable)for storing the application state.- Parameters:
savepoint- The name of the savepoint for which to retrieve the application state. This allows for several different application states.- Returns:
- An object representing the application state for the designated
savepoint. This will be
nullin case no application state has been stored for the designated savepoint (and of course ifnullhas been explicitly stored for the designated savepoint). - Throws:
IOException- If there are problems deserialising the application state, anIOExceptionwill be thrown.
-
getRawApplicationState
protected byte[] getRawApplicationState(String savepoint)
Gets the raw application state stored for designated savepoint as object. Note that this will only work, if you usedsetRawApplicationState(byte[])orsetRawApplicationState(String, byte[])for storing the application state.- Parameters:
savepoint- The name of the savepoint for which to retrieve the raw application state. This allows for several different application states.- Returns:
- The raw application state for the designated savepoint. This will
be
nullin case no application state has been stored for the designated savepoint (and of course ifnullhas been explicitly stored for the designated savepoint).
-
setApplicationState
protected void setApplicationState(Serializable appState) throws IOException
Stores the application state as serialised Java object for the next savepoint. Usenullto remove the state for the next savepoint.- Parameters:
appState- An object representing the application state for the next savepoint. Usenullto remove it for the next savepoint.- Throws:
IOException- If there are problems serialising the application state, anIOExceptionwill be thrown.- See Also:
RuntimeEnvironment.setApplicationState(byte[])
-
setRawApplicationState
protected void setRawApplicationState(byte[] appState)
Stores the raw application state for the next savepoint. Usenullto remove the state for the next savepoint.- Parameters:
appState- The raw application state for the next savepoint. Usenullto remove it for the next savepoint.- See Also:
RuntimeEnvironment.setApplicationState(byte[])
-
setApplicationState
protected void setApplicationState(String savepoint, Serializable appState) throws IOException
Stores the application state for the designated savepoint as object. Usenullto remove the designated savepoint. The savepoint will not be flushed.- Parameters:
savepoint- The savepoint for which to store the application state. This allows for several different application states.appState- An object representing the application state for the designated savepoint. Usenullto remove the designated savepoint.- Throws:
IOException- If there are problems serialising the application state, anIOExceptionwill be thrown.- See Also:
RuntimeEnvironment.setApplicationState(byte[]),RuntimeEnvironment.setSavepoint(String, boolean)
-
setRawApplicationState
protected void setRawApplicationState(String savepoint, byte[] appState)
Stores the raw application state for the designated savepoint. Usenullto remove the state for the designated savepoint. The savepoint will not be flushed.- Parameters:
savepoint- The savepoint for which to store the application state. This allows for several different application states.appState- The raw application state for the designated savepoint. Usenullto remove it for the designated savepoint.- See Also:
RuntimeEnvironment.setApplicationState(byte[])
-
requireGUIContext
protected <T extends GUIContext> T requireGUIContext(Class<T> guiContextType)
Returns the required GUI context or throws an exception if it is not available.- Type Parameters:
T- the type of the required GUI context- Parameters:
guiContextType- the type of the required GUI context- Returns:
- the required GUI context if available
- Throws:
ApplicationEnvironmentException- if the required GUI context is not available
-
-