KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ha > hasessionstate > server > PackagedSessionImpl


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ha.hasessionstate.server;
23
24 import org.jboss.ha.hasessionstate.interfaces.PackagedSession;
25
26 import java.io.IOException JavaDoc;
27 import java.io.Serializable JavaDoc;
28
29 /**
30  * Default implementation of PackagedSession
31  *
32  * @see PackagedSession, HASessionStateImpl
33  * @author sacha.labourey@cogito-info.ch
34  * @version $Revision: 56185 $
35  */

36 public class PackagedSessionImpl implements PackagedSession
37 {
38    /** The serialVersionUID
39     * @since 1.1.4.1
40     */

41    private static final long serialVersionUID = 4162160242862877223L;
42
43    protected byte[] state;
44    protected long versionId;
45    protected String JavaDoc owner;
46    protected Serializable JavaDoc key;
47    protected transient long lastModificationTimeInVM;
48    
49    public PackagedSessionImpl ()
50    {
51       this.lastModificationTimeInVM = System.currentTimeMillis ();
52    }
53    
54    public PackagedSessionImpl (Serializable JavaDoc key, byte[] state, String JavaDoc 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 JavaDoc getOwner ()
94    { return this.owner; }
95    public void setOwner (String JavaDoc owner)
96    { this.owner = owner; }
97    
98    public long getVersion ()
99    { return this.versionId; }
100    
101    public Serializable JavaDoc getKey ()
102    { return this.key; }
103    public void setKey (Serializable JavaDoc key)
104    { this.key = key; }
105
106    public long unmodifiedExistenceInVM ()
107    {
108       return this.lastModificationTimeInVM;
109    }
110    
111    // JBAS-3545 -- have to set the mod time after deserializing
112
private void readObject(java.io.ObjectInputStream JavaDoc in)
113          throws IOException JavaDoc, ClassNotFoundException JavaDoc
114    {
115       in.defaultReadObject();
116       this.lastModificationTimeInVM = System.currentTimeMillis();
117    }
118 }
119
Popular Tags