"How can I persist custom user data as part of the BC4J appmodule state management mechanism?"
From your ApplicationModuleImpl subclass, you can access a java.util.Hashtable of user data by calling getSession().getUserData() . Objects you put into this hashtable will stay available to your current user based on the session id they've been assigned (BC4J calls this their SessionCookie ). In order to make this user data participate in the automatic state management mechanism that BC4J provides, you need to override two methods in your application module class passivateState and activateState . These methods allow you to decide what custom information should be saved, and reloaded (respectively) from the XML-based application module state "snapshot".
I built a little sample project that you can download here: PersistingUserData.zip
- Run TestServlet in the IDE
- Point browser1 at
http://localhost:8989/PersistingUserData/servlet/TestServlet
- Point browser2 at
http://localhost:8989/PersistingUserData/servlet/TestServlet
- Request the following URL in browser1:
http://localhost:8989/PersistingUserData/servlet/TestServlet?a=b&c=d
- Request the following URL in browser2:
http://localhost:8989/PersistingUserData/servlet/TestServlet?p=q&w=z
- Repeat step (2) to see that a = b and c = d for browser1 were remembered
- Repeat step (3) to see that p = q and w = z for browser2 were remembered
Set breakpoints on the passivateState and activateState methods in the TestModuleImpl.java class running under the debugger to see when they get called.
To force AM pool recycling for just two browser users, I've artificially set the following configuration parameters for testing/illustration purposes... jbo.recyclethreshold = 0 (Don't wait before recycling AM instances) jbo.ampool.maxpoolsize = 1 (Don't grow the pool beyond one AM instance) jbo.ampool.minavailablesize = 1 jbo.ampool.maxavailablesize = 1
11:57:21 AM
|