001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixxml.serverutil;
021:
022: import java.util.LinkedList;
023:
024: import javax.servlet.http.HttpSession;
025:
026: /**
027: *
028: *
029: */
030:
031: public class SessionInfoStruct {
032: private int max_trail_elem = 25;
033: private HttpSession session;
034: private SessionData data;
035: private long numberofhits;
036: private LinkedList<TrailElement> traillog;
037:
038: /**
039: * Create a SessionInfoStruct with the given session, traillog and conutil.
040: * @param session
041: * @param trailog a trailog from another session used as the inital value for the trailog of this SessionInfoStruct.
042: May be null.
043: * @param conutil
044: */
045: public SessionInfoStruct(HttpSession session,
046: LinkedList<TrailElement> traillog, String serverName,
047: String remoteAddr) {
048: this .session = session;
049: this .data = new SessionData(session.getId(), serverName,
050: remoteAddr);
051: numberofhits = 0;
052: if (traillog != null) {
053: this .traillog = traillog;
054: } else {
055: this .traillog = new LinkedList<TrailElement>();
056: }
057: }
058:
059: public SessionData getData() {
060: return data;
061: }
062:
063: public void updateTimestamp(String servlet, String stylesheet) {
064: data.updateTimestamp();
065: numberofhits++;
066: synchronized (traillog) {
067: traillog.addLast(new TrailElement(servlet, stylesheet,
068: numberofhits));
069: if (traillog.size() > max_trail_elem) {
070: traillog.removeFirst();
071: }
072: }
073: }
074:
075: public LinkedList<SessionInfoStruct.TrailElement> getTraillog() {
076: return traillog;
077: }
078:
079: /**
080: * Get the number of times the session has been accessed (access to subframes isn't counted)
081: * @return value of numberofhits
082: */
083: public long getNumberOfHits() {
084: return numberofhits;
085: }
086:
087: public int getMaxTrailElem() {
088: return max_trail_elem;
089: }
090:
091: public void setMaxTrailElem(int max) {
092: max_trail_elem = max;
093: }
094:
095: /**
096: * Get the value of URI part with sessid.
097: * @return value of URI part with sessid.
098: */
099: public String getSessionIdURI() {
100: return (String) session
101: .getAttribute(SessionHelper.SESSION_ID_URL);
102: }
103:
104: public HttpSession getSession() {
105: return session;
106: }
107:
108: public class TrailElement {
109: String servletname;
110: String stylesheetname;
111: long count;
112:
113: public TrailElement(String sname, String ssheet, long c) {
114: servletname = sname;
115: stylesheetname = ssheet;
116: count = c;
117: }
118:
119: public String getServletname() {
120: return servletname;
121: }
122:
123: public String getStylesheetname() {
124: return stylesheetname;
125: }
126:
127: public long getCounter() {
128: return count;
129: }
130: }
131: }
|