1 17 18 package org.apache.catalina.session; 19 20 import java.beans.PropertyChangeListener ; 21 import java.beans.PropertyChangeSupport ; 22 import java.io.IOException ; 23 24 import org.apache.catalina.Lifecycle; 25 import org.apache.catalina.LifecycleException; 26 import org.apache.catalina.LifecycleListener; 27 import org.apache.catalina.Manager; 28 import org.apache.catalina.Store; 29 import org.apache.catalina.util.LifecycleSupport; 30 import org.apache.catalina.util.StringManager; 31 32 39 40 public abstract class StoreBase 41 implements Lifecycle, Store { 42 43 45 48 protected static String info = "StoreBase/1.0"; 49 50 53 protected static String storeName = "StoreBase"; 54 55 58 protected boolean started = false; 59 60 63 protected LifecycleSupport lifecycle = new LifecycleSupport(this); 64 65 68 protected PropertyChangeSupport support = new PropertyChangeSupport (this); 69 70 73 protected StringManager sm = StringManager.getManager(Constants.Package); 74 75 78 protected Manager manager; 79 80 82 85 public String getInfo() { 86 return(info); 87 } 88 89 90 93 public String getStoreName() { 94 return(storeName); 95 } 96 97 98 103 public void setManager(Manager manager) { 104 Manager oldManager = this.manager; 105 this.manager = manager; 106 support.firePropertyChange("manager", oldManager, this.manager); 107 } 108 109 112 public Manager getManager() { 113 return(this.manager); 114 } 115 116 117 119 124 public void addLifecycleListener(LifecycleListener listener) { 125 lifecycle.addLifecycleListener(listener); 126 } 127 128 129 133 public LifecycleListener[] findLifecycleListeners() { 134 135 return lifecycle.findLifecycleListeners(); 136 137 } 138 139 140 145 public void removeLifecycleListener(LifecycleListener listener) { 146 lifecycle.removeLifecycleListener(listener); 147 } 148 149 154 public void addPropertyChangeListener(PropertyChangeListener listener) { 155 support.addPropertyChangeListener(listener); 156 } 157 158 163 public void removePropertyChangeListener(PropertyChangeListener listener) { 164 support.removePropertyChangeListener(listener); 165 } 166 167 169 175 public void processExpires() { 176 long timeNow = System.currentTimeMillis(); 177 String [] keys = null; 178 179 if(!started) { 180 return; 181 } 182 183 try { 184 keys = keys(); 185 } catch (IOException e) { 186 manager.getContainer().getLogger().error("Error getting keys", e); 187 return; 188 } 189 if (manager.getContainer().getLogger().isDebugEnabled()) { 190 manager.getContainer().getLogger().debug(getStoreName()+ ": processExpires check number of " + keys.length + " sessions" ); 191 } 192 193 for (int i = 0; i < keys.length; i++) { 194 try { 195 StandardSession session = (StandardSession) load(keys[i]); 196 if (session == null) { 197 continue; 198 } 199 if (session.isValid()) { 200 continue; 201 } 202 if (manager.getContainer().getLogger().isDebugEnabled()) { 203 manager.getContainer().getLogger().debug(getStoreName()+ ": processExpires expire store session " + keys[i] ); 204 } 205 if ( ( (PersistentManagerBase) manager).isLoaded( keys[i] )) { 206 session.recycle(); 208 } else { 209 session.expire(); 211 } 212 remove(session.getIdInternal()); 213 } catch (Exception e) { 214 manager.getContainer().getLogger().error("Session: "+keys[i]+"; ", e); 215 try { 216 remove(keys[i]); 217 } catch (IOException e2) { 218 manager.getContainer().getLogger().error("Error removing key", e2); 219 } 220 } 221 } 222 } 223 224 225 227 228 236 public void start() throws LifecycleException { 237 if (started) 239 throw new LifecycleException 240 (sm.getString(getStoreName()+".alreadyStarted")); 241 lifecycle.fireLifecycleEvent(START_EVENT, null); 242 started = true; 243 244 } 245 246 247 255 public void stop() throws LifecycleException { 256 if (!started) 258 throw new LifecycleException 259 (sm.getString(getStoreName()+".notStarted")); 260 lifecycle.fireLifecycleEvent(STOP_EVENT, null); 261 started = false; 262 263 } 264 265 266 } 267 | Popular Tags |