1 22 package org.jboss.web.tomcat.tc6.session; 23 24 import java.io.IOException ; 25 import java.util.Iterator ; 26 import java.util.Map ; 27 28 import javax.servlet.ServletException ; 29 30 import org.apache.catalina.*; 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 36 47 public class ClusteredSessionValve extends ValveBase implements Lifecycle 48 { 49 private static final String info = "ClusteredSessionValve/1.0"; 51 52 private LifecycleSupport support = new LifecycleSupport(this); 54 55 58 public ClusteredSessionValve() 59 { 60 super(); 61 } 62 63 66 public String getInfo() 67 { 68 return info; 69 } 70 71 79 public void invoke(Request request, Response response) throws IOException , ServletException 80 { 81 SessionReplicationContext.enterWebapp(request, response, true); 84 try 85 { 86 87 88 getNext().invoke(request, response); 90 } 91 finally { 93 try 95 { 96 SessionReplicationContext ctx = SessionReplicationContext.exitWebapp(); 97 98 if (ctx.getSoleSnapshotManager() != null) 99 { 100 ctx.getSoleSnapshotManager().snapshot(ctx.getSoleSession()); 101 } 102 else 103 { 104 Map sessions = ctx.getCrossContextSessions(); 107 if (sessions != null && sessions.size() > 0) 108 { 109 for (Iterator iter = sessions.entrySet().iterator(); iter.hasNext();) 110 { 111 Map.Entry entry = (Map.Entry ) iter.next(); 112 ((SnapshotManager) entry.getValue()).snapshot((ClusteredSession) entry.getKey()); 113 } 114 } 115 } 116 } 117 finally 118 { 119 SessionReplicationContext.finishCacheActivity(); 120 } 121 122 } 123 } 124 125 public void addLifecycleListener(LifecycleListener listener) 127 { 128 support.addLifecycleListener(listener); 129 } 130 131 public void removeLifecycleListener(LifecycleListener listener) 132 { 133 support.removeLifecycleListener(listener); 134 } 135 136 public LifecycleListener[] findLifecycleListeners() 137 { 138 return support.findLifecycleListeners(); 139 } 140 141 public void start() throws LifecycleException 142 { 143 support.fireLifecycleEvent(START_EVENT, this); 144 } 145 146 public void stop() throws LifecycleException 147 { 148 support.fireLifecycleEvent(STOP_EVENT, this); 149 } 150 151 } 152 | Popular Tags |