KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > env > ResinSessionArrayValue


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.quercus.env;
31
32 import com.caucho.quercus.QuercusModuleException;
33 import com.caucho.quercus.lib.UnserializeReader;
34 import com.caucho.server.cluster.ClusterObject;
35 import com.caucho.util.CacheListener;
36
37 import java.io.IOException JavaDoc;
38 import java.io.ObjectInputStream JavaDoc;
39 import java.io.ObjectOutputStream JavaDoc;
40 import java.util.IdentityHashMap JavaDoc;
41 import java.util.Map JavaDoc;
42 import java.util.logging.Level JavaDoc;
43 import java.util.logging.Logger JavaDoc;
44
45 /**
46  * Represents the $_SESSION
47  */

48 public class ResinSessionArrayValue extends SessionArrayValue
49 {
50   static protected final Logger JavaDoc log
51     = Logger.getLogger(ResinSessionArrayValue.class.getName());
52
53   private ClusterObject _clusterObject;
54
55   public ResinSessionArrayValue(String JavaDoc id, long now,
56                 long maxInactiveInterval)
57   {
58     super(id, now, maxInactiveInterval);
59   }
60   
61   public ResinSessionArrayValue(String JavaDoc id, long now,
62                 long maxInactiveInterval, ArrayValue array)
63   {
64     super(id, now, maxInactiveInterval, array);
65   }
66
67   public void setClusterObject(ClusterObject obj)
68   {
69     _clusterObject = obj;
70   }
71
72   /**
73    * Copy for serialization
74    */

75   @Override JavaDoc
76   public Value copy(Env env, IdentityHashMap JavaDoc<Value,Value> map)
77   {
78     long accessTime = _accessTime;
79
80     ResinSessionArrayValue copy =
81       new ResinSessionArrayValue(getId(), accessTime, getMaxInactiveInterval(),
82                  (ArrayValue) getArray().copy(env, map));
83
84     copy.setClusterObject(_clusterObject);
85
86     return copy;
87   }
88
89   @Override JavaDoc
90   public boolean load()
91   {
92     if (_clusterObject != null)
93       return _clusterObject.load(this);
94     else
95       return true;
96   }
97
98   protected void store()
99   {
100     try {
101       ClusterObject clusterObject = _clusterObject;
102
103       if (clusterObject != null) {
104         // make sure the object always saves - PHP references can make changes
105
// without directly calling on the session object
106
clusterObject.change();
107
108         clusterObject.store(this);
109       }
110     } catch (Exception JavaDoc e) {
111       log.log(Level.WARNING, "Can't serialize session", e);
112     }
113   }
114
115   /**
116    * Invalidates the session.
117    */

118   @Override JavaDoc
119   protected void remove()
120   {
121     ClusterObject clusterObject = _clusterObject;
122     _clusterObject = null;
123
124     if (clusterObject != null)
125       clusterObject.remove();
126   }
127 }
128
Popular Tags