The ActivitySession service is implemented as a high-level service on top of the implementation of the Java 2 Platform, Enterprise Edition (J2EE) 1.4 Activity Service. It provides a unit-of-work scope within which unrecoverable or non-two-phase resources can be managed, and does this in a way that is both distributed and cooperative with respect to transactions. Use this collection of sample applications to explore the ActivitySession service.
COPYRIGHT LICENSE: This information contains sample code provided in source code form. You may copy, modify, and distribute these sample programs in any form without payment to IBM for the purposes of developing, using, marketing or distributing application programs conforming to the application programming interface for the operating platform for which the sample code is written. Notwithstanding anything to the contrary, IBM PROVIDES THE SAMPLE SOURCE CODE ON AN "AS IS" BASIS AND IBM DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND ANY WARRANTY OR CONDITION OF NON-INFRINGEMENT. IBM SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR OPERATION OF THE SAMPLE SOURCE CODE. IBM HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS TO THE SAMPLE SOURCE CODE.
Enterprise beans have ActivitySession attributes that you can specify on a per-method basis as part of deployment. These attributes follow the model established by the transaction attributes defined in the Enterprise JavaBeans (EJB) specification with ActivitySessions being either bean-managed, or container-managed. The EJB container also supports activation and passivation policies scoped to the ActivitySession service and supports local transactions scoped to ActivitySession attributes, rather than restricted to method invocation boundaries.
Activity sessions can also be used in the web container and can be related to HTTP sessions. Web applications can be deployed with the following ActivitySession control values:
Container
The web application has no access to the UserActivitySession interface.
Each HTTP session created by the web application has an ActivitySession
service implicitly created and associated with it.
None
The web application does not use the ActivitySession service.
For more information, see the ActivitySession service topic in the WebSphere Application Server Information Center.
The sample application comprises three individual samples contained in a single EAR file:In the following information, profile_root refers to the root directory for your profile. For example, app_server_root/profiles/profile1.
profile_root/bin/wsadmin -conntype none -f samplesMaster.jacl
profile_root/bin/wsadmin -conntype none -lang jython
-c "AdminApp.uninstall('activitysession')"
On Windows operating systems, run:
profile_root\bin\setupCmdLine
On Unix operating systems, run:
. profile_root/bin/setupCmdLine.sh
On iSeries operating systems, run:
. profile_root/bin/setupCmdLine
./buildsamples
Information about how to run the individual samples is provided below.
The HTTP session association (MasterMind Game) samplehttp://host_name:port/samples/activitysessions/MasterMind
When a new game starts, a new HTTP session begins in the servlet. Because an activation session control of Container is specified, an activity session begins. The HTTP session lasts until the servlet invalidates it at the end of each game. Because the bean has an activation policy of ActivitySession, its transient state remains in memory for the duration of the game.
The client accesses the entity bean during an activity session. When the bean is accessed the client ActivitySession context is established in the bean because the ActivitySession attribute is Mandatory. No global transaction context exists, so a Local Transaction Containment (LTC) is started. The LTC is scoped to the activity session and the resolution control of ContainerAtBoundary causes the container to complete the LTC when the activity session ends.
The client runs two activity sessions, updating two instances of the bean in each session. The sample completes the first session with a checkpoint and the second session with a reset. It then checks that updates that were made during the first activity session are committed to the data store, and updates that were made during the second activity session are rolled back. Each instance of the bean runs within its own LTC, but the same activity session.
In addition to demonstrating how to access the UserActivitySession interface from a Java EE client, the sample shows how the LTCs used in the bean instances are completed by the container when the activity session is completed. This action is particularly noticeable where the ActivitySession reset causes both LTCs for each bean instance to roll back.
This usage scenario is common for activity sessions, whereby multiple operations against one or more beans backed by one-phase resource managers can be grouped together to be verified or discarded.
Running the container-managed ActivitySessions sample
On Windows operating systems, run:
profile_root\bin\setupCmdLine
On Unix operating systems, run:
. profile_root/bin/setupCmdLine.sh
On iSeries operating systems, run:
. profile_root/bin/setupCmdLine
On Windows operating systems, run:
profile_root\bin\launchClient activitysession.ear -CCBootstrapPort=port -CCjar=ASContainerSampleClient.jar -CCexitVM=trueOn Unix operating systems, run:
profile_root/bin/launchClient.sh activitysession.ear -CCBootstrapPort=port -CCjar=ASContainerSampleClient.jar -CCexitVM=trueOn iSeries operating systems, run:
profile_root/bin/launchClient activitysession.ear -CCBootstrapPort=port -CCjar=ASContainerSampleClient.jar -CCexitVM=trueThe element, port, is the port on which the application server is listening.
Configuration | Default Port Number |
---|---|
Base | 2809 |
Network Deployment | 9810 |
Starting ActivitySessions Sample Accessing UserActivitySession Retrieving an ASContainerManagedEJBHome from JNDI Finding or Creating EJB instances Starting First ActivitySession Updating EJBs Ending ActivitySession with Checkpoint Starting Second ActivitySession Updating EJBs Ending ActivitySession with Reset Checking values Sample has completed successfully
This sample shows a session bean with BeanManaged ActivitySession attributes accessing the UserActivitySession interface to begin and end activity sessions. During these ActivitySessions, instances of the ASContainerManagedEJB2 bean are accessed. The LTCs in the ASContainerManagedEJB2 beans are bounded by the activity session in which the bean instances are invoked. The Resource-Manager Local Transactions (RMLTs) used to access the local transaction-capable data source remain active over multiple method invocations that occur within the same activity session.
The LTC resolution control of Application means that the container does not automatically complete the LTCs (and by implication, RMLTs) in the direction specified at ActivitySession end. Rather, it is the responsibility of the application (in this case, the ASContainerManagedEJB2 bean instances) to complete the RMLTs in the correct directions. If incompleted RMLTs exist at the end of the activity session, the container completes them in the direction specified by the LTC unresolved action. In this case, unresolved RMLTs are rolled back at the end of an activity session.
Running the bean-managed ActivitySessions sample
On Windows operating systems, run:
profile_root\bin\setupCmdLine
On Unix operating systems, run:
. profile_root/bin/setupCmdLine.sh
On iSeries operating systems, run:
. profile_root/bin/setupCmdLine
On Windows operating systems, run:
profile_root\bin\launchClient activitysession.ear -CCBootstrapPort=port -CCjar=ASBeanSampleClient.jar -CCexitVM=trueOn Unix operating systems, run:
profile_root/bin/launchClient.sh activitysession.ear -CCBootstrapPort=port -CCjar=ASBeanSampleClient.jar -CCexitVM=trueOn iSeries operating systems, run:
profile_root/bin/launchClient activitysession.ear -CCBootstrapPort=port -CCjar=ASBeanSampleClient.jar -CCexitVM=trueThe element, port, is the port on which the application server is listening:
Configuration | Default Port Number |
---|---|
Base | 2809 |
Network Deployment | 9810 |
Starting ActivitySessions Sample Retrieving an ASBeanManagedEJBHome from JNDI Creating EJB instance Calling ASBeanManagedEJB to perform tasks Starting ActivitySessions Sample Retrieving an ASContainerManagedEJB2Home from JNDI Creating EJB instance Starting an ActivitySession Calling open Calling performUpdates Calling endLTC to end LTC with commit Ending an ActivitySession with EndModeCheckPoint Checking values Values correct Starting an ActivitySession Calling open Calling performUpdates Calling endLTC to end LTC with rollback Ending an ActivitySession with EndModeCheckPoint Checking values Values correct Starting an ActivitySession Calling open Calling performUpdates endLTC not called leaving LTC dangling Ending an ActivitySession with EndModeCheckPoint Checking values Values correct Sample has completed successfully