You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by chiuming <ch...@yahoo.com> on 2001/09/09 06:11:01 UTC

Number of active session in Tomcat instance

Hi,
I had asked this question before. But I didn't get any
reply.  So I post this again in hope someone could
help me getting number of active session Tomcat holds.

The following code will return number of sessions in a
Context(web app)
but not all the sessions in the whole JVM (tomcat
instance).

For example:
if I call the class LocalMon in /admintool context:
/tomcat/webapps/admintool/WEB-INF/classes/LocalMon
then it will only report # of sessions in /admintool
web application.

Any way I can get the total number of sessions for all
web applications
(context)? -OR-
How to call LocalMon in /admintool context but reports
session on other
context(web app)?

My source file (class) return # of session and a (jsp)
is also 
attached.

===================================================
import java.util.Vector;
import java.util.Enumeration;
import java.io.File;
import java.net.URL;
import javax.servlet.http.*;

import org.apache.tomcat.core.Request;
import org.apache.tomcat.core.FacadeManager;
import org.apache.tomcat.core.Context;
import org.apache.tomcat.core.ContextManager;
import org.apache.tomcat.util.RequestUtil;
import org.apache.tomcat.session.StandardManager;

public class LocalMon
{
  private ContextManager cm;
  private Request realRequest;
  private StandardManager _sessionMgr;

  public void init( HttpServletRequest request ){
    FacadeManager facadeM =
(FacadeManager)request.getAttribute(
FacadeManager.FACADE_ATTRIBUTE);
    realRequest = facadeM.getRealRequest(request);
    cm = realRequest.getContext().getContextManager();
    try{
        int manager_note = cm.getNoteId(
ContextManager.CONTAINER_NOTE,
"tomcat.standardManager" );
        _sessionMgr =
(StandardManager)realRequest.getContext().getContainer().getNote(manager_note);

    } catch( Exception ignored ){
    }
  }

  public boolean initialized(){
      return ( cm != null );
  }

  public String getNumSessions(){
      return( String.valueOf(
_sessionMgr.getSessions().size() ) );
  }
}
==============================================================

thanks a lot

-cm



__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com