public void invoke(Request request,
Response response) throws IOException, ServletException {
// Note: we use specfically the tm in cache.
TransactionManager tm = manager_.getCacheService().getTransactionManager();
if(tm == null)
{
throw new RuntimeException("BatchReplicationClusteredSessionValve.invoke(): Obtain null tm");
}
// Before we start a tx, get the session. If this is a failover
// situation, this will cause data gravitation, which will occur
// thus outside of the scope of the tx we are about to start.
// JBossCacheManager will ensure the gravitation is in its own tx
request.getSession(false);
// Start a new transaction, we need transaction so all the replication are sent in batch.
try
{
tm.begin();
// let the servlet invocation go through
getNext().invoke(request, response);
log_.trace("Ready to commit batch replication for field level granularity");
tm.commit();
}
catch (Exception e)
{
try
{
tm.rollback();
}
catch (Exception exn)
{
log_.error("Caught exception rolling back transaction", exn);
}
// We will need to alert Tomcat of this exception.
if (e instanceof IOException)
throw (IOException) e;
if (e instanceof ServletException)
throw (ServletException) e;
if (e instanceof RuntimeException)
throw (RuntimeException) e;
throw new RuntimeException(e);
}
}
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. |