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

reference to internal tomcat object (get # of sessions)

Hi tomcat developers,
Please help me out on getting a reference to internal tomcat object and
find out total number sessions now exist in tomcat instance (JVM).

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