KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > container > monitor > SessionMonitor


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.container.monitor;
6
7 import java.util.* ;
8 import org.exoplatform.commons.utils.ExceptionUtil;
9 import org.exoplatform.container.client.ClientInfo ;
10 /**
11  * Tue, May 27, 2003 @
12  * @author: Tuan Nguyen
13  * @version: $Id: PortalMonitorService.java,v 1.2 2004/04/29 15:07:27 tuan08 Exp $
14  * @since: 0.0
15  * @email: tuan08@yahoo.com
16  */

17 public class SessionMonitor {
18   private SessionMonitorListenerStack listeners_ ;
19   private List history_ ;
20   private String JavaDoc error_ ;
21   private int errorCount_ = 0;
22   private int actionCount_ = 0;
23   private long startTime_ ;
24   private String JavaDoc owner_ ;
25   private ClientInfo clientInfo_ = ClientInfo.DEFAULT ;
26   
27   public SessionMonitor(SessionMonitorListenerStack listeners, String JavaDoc owner) {
28     startTime_ = System.currentTimeMillis() ;
29     history_ = new LinkedList() ;
30     listeners_ = listeners ;
31     owner_ = owner ;
32   }
33   
34   public String JavaDoc getSessionOwner() { return owner_ ; }
35   
36   public void log(ActionData data) {
37     if(error_ != null) data.setError(error_) ;
38     history_.add(data) ;
39     error_ = null ;
40     actionCount_++ ;
41     listeners_.onLog(this, data) ;
42   }
43   
44   public void error(String JavaDoc errorMessage, Throwable JavaDoc t) {
45     String JavaDoc trace = "no trace is available" ;
46     if(t != null) trace = ExceptionUtil.getStackTrace(t, 20) ;
47     error_ = errorMessage + "\n" + trace + "\n";
48     errorCount_++ ;
49     listeners_.onError(this, errorMessage, t) ;
50   }
51   
52   public List getHistory() { return history_ ; }
53   
54   public List emptyHistory() { return history_ ; }
55   
56   public SessionMonitorListenerStack getListeners() { return listeners_ ; }
57   
58   public int getErrorCount() { return errorCount_ ; }
59   
60   public int getActionCount() { return actionCount_ ; }
61   
62   public String JavaDoc getRemoteUser() { return clientInfo_.getRemoteUser() ; }
63   public String JavaDoc getIPAddress() { return clientInfo_.getIpAddress(); }
64   
65   public ClientInfo getClientInfo() { return clientInfo_ ; }
66   public void setClientInfo(ClientInfo ci) { clientInfo_ = ci ; }
67   
68   public long getAccessTime() { return startTime_ ; }
69   public long getLiveTime() { return System.currentTimeMillis() - startTime_ ;}
70   public long getLiveTimeInMinute() { return (System.currentTimeMillis() - startTime_)/60000 ;}
71   public long getLiveTimeInSecond() { return (System.currentTimeMillis() - startTime_)/1000 ;}
72 }
Popular Tags