You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by chiu ming luk <ch...@yahoo.com> on 2001/09/09 06:08:00 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 currect
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
Re: Number of active session in Tomcat instance
Posted by cm...@yahoo.com.
On Sun, 9 Sep 2001, chiu ming luk wrote:
> But I think this line is what I am using, It only
> returns # of sessions for the context which the code
> get called.
>
int manager_note = cm.getNoteId(
ContextManager.CONTAINER_NOTE, "tomcat.standardManager" );
_sessionMgr =
(StandardManager)realRequest.getContext().getContainer().getNote(manager_note);
Replace realRequest.getContext() with the cotexts you get from
ContextManager.
Enumeration enum=cm.getContexts();
...
_sessionMgrForOtherContext=
((Context)enum.nextElement()).getContainer().getNote(manager_note );
Costin
Re: Number of active session in Tomcat instance
Posted by chiu ming luk <ch...@yahoo.com>.
But I think this line is what I am using, It only
returns # of sessions for the context which the code
get called.
Any way I can get # of sessions for other context -OR-
for the whole tomcat instance?
thanks again.
--- cmanolache@yahoo.com wrote:
> On Sun, 9 Sep 2001, chiu ming luk wrote:
>
> > But there is no such method:
> >
> >
>
context.getContainer().getNote("tomcat.standardManager")
> >
> > in tomcat 3.2.1.
> >
> > getNote() would take an integer argument instead
> of a
> > string. What should be the argument of getNote()
> and
> > what will Container.getNote() return? according
> to
> > the source code. It returns Object type.
>
>
>
>
> > > > > > int manager_note = cm.getNoteId(
> > > > > > ContextManager.CONTAINER_NOTE,
> "tomcat.standardManager" );
> > > > > > _sessionMgr =
>
>
(StandardManager)realRequest.getContext().getContainer().getNote(manager_note);
>
> Costin
>
__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com
Re: Number of active session in Tomcat instance
Posted by cm...@yahoo.com.
On Sun, 9 Sep 2001, chiu ming luk wrote:
> But there is no such method:
>
> context.getContainer().getNote("tomcat.standardManager")
>
> in tomcat 3.2.1.
>
> getNote() would take an integer argument instead of a
> string. What should be the argument of getNote() and
> what will Container.getNote() return? according to
> the source code. It returns Object type.
> > > > > int manager_note = cm.getNoteId(
> > > > > ContextManager.CONTAINER_NOTE, "tomcat.standardManager" );
> > > > > _sessionMgr =
(StandardManager)realRequest.getContext().getContainer().getNote(manager_note);
Costin
Re: Number of active session in Tomcat instance
Posted by chiu ming luk <ch...@yahoo.com>.
But there is no such method:
context.getContainer().getNote("tomcat.standardManager")
in tomcat 3.2.1.
getNote() would take an integer argument instead of a
string. What should be the argument of getNote() and
what will Container.getNote() return? according to
the source code. It returns Object type.
thanks again.
--- cmanolache@yahoo.com wrote:
> The SessionManager is saved as a note in the
> context.
>
>
context.getContainer().getNote("tomcat.standardManager")
>
>
> Session management is at a higher level than
> tomcat.core, and
> the goal was to modularize tomcat and keep the
> components as
> independent as possible - with interceptors used as
> 'glue' between
> components.
>
> SimpleSessionManager uses notes to associate a
> manager instance
> with each Context.
>
> More sophisticated solutions could use a single
> manager for
> the entire tomcat - this would scale much better,
> and would
> probably be easier to control.
>
> Costin
>
>
>
> On Sun, 9 Sep 2001, chiu ming luk wrote:
>
> > Costin,
> > after I get the specific Context object in
> > org.apache.tomcat.core.Context.
> >
> > How can I get the SessionManager for that Context?
> >
> > thanks again.
> > ===============================================
> > realRequest = facadeM.getRealRequest(request);
> > cm = realRequest.getContext().getContextManager();
> > Enumeration e = cm.getContexts();
> > while ( e.hasMoreElements() ){
> > Context con = (Context) e.nextElement();
> > //how to get sessionManager?
> > int size = sessionMgr.getSessions().size();
> > }
> > ===============================================
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > --- cmanolache@yahoo.com wrote:
> > > Hi,
> > >
> > > What you can do is use
> ContextManager.getContexts(),
> > > then for each context you can get its
> > > SessionManager.
> > >
> > >
> > > Costin
> > >
> > >
> > > On Sat, 8 Sep 2001, chiu ming luk wrote:
> > >
> > > > 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
> currect
> > > > 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
> > >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Get email alerts & NEW webcam video instant
> messaging with Yahoo! Messenger
> > http://im.yahoo.com
>
=== message truncated ===
__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com
Re: Number of active session in Tomcat instance
Posted by cm...@yahoo.com.
The SessionManager is saved as a note in the context.
context.getContainer().getNote("tomcat.standardManager")
Session management is at a higher level than tomcat.core, and
the goal was to modularize tomcat and keep the components as
independent as possible - with interceptors used as 'glue' between
components.
SimpleSessionManager uses notes to associate a manager instance
with each Context.
More sophisticated solutions could use a single manager for
the entire tomcat - this would scale much better, and would
probably be easier to control.
Costin
On Sun, 9 Sep 2001, chiu ming luk wrote:
> Costin,
> after I get the specific Context object in
> org.apache.tomcat.core.Context.
>
> How can I get the SessionManager for that Context?
>
> thanks again.
> ===============================================
> realRequest = facadeM.getRealRequest(request);
> cm = realRequest.getContext().getContextManager();
> Enumeration e = cm.getContexts();
> while ( e.hasMoreElements() ){
> Context con = (Context) e.nextElement();
> //how to get sessionManager?
> int size = sessionMgr.getSessions().size();
> }
> ===============================================
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --- cmanolache@yahoo.com wrote:
> > Hi,
> >
> > What you can do is use ContextManager.getContexts(),
> > then for each context you can get its
> > SessionManager.
> >
> >
> > Costin
> >
> >
> > On Sat, 8 Sep 2001, chiu ming luk wrote:
> >
> > > 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 currect
> > > 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
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
> http://im.yahoo.com
>
Re: Number of active session in Tomcat instance
Posted by chiu ming luk <ch...@yahoo.com>.
Costin,
after I get the specific Context object in
org.apache.tomcat.core.Context.
How can I get the SessionManager for that Context?
thanks again.
===============================================
realRequest = facadeM.getRealRequest(request);
cm = realRequest.getContext().getContextManager();
Enumeration e = cm.getContexts();
while ( e.hasMoreElements() ){
Context con = (Context) e.nextElement();
//how to get sessionManager?
int size = sessionMgr.getSessions().size();
}
===============================================
--- cmanolache@yahoo.com wrote:
> Hi,
>
> What you can do is use ContextManager.getContexts(),
> then for each context you can get its
> SessionManager.
>
>
> Costin
>
>
> On Sat, 8 Sep 2001, chiu ming luk wrote:
>
> > 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 currect
> > 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
>
__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com
Re: Number of active session in Tomcat instance
Posted by cm...@yahoo.com.
Hi,
What you can do is use ContextManager.getContexts(),
then for each context you can get its SessionManager.
Costin
On Sat, 8 Sep 2001, chiu ming luk wrote:
> 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 currect
> 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