1 2 17 18 package org.apache.catalina.cluster.session; 19 20 43 import org.apache.catalina.Manager; 44 import java.io.IOException ; 45 import java.io.ObjectInputStream ; 46 import java.io.ObjectOutputStream ; 47 import java.security.Principal ; 48 49 public class ReplicatedSession extends org.apache.catalina.session.StandardSession 50 implements org.apache.catalina.cluster.ClusterSession{ 51 52 private transient Manager mManager = null; 53 protected boolean isDirty = false; 54 private transient long lastAccessWasDistributed = System.currentTimeMillis(); 55 private boolean isPrimarySession=true; 56 57 58 public ReplicatedSession(Manager manager) { 59 super(manager); 60 mManager = manager; 61 } 62 63 64 public boolean isDirty() 65 { 66 return isDirty; 67 } 68 69 public void setIsDirty(boolean dirty) 70 { 71 isDirty = dirty; 72 } 73 74 75 public void setLastAccessWasDistributed(long time) { 76 lastAccessWasDistributed = time; 77 } 78 79 public long getLastAccessWasDistributed() { 80 return lastAccessWasDistributed; 81 } 82 83 84 public void removeAttribute(String name) { 85 setIsDirty(true); 86 super.removeAttribute(name); 87 } 88 89 93 public void removeAttribute(String name, boolean notify) { 94 setIsDirty(true); 95 super.removeAttribute(name,notify); 96 } 97 98 99 102 public void setAttribute(String name, Object value) 103 { 104 if ( value == null ) { 105 removeAttribute(name); 106 return; 107 } 108 if (!(value instanceof java.io.Serializable )) 109 throw new java.lang.IllegalArgumentException ("Value for attribute "+name+" is not serializable."); 110 setIsDirty(true); 111 super.setAttribute(name,value); 112 } 113 114 public void setMaxInactiveInterval(int interval) { 115 setIsDirty(true); 116 super.setMaxInactiveInterval(interval); 117 } 118 119 120 124 public void setManager(SimpleTcpReplicationManager mgr) 125 { 126 mManager = mgr; 127 super.setManager(mgr); 128 } 129 130 131 139 public void setPrincipal(Principal principal) { 140 super.setPrincipal(principal); 141 setIsDirty(true); 142 } 143 144 public void expire() { 145 SimpleTcpReplicationManager mgr =(SimpleTcpReplicationManager)getManager(); 146 mgr.sessionInvalidated(getId()); 147 setIsDirty(true); 148 super.expire(); 149 } 150 151 public void invalidate() { 152 SimpleTcpReplicationManager mgr =(SimpleTcpReplicationManager)getManager(); 153 mgr.sessionInvalidated(getId()); 154 setIsDirty(true); 155 super.invalidate(); 156 } 157 158 159 169 public void readObjectData(ObjectInputStream stream) 170 throws ClassNotFoundException , IOException { 171 172 super.readObjectData(stream); 173 174 } 175 176 177 186 public void writeObjectData(ObjectOutputStream stream) 187 throws IOException { 188 189 super.writeObjectData(stream); 190 191 } 192 193 public void setId(String id, boolean tellNew) { 194 195 if ((this.id != null) && (manager != null)) 196 manager.remove(this); 197 198 this.id = id; 199 200 if (manager != null) 201 manager.add(this); 202 if (tellNew) tellNew(); 203 } 204 205 206 207 208 209 210 211 212 216 public boolean isPrimarySession() { 217 return isPrimarySession; 218 } 219 220 224 public void setPrimarySession(boolean primarySession) { 225 this.isPrimarySession=primarySession; 226 } 227 228 229 230 231 234 protected void log(String message) { 235 236 if ((mManager != null) && (mManager instanceof SimpleTcpReplicationManager)) { 237 ((SimpleTcpReplicationManager) mManager).log.debug("ReplicatedSession: " + message); 238 } else { 239 System.out.println("ReplicatedSession: " + message); 240 } 241 242 } 243 244 protected void log(String message, Throwable x) { 245 246 if ((mManager != null) && (mManager instanceof SimpleTcpReplicationManager)) { 247 ((SimpleTcpReplicationManager) mManager).log.error("ReplicatedSession: " + message,x); 248 } else { 249 System.out.println("ReplicatedSession: " + message); 250 x.printStackTrace(); 251 } 252 253 } 254 255 public String toString() { 256 StringBuffer buf = new StringBuffer ("ReplicatedSession id="); 257 buf.append(getId()).append(" ref=").append(super.toString()).append("\n"); 258 java.util.Enumeration e = getAttributeNames(); 259 while ( e.hasMoreElements() ) { 260 String name = (String )e.nextElement(); 261 Object value = getAttribute(name); 262 buf.append("\tname=").append(name).append("; value=").append(value).append("\n"); 263 } 264 buf.append("\tLastAccess=").append(getLastAccessedTime()).append("\n"); 265 return buf.toString(); 266 } 267 public int getAccessCount() { 268 return accessCount; 269 } 270 public void setAccessCount(int accessCount) { 271 this.accessCount = accessCount; 272 } 273 public long getLastAccessedTime() { 274 return lastAccessedTime; 275 } 276 public void setLastAccessedTime(long lastAccessedTime) { 277 this.lastAccessedTime = lastAccessedTime; 278 } 279 public long getThisAccessedTime() { 280 return thisAccessedTime; 281 } 282 public void setThisAccessedTime(long thisAccessedTime) { 283 this.thisAccessedTime = thisAccessedTime; 284 } 285 286 } 287 | Popular Tags |