001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ha.hasessionstate.server;
023:
024: import org.jboss.ha.hasessionstate.interfaces.PackagedSession;
025:
026: import java.io.IOException;
027: import java.io.Serializable;
028:
029: /**
030: * Default implementation of PackagedSession
031: *
032: * @see PackagedSession, HASessionStateImpl
033: * @author sacha.labourey@cogito-info.ch
034: * @version $Revision: 57188 $
035: */
036: public class PackagedSessionImpl implements PackagedSession {
037: /** The serialVersionUID
038: * @since 1.1.4.1
039: */
040: private static final long serialVersionUID = 4162160242862877223L;
041:
042: protected byte[] state;
043: protected long versionId;
044: protected String owner;
045: protected Serializable key;
046: protected transient long lastModificationTimeInVM;
047:
048: public PackagedSessionImpl() {
049: this .lastModificationTimeInVM = System.currentTimeMillis();
050: }
051:
052: public PackagedSessionImpl(Serializable key, byte[] state,
053: String owner) {
054: this .key = key;
055: this .setState(state);
056: this .owner = owner;
057: this .lastModificationTimeInVM = System.currentTimeMillis();
058: }
059:
060: public byte[] getState() {
061: return this .state;
062: }
063:
064: public boolean setState(byte[] state) {
065: this .lastModificationTimeInVM = System.currentTimeMillis();
066: if (isStateIdentical(state))
067: return true;
068: else {
069: this .state = state;
070: this .versionId++;
071: return false;
072: }
073: }
074:
075: public boolean isStateIdentical(byte[] state) {
076: return java.util.Arrays.equals(state, this .state);
077: }
078:
079: public void update(PackagedSession clone) {
080: this .state = (byte[]) clone.getState().clone();
081: this .versionId = clone.getVersion();
082: this .owner = clone.getOwner();
083: this .lastModificationTimeInVM = System.currentTimeMillis();
084: }
085:
086: public String getOwner() {
087: return this .owner;
088: }
089:
090: public void setOwner(String owner) {
091: this .owner = owner;
092: }
093:
094: public long getVersion() {
095: return this .versionId;
096: }
097:
098: public Serializable getKey() {
099: return this .key;
100: }
101:
102: public void setKey(Serializable key) {
103: this .key = key;
104: }
105:
106: public long unmodifiedExistenceInVM() {
107: return this .lastModificationTimeInVM;
108: }
109:
110: // JBAS-3545 -- have to set the mod time after deserializing
111: private void readObject(java.io.ObjectInputStream in)
112: throws IOException, ClassNotFoundException {
113: in.defaultReadObject();
114: this.lastModificationTimeInVM = System.currentTimeMillis();
115: }
116: }
|