1 7 package org.jboss.web.tomcat.tc5.session; 8 9 import org.jboss.metadata.WebMetaData; 10 11 import java.beans.PropertyChangeSupport ; 12 import java.io.Serializable ; 13 import java.security.Principal ; 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 16 import java.util.Map ; 17 18 36 class SessionBasedClusteredSession 37 extends ClusteredSession implements Serializable 38 { 39 static final long serialVersionUID = 3200976125245487256L; 40 43 protected static final String info = "SessionBasedClusteredSession/1.0"; 44 45 private transient boolean isSessionModifiedSinceLastSave; 46 private transient JBossCacheService proxy_; 47 48 public SessionBasedClusteredSession(AbstractJBossManager manager) 49 { 50 super(manager); 51 initAfterLoad(manager); 52 } 53 54 60 public void initAfterLoad(AbstractJBossManager manager) 61 { 62 if (this.proxy_ == null) 64 { 65 if (log.isDebugEnabled()) 66 { 67 log.debug("initAfterLoad(): initialize the transient variables ..."); 68 } 69 setManager(manager); 70 listeners = new ArrayList (); 71 notes = new HashMap (); 72 support = new PropertyChangeSupport (this); 73 expiring = false; 74 isSessionModifiedSinceLastSave = false; 75 76 isOutdated = false; 78 79 proxy_ = ((JBossCacheManager) manager).getCacheService(); 80 81 if (proxy_ == null) 83 { 84 throw new RuntimeException ("SessionBasedClusteredSession: Cache service is null."); 85 } 86 87 this.activate(); 89 } 90 } 91 92 99 public void setCreationTime(long time) 100 { 101 super.setCreationTime(time); 102 sessionIsDirty(); 103 } 104 105 113 public void setPrincipal(Principal principal) 114 { 115 116 Principal oldPrincipal = this.principal; 117 this.principal = principal; 118 support.firePropertyChange("principal", oldPrincipal, this.principal); 119 120 if ((oldPrincipal != null && !oldPrincipal.equals(principal)) || 121 (oldPrincipal == null && principal != null)) 122 sessionIsDirty(); 123 124 } 125 126 130 public String toString() 131 { 132 StringBuffer sb = new StringBuffer (); 133 sb.append("SessionBasedClusteredSession["); 134 sb.append(id); 135 sb.append("]"); 136 return (sb.toString()); 137 138 } 139 140 143 public synchronized void processSessionRepl() 144 { 145 if (!isSessionDirty()) 146 { 147 if (log.isDebugEnabled()) 148 { 149 log.debug("processSessionRepl(): session is not dirty. No need to replicate."); 150 } 151 return; 152 } 153 if (log.isDebugEnabled()) 156 { 157 log.debug("processSessionRepl(): session is dirty. Will increment version from: " + 158 getVersion() + " and replicate."); 159 } 160 this.incrementVersion(); proxy_.putSession(id, this); 162 163 isSessionModifiedSinceLastSave = false; 164 } 165 166 public void removeMyself() 167 { 168 proxy_.removeSession(id); 169 } 170 171 public void removeMyselfLocal() 172 { 173 proxy_.removeSessionLocal(id); 174 } 175 176 178 183 public void access() 184 { 185 super.access(); 186 if (invalidationPolicy == WebMetaData.SESSION_INVALIDATE_ACCESS) 189 { 190 this.sessionIsDirty(); 191 } 192 } 193 194 protected Object getJBossInternalAttribute(String name) 195 { 196 197 Object result = attributes.get(name); 198 199 if (result != null) 200 { 201 if (invalidationPolicy == WebMetaData.SESSION_INVALIDATE_SET_AND_GET) 202 { 203 sessionIsDirty(); 204 } 205 else if (invalidationPolicy == WebMetaData.SESSION_INVALIDATE_SET_AND_NON_PRIMITIVE_GET) 206 { 207 if (!(result instanceof String || 208 result instanceof Integer || 209 result instanceof Long || 210 result instanceof Byte || 211 result instanceof Short || 212 result instanceof Float || 213 result instanceof Double || 214 result instanceof Character || 215 result instanceof Boolean ) 216 ) 217 { 218 sessionIsDirty(); 219 } 220 } 221 } 222 223 return result; 224 225 } 226 227 protected Object removeJBossInternalAttribute(String name) 228 { 229 sessionIsDirty(); 230 return attributes.remove(name); 231 } 232 233 protected Map getJBossInternalAttributes() 234 { 235 sessionIsDirty(); 238 return attributes; 239 } 240 241 protected Object setJBossInternalAttribute(String name, Object value) 242 { 243 sessionIsDirty(); 244 return attributes.put(name, value); 245 } 246 247 protected void sessionIsDirty() 248 { 249 isSessionModifiedSinceLastSave = true; 251 } 252 253 public boolean isSessionDirty() 254 { 255 return isSessionModifiedSinceLastSave; 256 } 257 258 } 259 | Popular Tags |