0

I have an application deployed with JBoss on two machines in a cluster. When a user logs into one application server, I've validated that the session is replicated to the other cluster (logging in with the same cookies to the other server confirms this).

JBoss handles this replication automatically with Infinispan and JGroups for caching and messaging respectively. My issue is: How can I get a handle of each replicated session in the second server?

The normal way nowadays to manage HttpSession instances is by implementing the HttpSessionListener interface which calls a sessionCreated(HttpSession s) method whenever a new session is added. This works fine for the first server, but this does not work in the second server because: the session in server 1 is serialized, copied over, then de-serialized in the second server, which bypasses the constructor and therefore does not allow the session to be registered to the HttpSessionListener listener.

Is there another possibility to get a handle of a session as it is replicated? Could I perhaps listen for de-serialization events (is that even possible) or do something else?

Kon
  • 10,702
  • 6
  • 41
  • 58
  • 1
    If you are using infinispan to distribute them, then you can create an infinispan event `@Listener` and handle new sessions via `@CacheEntryCreated`: http://docs.jboss.org/infinispan/6.0/apidocs/org/infinispan/notifications/Listener.html – Shadow Man Apr 04 '14 at 00:47
  • @ShadowCreeper Thanks for the info, let me look into that. You should leave this as an answer so I can mark as correct as this seems to be the only way. HttpSessionContextListener doesn't work for 7.2.0 but this might. – Kon Apr 04 '14 at 15:49
  • Glad to help. I think it would be better if you answered the question yourself, with an example of the listener class you created and instructions on how to do it for the next guy who has this issue. All I did was point you in a (possibly-right) direction. I have no idea how you are handling your cache, if by yourself manually creating a `CacheManager` or through JBoss via `@Clustered` annotation, etc. – Shadow Man Apr 04 '14 at 18:44

0 Answers0