On 1/6/11 6:07 PM, Ziggy wrote: > I was looking at the code for the Tomcat Manager application to try and find > out how it is determining whether a webapp/context is running and how many > sesions are active. Looking at the code i think it uses these two methods > > Context.getAvailalbe() //check if available > Context.getManager().findSessions().length // Number of sessions. > > Here is the relevant function > > protected void list(PrintWriter writer) { > > if (debug >= 1) > log("list: Listing contexts for virtual host '" + > host.getName() + "'"); > > writer.println(sm.getString("managerServlet.listed", > host.getName())); > Container[] contexts = host.findChildren(); > for (int i = 0; i < contexts.length; i++) { > Context context = (Context) contexts[i]; > String displayPath = context.getPath(); > if( displayPath.equals("") ) > displayPath = "/"; > if (context != null ) { > if (context.getAvailable()) { > writer.println(sm.getString("managerServlet.listitem", > displayPath, > "running", > "" + > context.getManager().findSessions().length, > context.getDocBase())); > } else { > writer.println(sm.getString("managerServlet.listitem", > displayPath, > "stopped", > "0", > context.getDocBase())); > } > } > } > } > > I was looking at the above for the above information as i am working on a > client tool that tries to find out this exact information. The tool i am > using connects to Tomcat via JMX but i am not sure if i can get the same > information via JMX. Can i access the Context class? or is there any other > way (Mbeans?) i can check if a context is running via JMX?
Connect to a Tomcat instance using JConsole and look for the 'Manager' objects. Catalina:type=Manager,path=/app01,host=localhost There's an attribute 'activeSessions'. p
0x62590808.asc
Description: application/pgp-keys
signature.asc
Description: OpenPGP digital signature