Saturday, March 7, 2009

IBM Portal V6 people online statistics

First, on-line number of the problem and analysis
Servlet-based application is easy to statistics the number online, the system can easily monitor online users log in and log out of the state, thus the number of statistics. However, in the portlet container to statistics the number of words online, it is easy to confuse people. Portlet api try to study if portlet session used to monitor the function can not be resolved.
IBM Portal V6 are the portlet container and a common servlet container, in fact, portlet container at servlet containers set up at on the virtual
At each portlet configuration on a web. Xml to servlet configuration, of course, right yes portlet.xml of the portlet container current portlet configuration.
Analysis by the above example, be:
Servlet number = Portlet Container online online put the number of such online portlet container into question the number of questions servlet-line statistics on the number of questions, for solving the number of servlet-line on the much simpler problem, that is, write a listener, linked to the servlet container monitor the number of on-line.

The number of online statistics, has two ways to achieve: First, to achieve at portlet module; the second is subject to achieve.
Achieve at portlet module is loaded into the listener portlet's web.xml, the number of people online at the page portlet display.
In the subject to realize that the line shows the number of subject-related pages, such as in navigation, LOGO location on display and so on.
java Because of the two methods are put listener deployed, then the first to achieve Listener olinecount.java

package com.yds.portal.onlinecount.servlet; package com.yds.portal.onlinecount.servlet;

import java .io.PrintStream; import java. io.PrintStream;
import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener; import javax.servlet.http.HttpSessionListener;

public class SessionCounter public class SessionCounter
implements javax.servlet.http.HttpSessionListener implements javax.servlet.http.HttpSessionListener
{ (
/ / Definition of static variables to preserve the number of online
private static int activeSessions = 0; private static int activeSessions = 0;

public SessionCounter() public SessionCounter ()
{ (
} )

public void sessionCreated(javax.servlet.http.HttpSessionEvent arg0) public void sessionCreated (javax.servlet.http.HttpSessionEvent arg0)
{/ / If the number of sessions to create while online plus 1
activeSessions++; activeSessions + +;

} )

public void sessionDestroyed(javax.servlet.http.HttpSessionEvent arg0) public void sessionDestroyed (javax.servlet.http.HttpSessionEvent arg0)
{/ / Session was closed at the time, if the line number is greater than 0, minus one
if (activeSessions > 0) if (activeSessions> 0)
activeSessions--; activeSessions -;

} )
/ / Return the number of online
public static int getActiveSessions() public static int getActiveSessions ()
{ (
return activeSessions; return activeSessions;
} )

} )
Put this type of package ydsonlinecount.jar, used in different environments.

1) In the portlet loaded listener.
a. Create a new portlet project, named OnlineCount, put the above into ydsonlinecount.jar project WEB-INF \ lib directory.
b. listener configuration in web.xml.
Add in the web.xml file:


com.yds.portal.onlinecount.servlet.SessionCounter com.yds.portal.onlinecount.servlet.SessionCounter


c. In the jsp page in the introduction of import = "com.yds.portal.onlinecount.servlet.SessionCounter", and then add <% = SessionCounter.getActiveSessions ()%> you, here a direct call to listener methods to obtain the number of users.
d. packaged release.

2) Subject to deploy Listener
At the listener deployed to the subject, the put ydsonlinecount.jar are in fact deployed to the portal up for the use of topic. Deployment Listener wps.ear is to modify the web.xml, the application because the portal is wps.ear package.
a. put on the shared directory ydsonlinecount.jar. Packages put on this directory, the portal application can directly use the type of bag.
b. Monitor the deployment, it is necessary to guide wps.ear out to modify its web.xml, put the introduction of listener. Generally speaking, the subject with the skin can be directly deployed to wps.war, so that they take effect. But the listener must be re-deployed to take effect, if only directly modify the web.xml, are not entered into force listener.
Concrete steps can be reference links:
http://publib.boulder.ibm.com/infocenter/wpdoc/v6r0/index.jsp?topic=/com.ibm.wp.exp.doc/wps/dgn_dpycst.html
In accordance with the content of links to guide put out wps.ear package, modify web.xml, put a good listener configuration, and then folded back and update on wps.ear portal. JSP according to the subject at 1) the introduction of the method shows that the number online.

Three sum up
From the above we can see that because of portlet container and jsp are shared servlet container, portlet container on the number line are equal number of servlet-line, but just listening to your servlet. On the other hand, this is normal login / logout can be statistics, but for those directly turn off your browser's user, you must wait until the conversation time before the users has been calculated, the result will be to immediately and Statistics, then, we should also turn off the use of scripts to monitor page, visit the exit portal URL, which users instant statistics.