public void invoke(Request request,
Response response) throws IOException, ServletException {
// Initialize the context and store the request and response objects
// for any clustering code that has no direct access to these objects
SessionReplicationContext.enterWebapp(request, response, true);
try
{
// let the servlet invocation go through
getNext().invoke(request, response);
}
finally // We replicate no matter what
{
// -- > We are now after the servlet invocation
try
{
SessionReplicationContext ctx = SessionReplicationContext.exitWebapp();
if (ctx.getSoleSnapshotManager() != null)
{
ctx.getSoleSnapshotManager().snapshot(ctx.getSoleSession());
}
else
{
// Cross-context request touched multiple sesssions;
// need to replicate them all
Map sessions = ctx.getCrossContextSessions();
if (sessions != null && sessions.size() > 0)
{
for (Iterator iter = sessions.entrySet().iterator(); iter.hasNext();)
{
Map.Entry entry = (Map.Entry) iter.next();
((SnapshotManager) entry.getValue()).snapshot((ClusteredSession) entry.getKey());
}
}
}
}
finally
{
SessionReplicationContext.finishCacheActivity();
}
}
}
Valve-chain handler method.
This method gets called when the request goes through the Valve-chain. Our session replication mechanism replicates the
session after request got through the servlet code. |