001: package org.enhydra.server;
002:
003: import java.util.Date;
004:
005: import com.lutris.appserver.server.Application;
006: import com.lutris.appserver.server.session.SessionException;
007: import com.lutris.appserver.server.session.SessionManager;
008: import com.lutris.appserver.server.sessionEnhydra.StandardSessionManager;
009: import com.lutris.util.Config;
010: import com.lutris.util.KeywordValueException;
011:
012: /**
013: * <p>Title: </p>
014: * <p>Description:
015: * JavaBean class provide information about Session Manager
016: * from config file and currently active sessions from application
017: * SessionManager.</p>
018: * <p>Copyright: Copyright (c) 2002</p>
019: * <p>Company: www.together.at</p>
020: * @author Damir Milovic, damir@uns.ns.ac.yu
021: * @version 1.0b1
022: */
023:
024: public class SessionsInfo {
025:
026: private SessionManager sm;
027: private String type;
028: private String persistence;
029: private String pageSessionsOnStop;
030: private String saveSessionsToMemoryOnStop;
031: private String activeSessions;
032: private String pagedSessions;
033: private String peakSessions;
034: private Date peakSessionsWhen;
035:
036: private Config config;
037:
038: /**
039: *
040: * @param app associate aplication
041: * @param smConfig cofig section for SessionManager
042: */
043: public SessionsInfo(Application app, Config smConfig)
044: throws SessionException, KeywordValueException {
045: // Initialize properties from SessionManager
046: sm = null;
047: activeSessions = "N/A";
048: pagedSessions = "N/A";
049: peakSessions = "N/A";
050: peakSessionsWhen = null;
051:
052: if (app != null) {
053: sm = app.getSessionManager();
054: if (sm != null) {
055: activeSessions = String
056: .valueOf(sm.activeSessionCount());
057: boolean classKnown = true;
058: try {
059: Class auxClass = Class
060: .forName("com.lutris.appserver.server.sessionEnhydra.StandardSessionManager");
061:
062: } catch (Exception e) {
063: classKnown = false;
064: }
065: if (classKnown && sm instanceof StandardSessionManager)
066: pagedSessions = String
067: .valueOf(((StandardSessionManager) sm)
068: .pagedSessionCount());
069:
070: peakSessions = String.valueOf(sm.maxSessionCount());
071: peakSessionsWhen = sm.maxSessionCountDate();
072: } else
073: log("WARNING: SessionManager = null !");
074: } else
075: log("WARNING: app = null !");
076:
077: // Initialize properties from config file
078: config = smConfig;
079: persistence = "NO";
080: pageSessionsOnStop = "NO";
081: saveSessionsToMemoryOnStop = "NO";
082: if (config != null) {
083: type = "Enhydra Standard Session Manager"; //FIXME, hard coded
084: if (config.containsKey("MemoryPersistence")) {
085: if (config.getBoolean("MemoryPersistence"))
086: saveSessionsToMemoryOnStop = "YES";
087: }
088:
089: if (config.containsKey("SessionHome")) {
090: config = (Config) config.getSection("SessionHome");
091: if (config.containsKey("Mode")) {
092: String s = (String) config.get("Mode");
093: if (s.equalsIgnoreCase("BASIC"))
094: persistence = "NO";
095: if (s.equalsIgnoreCase("PAGE_TO_DISK"))
096: persistence = "Page to disk";
097: if (s.equalsIgnoreCase("PAGE_TO_DB"))
098: persistence = "Page to DB";
099: }
100: if (config.containsKey("SaveOnRestart")) {
101: if (config.getBoolean("SaveOnRestart"))
102: pageSessionsOnStop = "YES";
103: }
104: }
105: }
106: }
107:
108: /**
109: *
110: * @return number of currently active sessions
111: */
112: public String getActiveSessions() {
113: return activeSessions;
114: }
115:
116: /**
117: *
118: * @return number of currently paged sessions
119: */
120: public String getPagedSessions() {
121: return pagedSessions;
122: }
123:
124: /**
125: *
126: * @return parameter SaveSessionsOnRestart from config file
127: */
128: public String getPageSessionsOnStop() {
129: return pageSessionsOnStop;
130: }
131:
132: public String getPeakSessions() {
133: return peakSessions;
134: }
135:
136: public Date getPeakSessionsWhen() {
137: return peakSessionsWhen;
138: }
139:
140: public String getPersistence() {
141: return persistence;
142: }
143:
144: public String getSaveSessionsToMemoryOnStop() {
145: return saveSessionsToMemoryOnStop;
146: }
147:
148: public String getType() {
149: return type;
150: }
151:
152: private void log(String message) {
153: //FIXME write to log file
154: System.err.println("EnhydraServer, SessionsInfo: " + message);
155: }
156: }
|