001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.quercus.env;
031:
032: import com.caucho.quercus.QuercusModuleException;
033: import com.caucho.quercus.lib.UnserializeReader;
034: import com.caucho.server.cluster.ClusterObject;
035: import com.caucho.util.CacheListener;
036:
037: import java.io.IOException;
038: import java.io.ObjectInputStream;
039: import java.io.ObjectOutputStream;
040: import java.util.IdentityHashMap;
041: import java.util.Map;
042: import java.util.logging.Level;
043: import java.util.logging.Logger;
044:
045: /**
046: * Represents the $_SESSION
047: */
048: public class ResinSessionArrayValue extends SessionArrayValue {
049: static protected final Logger log = Logger
050: .getLogger(ResinSessionArrayValue.class.getName());
051:
052: private ClusterObject _clusterObject;
053:
054: public ResinSessionArrayValue(String id, long now,
055: long maxInactiveInterval) {
056: super (id, now, maxInactiveInterval);
057: }
058:
059: public ResinSessionArrayValue(String id, long now,
060: long maxInactiveInterval, ArrayValue array) {
061: super (id, now, maxInactiveInterval, array);
062: }
063:
064: public void setClusterObject(ClusterObject obj) {
065: _clusterObject = obj;
066: }
067:
068: /**
069: * Copy for serialization
070: */
071: @Override
072: public Value copy(Env env, IdentityHashMap<Value, Value> map) {
073: long accessTime = _accessTime;
074:
075: ResinSessionArrayValue copy = new ResinSessionArrayValue(
076: getId(), accessTime, getMaxInactiveInterval(),
077: (ArrayValue) getArray().copy(env, map));
078:
079: copy.setClusterObject(_clusterObject);
080:
081: return copy;
082: }
083:
084: @Override
085: public boolean load() {
086: if (_clusterObject != null)
087: return _clusterObject.load(this );
088: else
089: return true;
090: }
091:
092: protected void store() {
093: try {
094: ClusterObject clusterObject = _clusterObject;
095:
096: if (clusterObject != null) {
097: // make sure the object always saves - PHP references can make changes
098: // without directly calling on the session object
099: clusterObject.change();
100:
101: clusterObject.store(this );
102: }
103: } catch (Exception e) {
104: log.log(Level.WARNING, "Can't serialize session", e);
105: }
106: }
107:
108: /**
109: * Invalidates the session.
110: */
111: @Override
112: protected void remove() {
113: ClusterObject clusterObject = _clusterObject;
114: _clusterObject = null;
115:
116: if (clusterObject != null)
117: clusterObject.remove();
118: }
119: }
|