Develop an enterprise application to use ActivitySessions
This topic provides an overview of the high-level tasks for using ActivitySessions in enterprise applications.
Before using ActivitySessions in enterprise applications, consider the following points:
- An application that is accessed under an ActivitySession context can receive a javax.transaction.InvalidTransactionException RemoteException, thrown by the EJB container when servicing any application method. This exception occurs when an instance of an enterprise bean that has an ActivitySession-based activation policy becomes involved with concurrent global and local transactions.
- To enable an enterprise bean to participate in an ActivitySession context and support ActivitySession-based operations, it must be configured with an ActivationPolicy of ACTIVITY_SESSION. A bean configured with ActivationPolicy of either TRANSACTION or ONCE cannot participate in an ActivitySession context.
- A session bean can either use container-managed ActivitySessions or implement bean-managed ActivitySessions; entity beans can use only container-managed ActivitySessions. A bean is deployed to be bean-managed or container-managed with respect to ActivitySession management by setting its transaction type deployment attribute to be bean-managed or container-managed when we deploy the enterprise bean. A bean that uses bean-managed transactions can use bean-managed ActivitySessions; a bean that uses container-managed transactions can use container-managed ActivitySessions.
- If we want a session bean or an enterprise application client to manage its own ActivitySessions, write the code that explicitly demarcates the boundaries of an ActivitySession, as described in Developing an enterprise bean or J2EE client to manage ActivitySessions.
The following high level tasks illustrate how to use an ActivitySession in an enterprise application:
Tasks
- Develop an enterprise application that uses one or more enterprise beans that are persisted to non-transactional data stores. Use this approach for an application that needs to coordinate multiple one-phase resource managers, for example, for two or more entity enterprise beans whose persistence is delegated to LocalTransaction resource adapters.
In this scenario, the enterprise beans that the application uses have an Activation policy of ActivitySession and a local transaction containment policy with a boundary of ActivitySession and resolution-control of ContainerAtBoundary. The container synchronizes the EJB state data with the one-phase resource managers at ActivitySession completion, and no application code needs to be aware of ActivitySession support.
- Develop an enterprise application in which an enterprise bean accesses a resource manager multiple times in different business methods. Use this approach for an application that needs to extend a resource manager local transaction (RMLT) over several business methods of an enterprise bean instance.
In this scenario, the enterprise beans that the application uses have an Activation policy of ActivitySession and a local transaction containment policy with a boundary of ActivitySession and resolution-control of Application. The application logic starts and ends the RMLTs, for example, using the javax.resource.cci.LocalTransaction interface offered by a LocalTransaction Connector, but is not constrained to start and commit the LocalTransaction in the same method.
- Develop an enterprise client application to use an ActivitySession to scope EJB activation and load-balancing. Use this approach for an application client that needs to access an entity bean instance several times in the same client session, either without needing to run under a transaction context, or with the need to run under a number of distinct and serially-executed transactions.
In this scenario, the enterprise beans that the application uses have an Activation policy of ActivitySession and a local transaction containment policy appropriate to the function of the enterprise bean. The enterprise client application can represent a period of user activity, for example a signon period, during which a number of interactions occur with one or more enterprise beans. If the enterprise client application begins an ActivitySession and invokes the enterprise beans within the scope of the unit of work (UOW) that the ActivitySession represents, the container on the ActivitySession boundary activates the enterprise bean instances. The instances remain in the active state until the container passivates them at the end of the ActivitySession. Workload affinity management based on the ActivitySession is a platform quality of service. Global transactions can begin and end within the ActivitySession, if they are wholly encapsulated by the ActivitySession and run serially. EJB instances that are activated at the ActivitySession boundary remain active across the serial global transactions.
- Develop a Web application client to participate in an ActivitySession context. A Web application that runs in the WebSphere Web container can participate in an ActivitySession context. Web applications can use the UserActivitySession interface to begin and end an ActivitySession context. Also, the ActivitySession can be associated with an HttpSession, thereby extending access to the ActivitySession over multiple HTTP invocations and supporting EJB activation periods that can be determined by the lifecycle of the Web HTTP client.
The Web container manages ActivitySessions based on deployment descriptor attributes associated with the Web application module.
Example
For examples of using ActivitySessions in enterprise applications, see the topic about ActivitySessions samples.
Subtopics
- Develop an enterprise bean or enterprise application client to manage ActivitySessions
Use this task to write the code needed by a session EJB or enterprise application client to manage an ActivitySession, based on the example code extract provided.- ActivitySession service application programming interfaces
The ActivitySession service provides an application programming interface available to Web applications, session EJBs, and Java platform for enterprise applications client applications for application-managed demarcation of ActivitySession context.
Related:
The ActivitySession service ActivitySession service application programming interfaces ActivitySession and transaction contexts ActivitySession samples Developing an enterprise bean or enterprise application client to manage ActivitySessions Set Web module ActivitySession deployment attributes Set EJB module ActivitySession deployment attributes Usage model for using ActivitySessions with HTTP sessions ActivitySession and transaction container policies in combination