1 22 package org.jboss.ha.hasessionstate.server; 23 24 import org.jboss.ha.hasessionstate.interfaces.PackagedSession; 25 26 import java.io.IOException ; 27 import java.io.Serializable ; 28 29 36 public class PackagedSessionImpl implements PackagedSession 37 { 38 41 private static final long serialVersionUID = 4162160242862877223L; 42 43 protected byte[] state; 44 protected long versionId; 45 protected String owner; 46 protected Serializable key; 47 protected transient long lastModificationTimeInVM; 48 49 public PackagedSessionImpl () 50 { 51 this.lastModificationTimeInVM = System.currentTimeMillis (); 52 } 53 54 public PackagedSessionImpl (Serializable key, byte[] state, String owner) 55 { 56 this.key = key; 57 this.setState (state); 58 this.owner = owner; 59 this.lastModificationTimeInVM = System.currentTimeMillis (); 60 } 61 62 public byte[] getState () 63 { 64 return this.state; 65 } 66 67 public boolean setState (byte[] state) 68 { 69 this.lastModificationTimeInVM = System.currentTimeMillis (); 70 if (isStateIdentical (state)) 71 return true; 72 else 73 { 74 this.state = state; 75 this.versionId++; 76 return false; 77 } 78 } 79 80 public boolean isStateIdentical (byte[] state) 81 { 82 return java.util.Arrays.equals (state, this.state); 83 } 84 85 public void update (PackagedSession clone) 86 { 87 this.state = (byte[])clone.getState().clone(); 88 this.versionId = clone.getVersion (); 89 this.owner = clone.getOwner (); 90 this.lastModificationTimeInVM = System.currentTimeMillis(); 91 } 92 93 public String getOwner () 94 { return this.owner; } 95 public void setOwner (String owner) 96 { this.owner = owner; } 97 98 public long getVersion () 99 { return this.versionId; } 100 101 public Serializable getKey () 102 { return this.key; } 103 public void setKey (Serializable key) 104 { this.key = key; } 105 106 public long unmodifiedExistenceInVM () 107 { 108 return this.lastModificationTimeInVM; 109 } 110 111 private void readObject(java.io.ObjectInputStream in) 113 throws IOException , ClassNotFoundException 114 { 115 in.defaultReadObject(); 116 this.lastModificationTimeInVM = System.currentTimeMillis(); 117 } 118 } 119 | Popular Tags |