username and session caching
anwar83 Nov 20, 2006 9:28 PMHi, for your information, I've done a very simple/basic caching using jbosscache about 5 months ago and left it since then. In what have been done, I'm accessing a jbosscache(Mbean) and put a user session id in it. The article that I'm following is here
http://javaboutique.internet.com/tutorials/docaching/index-3.html
What happen is the data is not shared and each user have their own unique session id, which is exactly what I want it to be. I use JbossAS 4.0.4RC2 or 4.0.2 that time and maybe JbossCache 1.3(can't remember well, including the setting).
However when i tried it now with JbossAS 4.0.5 and Jboss 1.4, It doesn't work anymore. Instead the data that being put into cache will be overrided by a data from a second user. So now a first user will get a second user's session id, not his own.
The code use to put and get the data from jboss cache is as follow
private Option option = new Option(); private Fqn fqn =new Fqn("/user/session"); private Map<String, String> map = new HashMap<String, String>(); private TreeCacheMBean cache; private TreeCacheMBean getTreeCacheMBean() { if (cache == null) { try { log.info("TreeCacheMBean is null"); cache = (TreeCacheMBean) MBeanProxyExt.create( TreeCacheMBean.class, "jboss.cache:service=TomcatClusteringCache", server); } catch (MalformedObjectNameException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return cache; } public void insertSession(String sessionID, String userId) throws Exception { option.setCacheModeLocal(true); map.put("userId", userId); cache = getTreeCacheMBean(); cache.put(fqn,"sessionId", sessionId, option); log.info("End input into cache"); } public String getSession() throws Exception { String session = ""; cache = getTreeCacheMBean(); option.setCacheModeLocal(true); session = (String) cache.get(fqn,"sessionId",option); return session; }
I try to search in forum and found this
http://jboss.org/index.html?module=bb&op=viewtopic&t=86054
which is very-very similar with what I want to do. The question that puzzling me is can jboss cache automatically know who is whom in concurrent access? I means if it is able make a differentiate each user access without the data being overrided by newest insertion. I want to confirm whether my first try is really working or just my mistake in doing testing. If it is able to differentiate a user, then can you point me to configuration that need to be done? I read about locking and concurrency access but not found what i need. Sorry, a newbie here.
Thanks so much,
Anwar