I'll try to describe my use case as simply as possible.

I have a JavaBean class, UserActivity, which uses a HashMap to contain members 
which are Strings, Dates, Booleans, and Integers.  The class contains mainly 
just getters and setters but also a few convenience methods for comparing 
dates, modifying counters, etc.

I have a standard MBean, UserActivityManager, which uses the TreeCacheAop 
service for caching HashMaps which are used to build UserActivity objects.  [I 
do this because I was never able to get replication working when caching 
non-Collection objects, so everytime I fetch a UserActivity I'm really doing a 
fetch of a HashMap and then constructing the UserActivity from the HashMap.  I 
know it's a hack, but it's working flawlessly for another class of objects 
being cached with TreeCacheAop so I've gone with it again for the user activity 
reports.]  This MBean provides a getUserActivity() method for accessing 
UserActivity objects.  It also provides several methods which are currently 
only being used via the JMX console, such as clearAllUsers(), 
getTotalUserCount(), displayAllUserActivity(), etc.

In the UserActivityManager.getUserActivity() method I return a UserActivity 
object built from the dynamic proxy for the correponding cached HashMap object, 
if it exists, like so:

HashMap map = (HashMap) m_mbeanServer.invoke(m_cacheServiceName,
  |                                              "getObject",
  |                                              new Object[] 
{fullyQualifiedName},
  |                                              new String[] 
{String.class.getName()});
  | return new UserActivity(map);

If a HashMap respresenting a UserActivity object for the user doesn't already 
exist then I create one, put it to the cache using TreeCacheAop.putObject(), 
and then construct and return a UserActivity object built from the dynamic 
proxy (the result of TreeCacheAop.getObject() as shown above).  For example:

HashMap map = new HashMap();
  | map.put("loginId", loginId);
  | m_mbeanServer.invoke(m_cacheServiceName,
  |                      "putObject",
  |                      new Object[] {fullyQualifiedName, map},
  |                      new String[] {String.class.getName(), 
Object.class.getName()});
  | map = (HashMap) m_mbeanServer.invoke(m_cacheServiceName,
  |                                      "getObject",
  |                                      new Object[] {fullyQualifiedName},
  |                                      new String[] {String.class.getName()});
  | return new UserActivity(map);

The code which actually uses the UserActivity objects is Servlet code which 
updates the various Dates, Strings, and Integer counts of the UserActivity 
objects via the setter methods.  It first creates and starts a transaction, 
then calls UserActivityManager.getUserActivity() to get a UserActivity object, 
and then updates the fields using the setter methods before finally committing 
the transaction.  For example:

// create and begin a transaction
  | UserTransaction userTransaction = (UserTransaction) 
m_jndiContext.lookup("UserTransaction");
  | userTransaction.begin();
  | 
  | // get the UserActivity for the user, creating one if one doesn't already 
exist
  | UserActivity userActivity = (UserActivity) 
m_mbeanServer.invoke(m_userActivityManagerService,
  |                                                 "getUserActivity",
  |                                                 new Object[] {loginId, new 
Boolean(true)},
  |                                                 new String[] 
{String.class.getName(), Boolean.class.getName()});
  |                 
  | // set the error and heartbeat time
  | userActivity.setLastErrorTime(new Date());
  | userActivity.setLastHeartbeatTime(new Date());
  | 
  | // commit the transaction
  | userTransaction.commit();


Thanks for any ideas as to what I might be doing wrong, how I might fix things, 
etc.


--James

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3871083#3871083

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3871083


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
JBoss-Development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to