I'm interested in the following: Once session replication occurs, is there a way to trigger code to be run in the application server to which data is replicated? For example, a user logs into Server 1, does something which triggers a replication to Server 2. Is it possible to cause some code to run once the replication occurs on Server 2?
I assume you mean when the actual failover happens and not on every replication?
Sounds like the best bet for you is the HttpSessionActivationListener, see http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpSessionActivationListener.html#sessionDidActivate(javax.servlet.http.HttpSessionEvent)
1 of 1 people found this helpful
I'm not certain that this actually works as it should in AS 7.2.0, although it definitely does in WildFly 8.0.0.
N.B. You should never attempt to modify the session in a session activation listener. These changes would need to replicate, which would trigger the session activation listener again, ad infinitum. To guard against this in WildFly, attempts to modify the session from a session activation listener will throw an IllegalStateException.
I think Paul is right. I don't see this working in my AS 7.2.0 deployment. I can't seem to get the implementation methods of this class to ever run. Unfortunately, WildFly 8.0.0 is not an option at the moment.
Thanks for the note on the modification. I only need these sessions on activation to populate some proprietary lists with the ID strings, which are immutable anyways.
Ah, different versions, different caveats