1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.system;
17
18 import javax.servlet.ServletContext;
19 import javax.servlet.http.HttpSession;
20 import javax.servlet.http.HttpSessionEvent;
21 import javax.servlet.http.HttpSessionListener;
22
23 /***
24 * @author someda
25 */
26 public class TgwStatusListener implements HttpSessionListener {
27
28 private static long sessionCount = 0;
29
30 public void sessionCreated(HttpSessionEvent event) {
31 HttpSession session = event.getSession();
32 ServletContext sc = session.getServletContext();
33 incrementSessionCount();
34 setSessionCountAttribute(sc);
35 }
36
37 public void sessionDestroyed(HttpSessionEvent event) {
38 HttpSession session = event.getSession();
39 ServletContext sc = session.getServletContext();
40 decrementSessionCount();
41 setSessionCountAttribute(sc);
42 }
43
44 private synchronized static void incrementSessionCount(){
45 sessionCount++;
46 }
47
48 private synchronized static void decrementSessionCount(){
49 sessionCount--;
50 }
51
52 private void setSessionCountAttribute(ServletContext context){
53 Long count = new Long(sessionCount);
54 context.setAttribute(Constants.CATTR_SESSIONCOUNT,count);
55 }
56
57 }