de.danet.an.workflow.tools.util
Class SimpleApplicationDirectoryEJB

java.lang.Object
  extended byde.danet.an.workflow.tools.util.SimpleApplicationDirectoryEJB
All Implemented Interfaces:
javax.ejb.EnterpriseBean, java.io.Serializable, javax.ejb.SessionBean

public class SimpleApplicationDirectoryEJB
extends java.lang.Object
implements javax.ejb.SessionBean

This EJB provides a directory for simple applications. Applications are considered simple in this context if their state can efficiently be represented (and stored) using a single serializable object.

This directory maps a unique id to the activity unique key information of the executing activity and an associated state (and vice versa). Optionally, the assignment time and an assigned resource may be saved in this directory as well.

Version:
$Revision: 1.15 $
Author:
Michael Lipp
See Also:
de.danet.an.workflow.util, Serialized Form

Constructor Summary
SimpleApplicationDirectoryEJB()
          Creates an instance of SimpleApplicationDirectoryEJB with all attributes initialized to default values.
 
Method Summary
 void ejbActivate()
          Not called for stateless session beans.
 void ejbCreate()
          Create a new EJB.
 void ejbPassivate()
          Not called for stateless session beans.
 void ejbRemove()
          Remove this EJB.
 SimpleApplicationInfo infoByActivity(ActivityUniqueKey auk)
          Return the information associated with the activity.
 java.util.Collection infosByApplication(java.lang.String applName)
          Return infos associated with a given application.
 java.util.Collection infosByKey(java.lang.String applName, java.lang.String applInstKey)
          Return the infos associated with the given application name and key.
 java.util.Collection infosByResource(java.lang.String applName, java.lang.String resourceKey)
          Return infos associated with a given application and resource.
 SimpleApplicationInfo instanceInfo(long instId)
          Return the information associated with the application instance.
 long registerInstance(java.lang.String applName, Activity activity, java.lang.Object state, boolean saveAssignment)
          Register a new application instance.
 long registerInstance(java.lang.String applName, java.lang.String applInstKey, Activity activity, java.lang.Object state, boolean saveAssignment)
          Register a new application instance.
 void removeInstance(long instId)
          Remove an application instance.
 void setSessionContext(javax.ejb.SessionContext context)
          Save the session context asigned by the container.
 void updateInvokingActivity(long instId, ActivityUniqueKey auk)
          Update the activity associated with the given application instance.
 void updateState(long instId, java.lang.Object state)
          Update the state information associated with the given application instance id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleApplicationDirectoryEJB

public SimpleApplicationDirectoryEJB()
Creates an instance of SimpleApplicationDirectoryEJB with all attributes initialized to default values.

Method Detail

setSessionContext

public void setSessionContext(javax.ejb.SessionContext context)
Save the session context asigned by the container.

Specified by:
setSessionContext in interface javax.ejb.SessionBean
Parameters:
context - the context

ejbCreate

public void ejbCreate()
               throws javax.ejb.CreateException
Create a new EJB.

Throws:
javax.ejb.CreateException - if creation fails

ejbRemove

public void ejbRemove()
Remove this EJB.

Specified by:
ejbRemove in interface javax.ejb.SessionBean

ejbActivate

public void ejbActivate()
                 throws javax.ejb.EJBException
Not called for stateless session beans.

Specified by:
ejbActivate in interface javax.ejb.SessionBean
Throws:
javax.ejb.EJBException
See Also:
SessionBean

ejbPassivate

public void ejbPassivate()
                  throws javax.ejb.EJBException
Not called for stateless session beans.

Specified by:
ejbPassivate in interface javax.ejb.SessionBean
Throws:
javax.ejb.EJBException
See Also:
SessionBean

registerInstance

public long registerInstance(java.lang.String applName,
                             Activity activity,
                             java.lang.Object state,
                             boolean saveAssignment)
Register a new application instance. This method returns a unique key that can be used to retrieve, update and removeInstance(long) remove the instance information.

Parameters:
applName - the application name
activity - the invoking activity
state - the application state
saveAssignment - if true the assigned resource will be saved to allow searching application instances with a particular assignee
Returns:
the instance id

registerInstance

public long registerInstance(java.lang.String applName,
                             java.lang.String applInstKey,
                             Activity activity,
                             java.lang.Object state,
                             boolean saveAssignment)
Register a new application instance. This method returns a unique key that may be used to

Parameters:
applName - the application name
applInstKey - an arbitrary key for this instance, up to 1000 characters long
activity - the invoking activity
state - the application state
saveAssignment - if true the assigned resource will be saved to allow searching application instances with a particular assignee
Returns:
the instance id

removeInstance

public void removeInstance(long instId)
Remove an application instance.

Parameters:
instId - the application instance id previously assigned by registerInstance

instanceInfo

public SimpleApplicationInfo instanceInfo(long instId)
                                   throws InvalidKeyException
Return the information associated with the application instance.

Parameters:
instId - the application instance id previously assigned by registerInstance
Returns:
the info
Throws:
InvalidKeyException - if there is no data available for the given id

infoByActivity

public SimpleApplicationInfo infoByActivity(ActivityUniqueKey auk)
                                     throws InvalidKeyException
Return the information associated with the activity.

Parameters:
auk - the unique key of the activity an application instance is expected to be registered for.
Returns:
the info
Throws:
InvalidKeyException - if there is no data available for the given activity

infosByApplication

public java.util.Collection infosByApplication(java.lang.String applName)
Return infos associated with a given application.

Parameters:
applName - the application name
Returns:
the infos as collection

infosByKey

public java.util.Collection infosByKey(java.lang.String applName,
                                       java.lang.String applInstKey)
                                throws InvalidKeyException
Return the infos associated with the given application name and key.

Parameters:
applName - the application name
applInstKey - the key associated with the instance
Returns:
the infos or an empty collection if no infos with the given application name and key exist
Throws:
InvalidKeyException

infosByResource

public java.util.Collection infosByResource(java.lang.String applName,
                                            java.lang.String resourceKey)
Return infos associated with a given application and resource.

Parameters:
applName - the application name
resourceKey - the resource's key
Returns:
the infos as collection

updateState

public void updateState(long instId,
                        java.lang.Object state)
                 throws InvalidKeyException
Update the state information associated with the given application instance id.

Parameters:
instId - the application instance id previously assigned by registerInstance
state - the new state
Throws:
InvalidKeyException - if there is no application instance with the given id

updateInvokingActivity

public void updateInvokingActivity(long instId,
                                   ActivityUniqueKey auk)
                            throws InvalidKeyException
Update the activity associated with the given application instance. This is useful if an application instance is started by one tool (agent) invocation and stopped by another.

Be careful to ensure the eventual termination of the application. If the creating activity has completed, the terminate method of the tool agent that started the application will not be called on abnormal process completion. So, if a process is terminated abnormally and the starting activity is closed and the stopping activity has not yet been started (and associated with the application) the application will not be stopped. This should normally not be a problem for simple applications.

As a convenience, any application information that is still registered after a process completion will automatically be deleted.

The new activity must belong to the same process as the activity that initially created the application instance.

Parameters:
instId - the application instance id previously assigned by registerInstance
auk - the new activity's unique key. May be null if the application instance is temporarily not associated with an activity.
Throws:
InvalidKeyException - if there is no application instance with the given id