1 22 package org.jboss.web.tomcat.tc6.session; 23 24 import java.io.IOException ; 25 import javax.servlet.ServletException ; 26 import javax.transaction.TransactionManager ; 27 28 import org.apache.catalina.Lifecycle; 29 import org.apache.catalina.LifecycleException; 30 import org.apache.catalina.LifecycleListener; 31 import org.apache.catalina.connector.Request; 32 import org.apache.catalina.connector.Response; 33 import org.apache.catalina.util.LifecycleSupport; 34 import org.apache.catalina.valves.ValveBase; 35 import org.jboss.logging.Logger; 36 37 43 public class BatchReplicationClusteredSessionValve extends ValveBase implements Lifecycle 44 { 45 private static Logger log_ = Logger.getLogger(BatchReplicationClusteredSessionValve.class); 46 47 private static final String info = "BatchReplicationClusteredSessionValve/1.0"; 49 50 protected LifecycleSupport support = new LifecycleSupport(this); 52 53 protected JBossCacheManager manager_; 54 55 59 public BatchReplicationClusteredSessionValve(AbstractJBossManager manager) 60 { 61 super(); 62 manager_ = (JBossCacheManager)manager; 63 } 64 65 68 public String getInfo() 69 { 70 return info; 71 } 72 73 81 public void invoke(Request request, Response response) throws IOException , ServletException 82 { 83 TransactionManager tm = manager_.getCacheService().getTransactionManager(); 85 if(tm == null) 86 { 87 throw new RuntimeException ("BatchReplicationClusteredSessionValve.invoke(): Obtain null tm"); 88 } 89 90 request.getSession(false); 95 96 try 98 { 99 tm.begin(); 100 101 getNext().invoke(request, response); 103 104 log_.trace("Ready to commit batch replication for field level granularity"); 105 106 tm.commit(); 107 } 108 catch (Exception e) 109 { 110 try 111 { 112 tm.rollback(); 113 } 114 catch (Exception exn) 115 { 116 log_.error("Caught exception rolling back transaction", exn); 117 } 118 throw new RuntimeException ("JBossCacheManager.processSessionRepl(): failed to replicate session.", e); 120 } 121 } 122 123 public void addLifecycleListener(LifecycleListener listener) 125 { 126 support.addLifecycleListener(listener); 127 } 128 129 public void removeLifecycleListener(LifecycleListener listener) 130 { 131 support.removeLifecycleListener(listener); 132 } 133 134 public LifecycleListener[] findLifecycleListeners() 135 { 136 return support.findLifecycleListeners(); 137 } 138 139 public void start() throws LifecycleException 140 { 141 support.fireLifecycleEvent(START_EVENT, this); 142 } 143 144 public void stop() throws LifecycleException 145 { 146 support.fireLifecycleEvent(STOP_EVENT, this); 147 } 148 149 } 150 | Popular Tags |