1 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 17 public class SessionMonitor { 18 private SessionMonitorListenerStack listeners_ ; 19 private List history_ ; 20 private String error_ ; 21 private int errorCount_ = 0; 22 private int actionCount_ = 0; 23 private long startTime_ ; 24 private String owner_ ; 25 private ClientInfo clientInfo_ = ClientInfo.DEFAULT ; 26 27 public SessionMonitor(SessionMonitorListenerStack listeners, String owner) { 28 startTime_ = System.currentTimeMillis() ; 29 history_ = new LinkedList() ; 30 listeners_ = listeners ; 31 owner_ = owner ; 32 } 33 34 public String 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 errorMessage, Throwable t) { 45 String 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 getRemoteUser() { return clientInfo_.getRemoteUser() ; } 63 public String 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 |