1 7 package org.jboss.web.tomcat.tc5.session; 8 9 import java.io.IOException ; 10 import javax.servlet.http.HttpSession ; 11 import javax.servlet.ServletException ; 12 13 import org.apache.catalina.*; 14 import org.apache.catalina.connector.Request; 15 import org.apache.catalina.connector.Response; 16 import org.apache.catalina.util.LifecycleSupport; 17 import org.apache.catalina.valves.ValveBase; 18 19 29 public class ClusteredSessionValve extends ValveBase implements Lifecycle 30 { 31 private static final String info = "ClusteredSessionValve/1.0"; 33 34 protected SnapshotManager snapshot; 36 37 protected LifecycleSupport support = new LifecycleSupport(this); 39 40 protected static ThreadLocal requestThreadLocal = new ThreadLocal (); 43 protected static ThreadLocal responseThreadLocal = new ThreadLocal (); 44 45 50 public ClusteredSessionValve(SnapshotManager snapshot) 51 { 52 super(); 53 this.snapshot = snapshot; 54 } 55 56 59 public String getInfo() 60 { 61 return info; 62 } 63 64 73 public void invoke(Request request, Response response) throws IOException , ServletException 74 { 75 requestThreadLocal.set(request); 78 responseThreadLocal.set(response); 79 80 getNext().invoke(request, response); 82 83 85 HttpSession session = request.getSession(false); 87 88 if (session != null && session.getId() != null) 89 { 90 snapshot.snapshot(session.getId()); 92 } 93 94 requestThreadLocal.set(null); 97 responseThreadLocal.set(null); 98 } 99 100 public void addLifecycleListener(LifecycleListener listener) 102 { 103 support.addLifecycleListener(listener); 104 } 105 106 public void removeLifecycleListener(LifecycleListener listener) 107 { 108 support.removeLifecycleListener(listener); 109 } 110 111 public LifecycleListener[] findLifecycleListeners() 112 { 113 return support.findLifecycleListeners(); 114 } 115 116 public void start() throws LifecycleException 117 { 118 snapshot.start(); 119 support.fireLifecycleEvent(START_EVENT, this); 120 } 121 122 public void stop() throws LifecycleException 123 { 124 support.fireLifecycleEvent(STOP_EVENT, this); 125 snapshot.stop(); 126 } 127 128 } 129 | Popular Tags |