KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > server > SessionsInfo


1 package org.enhydra.server;
2
3 import java.util.Date JavaDoc;
4
5 import com.lutris.appserver.server.Application;
6 import com.lutris.appserver.server.session.SessionException;
7 import com.lutris.appserver.server.session.SessionManager;
8 import com.lutris.appserver.server.sessionEnhydra.StandardSessionManager;
9 import com.lutris.util.Config;
10 import com.lutris.util.KeywordValueException;
11 /**
12  * <p>Title: </p>
13  * <p>Description:
14  * JavaBean class provide information about Session Manager
15  * from config file and currently active sessions from application
16  * SessionManager.</p>
17  * <p>Copyright: Copyright (c) 2002</p>
18  * <p>Company: www.together.at</p>
19  * @author Damir Milovic, damir@uns.ns.ac.yu
20  * @version 1.0b1
21  */

22
23 public class SessionsInfo {
24
25   private SessionManager sm ;
26   private String JavaDoc type;
27   private String JavaDoc persistence;
28   private String JavaDoc pageSessionsOnStop;
29   private String JavaDoc saveSessionsToMemoryOnStop;
30   private String JavaDoc activeSessions;
31   private String JavaDoc pagedSessions;
32   private String JavaDoc peakSessions;
33   private Date JavaDoc peakSessionsWhen;
34
35   private Config config;
36   /**
37    *
38    * @param app associate aplication
39    * @param smConfig cofig section for SessionManager
40    */

41   public SessionsInfo(Application app,Config smConfig)throws SessionException,KeywordValueException{
42     // Initialize properties from SessionManager
43
sm = null;
44       activeSessions = "N/A";
45       pagedSessions = "N/A";
46       peakSessions = "N/A";
47       peakSessionsWhen = null;
48
49     if(app != null) {
50       sm = app.getSessionManager();
51       if (sm != null){
52         activeSessions = String.valueOf(sm.activeSessionCount());
53         boolean classKnown=true;
54         try{
55         Class JavaDoc auxClass=Class.forName("com.lutris.appserver.server.sessionEnhydra.StandardSessionManager");
56         
57       }catch (Exception JavaDoc e){
58          classKnown=false;
59       }
60         if (classKnown && sm instanceof StandardSessionManager)
61           pagedSessions = String.valueOf(((StandardSessionManager)sm).pagedSessionCount());
62
63         peakSessions = String.valueOf(sm.maxSessionCount());
64         peakSessionsWhen = sm.maxSessionCountDate();
65       }else log("WARNING: SessionManager = null !");
66     }else log("WARNING: app = null !");
67
68     // Initialize properties from config file
69
config = smConfig;
70     persistence = "NO";
71     pageSessionsOnStop = "NO";
72     saveSessionsToMemoryOnStop = "NO";
73     if (config != null){
74       type = "Enhydra Standard Session Manager"; //FIXME, hard coded
75
if (config.containsKey("MemoryPersistence")){
76         if(config.getBoolean("MemoryPersistence")) saveSessionsToMemoryOnStop = "YES";
77       }
78
79       if (config.containsKey("SessionHome")){
80        config = (Config) config.getSection("SessionHome");
81         if (config.containsKey("Mode")){
82           String JavaDoc s = (String JavaDoc) config.get("Mode");
83           if (s.equalsIgnoreCase("BASIC")) persistence = "NO" ;
84           if (s.equalsIgnoreCase("PAGE_TO_DISK")) persistence = "Page to disk" ;
85           if (s.equalsIgnoreCase("PAGE_TO_DB")) persistence = "Page to DB" ;
86         }
87         if (config.containsKey("SaveOnRestart")){
88             if(config.getBoolean("SaveOnRestart")) pageSessionsOnStop = "YES";
89         }
90       }
91     }
92   }
93   /**
94    *
95    * @return number of currently active sessions
96    */

97   public String JavaDoc getActiveSessions() {
98     return activeSessions;
99   }
100   /**
101    *
102    * @return number of currently paged sessions
103    */

104   public String JavaDoc getPagedSessions() {
105     return pagedSessions;
106   }
107   /**
108    *
109    * @return parameter SaveSessionsOnRestart from config file
110    */

111   public String JavaDoc getPageSessionsOnStop() {
112     return pageSessionsOnStop;
113   }
114   public String JavaDoc getPeakSessions() {
115     return peakSessions;
116   }
117   public Date JavaDoc getPeakSessionsWhen() {
118     return peakSessionsWhen;
119   }
120   public String JavaDoc getPersistence() {
121     return persistence;
122   }
123   public String JavaDoc getSaveSessionsToMemoryOnStop() {
124     return saveSessionsToMemoryOnStop;
125   }
126   public String JavaDoc getType() {
127     return type;
128   }
129   private void log(String JavaDoc message){
130   //FIXME write to log file
131
System.err.println("EnhydraServer, SessionsInfo: "+message);
132   }
133 }
Popular Tags