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.server.dispatch;
031:
032: import com.caucho.log.Log;
033: import com.caucho.server.webapp.WebApp;
034: import com.caucho.server.session.SessionManager;
035: import com.caucho.server.connection.AbstractHttpRequest;
036: import com.caucho.util.L10N;
037: import com.caucho.util.Alarm;
038: import com.caucho.vfs.Dependency;
039:
040: import java.util.logging.Logger;
041:
042: /**
043: * A repository for request information gleaned from the uri.
044: */
045: public class VersionInvocation extends Invocation {
046: static final L10N L = new L10N(Invocation.class);
047: static final Logger log = Logger.getLogger(Invocation.class
048: .getName());
049:
050: private final Invocation _invocation;
051: private final WebApp _webApp;
052:
053: private final Invocation _oldInvocation;
054: private final WebApp _oldWebApp;
055:
056: private final long _expireTime;
057:
058: public VersionInvocation(Invocation invocation, WebApp webApp,
059: Invocation oldInvocation, WebApp oldWebApp, long expireTime) {
060: _invocation = invocation;
061: _webApp = webApp;
062:
063: _oldInvocation = oldInvocation;
064: _oldWebApp = oldWebApp;
065:
066: _expireTime = expireTime;
067: }
068:
069: /**
070: * Returns true if the invocation has been modified. Generally only
071: * true if the webApp has been modified.
072: */
073: public boolean isModified() {
074: long now = Alarm.getCurrentTime();
075:
076: if (_expireTime < now)
077: return true;
078: else
079: return _invocation.isModified()
080: || _oldInvocation.isModified();
081: }
082:
083: /**
084: * Log the reason for modification.
085: */
086: public boolean logModified(Logger log) {
087: long now = Alarm.getCurrentTime();
088:
089: if (_expireTime < now) {
090: log
091: .info(L.l("{0}: versioning rollover complete.",
092: _webApp));
093:
094: return true;
095: } else
096: return _invocation.logModified(log)
097: || _oldInvocation.logModified(log);
098: }
099:
100: /**
101: * Returns the versioned invocation based on this request.
102: *
103: * @param request the servlet request
104: */
105: public Invocation getRequestInvocation(AbstractHttpRequest request) {
106: if (_expireTime < Alarm.getCurrentTime())
107: return _invocation;
108:
109: String sessionId = request.getRequestedSessionId();
110:
111: if (sessionId == null)
112: sessionId = _invocation.getSessionId();
113:
114: if (sessionId == null)
115: return _invocation;
116:
117: SessionManager oldSessionManager = _oldWebApp
118: .getSessionManager();
119:
120: if (oldSessionManager != null
121: && oldSessionManager.containsSession(sessionId)) {
122: return _oldInvocation;
123: } else
124: return _invocation;
125: }
126:
127: /**
128: * Returns the invocation's hash code.
129: */
130: public int hashCode() {
131: return _invocation.hashCode();
132: }
133:
134: /**
135: * Checks for equality
136: */
137: public boolean equals(Object o) {
138: return _invocation.equals(o);
139: }
140: }
|