From portal-commits at lists.jboss.org Fri May 23 18:00:53 2008 Content-Type: multipart/mixed; boundary="===============3705336208958716780==" MIME-Version: 1.0 From: portal-commits at lists.jboss.org To: portal-commits at lists.jboss.org Subject: [portal-commits] JBoss Portal SVN: r10806 - in branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/users: event and 1 other directory. Date: Fri, 23 May 2008 18:00:52 -0400 Message-ID: --===============3705336208958716780== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: sviluppatorefico Date: 2008-05-23 18:00:51 -0400 (Fri, 23 May 2008) New Revision: 10806 Added: branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/= core/samples/users/event/PortalSessionEventListener.java branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/= core/samples/users/event/StatsListener.java Modified: branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/= core/samples/users/CurrentUsersPortlet.java branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/= core/samples/users/event/UserEventListener.java Log: added support for session and guest Modified: branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/= portal/core/samples/users/CurrentUsersPortlet.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal= /core/samples/users/CurrentUsersPortlet.java 2008-05-23 14:54:41 UTC (rev 1= 0805) +++ branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal= /core/samples/users/CurrentUsersPortlet.java 2008-05-23 22:00:51 UTC (rev 1= 0806) @@ -26,12 +26,12 @@ import org.jboss.portal.core.identity.UsersActivityStatsService; import org.jboss.portal.core.servlet.jsp.PortalJsp; import org.jboss.portal.core.servlet.jsp.taglib.context.DelegateContext; +import org.jboss.portlet.JBossPortlet; +import org.jboss.portlet.JBossRenderRequest; +import org.jboss.portlet.JBossRenderResponse; = -import javax.portlet.GenericPortlet; import javax.portlet.PortletException; import javax.portlet.PortletRequestDispatcher; -import javax.portlet.RenderRequest; -import javax.portlet.RenderResponse; import javax.portlet.UnavailableException; import java.io.IOException; import java.io.PrintWriter; @@ -39,52 +39,56 @@ = /** * Read the current users online and write them in output. - * + * = * @author Luca Stancapiano */ -public class CurrentUsersPortlet extends GenericPortlet -{ +public class CurrentUsersPortlet extends JBossPortlet { = - /** Logger */ - public static Logger log =3D Logger.getLogger(CurrentUsersPortlet.class= ); + /** Logger */ + public static Logger log =3D Logger.getLogger(CurrentUsersPortlet.class); = - protected void doView(RenderRequest rRequest, RenderResponse rResponse) - throws PortletException, IOException, UnavailableException - { - UsersActivityStatsService uass =3D (UsersActivityStatsService)this - .getPortletContext().getAttribute("UsersActivityStats"); + protected void doView(JBossRenderRequest rRequest, + JBossRenderResponse rResponse) throws PortletException, + IOException, UnavailableException { + UsersActivityStatsService uass =3D (UsersActivityStatsService) this + .getPortletContext().getAttribute("UsersActivityStats"); = - rResponse.setContentType("text/html"); - PrintWriter writer =3D rResponse.getWriter(); + rResponse.setContentType("text/html"); + PrintWriter writer =3D rResponse.getWriter(); = - //TODO: this is wrong - should pass period instead of current time -= actually it works by a coincedence... - Set users =3D uass.getActiveUsersNames(System.currentTimeMillis()); + long currentTime =3D System.currentTimeMillis(); = - if (users.size() =3D=3D 1) - { - DelegateContext ctx =3D new DelegateContext(); - ctx.put("USERS", users.toString()); - ctx.put("USERS_COUNT", Integer.toString(users.size())); - rRequest.setAttribute(PortalJsp.CTX_REQUEST, ctx); - PortletRequestDispatcher rd =3D getPortletContext().getRequestDis= patcher("/WEB-INF/jsp/users/oneUser.jsp"); - rd.include(rRequest, rResponse); - } - else if (users.size() > 1) - { - DelegateContext ctx =3D new DelegateContext(); - ctx.put("USERS", users.toString()); - ctx.put("USERS_COUNT", Integer.toString(users.size())); - rRequest.setAttribute(PortalJsp.CTX_REQUEST, ctx); - PortletRequestDispatcher rd =3D getPortletContext().getRequestDis= patcher("/WEB-INF/jsp/users/users.jsp"); - rd.include(rRequest, rResponse); - } - else - { - PortletRequestDispatcher rd =3D getPortletContext().getRequestDis= patcher("/WEB-INF/jsp/users/noUser.jsp"); - rd.include(rRequest, rResponse); - } + // TODO: this is wrong - should pass period instead of current time - + // actually it works by a coincedence... + Set users =3D uass.getActiveUsersNames(currentTime); = + int sessionCount =3D uass.getActiveSessionCount(currentTime); = - writer.close(); - } + int allLoggedSessions =3D uass.getUsersActivities(currentTime).size(); + + if (sessionCount =3D=3D 1) { + DelegateContext ctx =3D new DelegateContext(); + ctx.put("USERS", users.toString()); + ctx.put("USERS_COUNT", Integer.toString(sessionCount)); + rRequest.setAttribute(PortalJsp.CTX_REQUEST, ctx); + PortletRequestDispatcher rd =3D getPortletContext() + .getRequestDispatcher("/WEB-INF/jsp/users/oneUser.jsp"); + rd.include(rRequest, rResponse); + } else if (sessionCount > 1) { + DelegateContext ctx =3D new DelegateContext(); + ctx.put("USERS", users.toString()); + ctx.put("USERS_COUNT", Integer.toString(sessionCount)); + ctx.put("USERS_LOGGED_COUNT", Integer.toString(users.size())); + rRequest.setAttribute(PortalJsp.CTX_REQUEST, ctx); + PortletRequestDispatcher rd =3D getPortletContext() + .getRequestDispatcher("/WEB-INF/jsp/users/users.jsp"); + rd.include(rRequest, rResponse); + } else { + PortletRequestDispatcher rd =3D getPortletContext() + .getRequestDispatcher("/WEB-INF/jsp/users/noUser.jsp"); + rd.include(rRequest, rResponse); + } + + writer.close(); + } } Added: branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/por= tal/core/samples/users/event/PortalSessionEventListener.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal= /core/samples/users/event/PortalSessionEventListener.java = (rev 0) +++ branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal= /core/samples/users/event/PortalSessionEventListener.java 2008-05-23 22:00:= 51 UTC (rev 10806) @@ -0,0 +1,57 @@ +/*************************************************************************= ***** + * JBoss, a division of Red Hat = * + * Copyright 2006, Red Hat Middleware, LLC, and individual = * + * contributors as indicated by the @authors tag. See the = * + * copyright.txt in the distribution for a full listing of = * + * individual contributors. = * + * = * + * This is free software; you can redistribute it and/or modify it = * + * under the terms of the GNU Lesser General Public License as = * + * published by the Free Software Foundation; either version 2.1 of = * + * the License, or (at your option) any later version. = * + * = * + * This software is distributed in the hope that it will be useful, = * + * but WITHOUT ANY WARRANTY; without even the implied warranty of = * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU = * + * Lesser General Public License for more details. = * + * = * + * You should have received a copy of the GNU Lesser General Public = * + * License along with this software; if not, write to the Free = * + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA = * + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. = * + *************************************************************************= *****/ +package org.jboss.portal.core.samples.users.event; + +import org.jboss.portal.api.event.PortalEvent; +import org.jboss.portal.api.event.PortalEventContext; +import org.jboss.portal.api.session.event.PortalSessionEvent; +import org.jboss.portal.core.identity.UserActivity; + +/** + * @author Luca Stancapiano + * @version $Revision: 1.1 $ + */ +public class PortalSessionEventListener extends StatsListener +{ + + public void onEvent(PortalEventContext eventContext, PortalEvent event) + { + if (event instanceof PortalSessionEvent) + { + PortalSessionEvent portalEvent =3D (PortalSessionEvent) event; + UserActivity userActivity =3D null; + + if (portalEvent.getType() =3D=3D PortalSessionEvent.SESSION_CREAT= ED) + { + userActivity =3D new UserActivity(UserActivity.GUEST, eventCon= text.getPortalRuntimeContext().getSession() + .getId(), System.currentTimeMillis(), UserActivity.NAVIG= ATION); + } + else if (portalEvent.getType() =3D=3D PortalSessionEvent.SESSION_= DESTROYED) + { + userActivity =3D new UserActivity(UserActivity.GUEST, eventCon= text.getPortalRuntimeContext().getSession() + .getId(), System.currentTimeMillis(), UserActivity.EXIT); + } + getStatsService().registerActivity(userActivity); + } + } +} Added: branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/por= tal/core/samples/users/event/StatsListener.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal= /core/samples/users/event/StatsListener.java (rev 0) +++ branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal= /core/samples/users/event/StatsListener.java 2008-05-23 22:00:51 UTC (rev 1= 0806) @@ -0,0 +1,44 @@ +package org.jboss.portal.core.samples.users.event; + +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; + +import org.apache.log4j.Logger; +import org.jboss.mx.util.MBeanProxy; +import org.jboss.mx.util.MBeanProxyCreationException; +import org.jboss.mx.util.MBeanServerLocator; +import org.jboss.portal.api.event.PortalEventListener; +import org.jboss.portal.core.identity.UsersActivityStatsService; + +public abstract class StatsListener implements PortalEventListener +{ + + /** Our logger. */ + private static final Logger log =3D Logger.getLogger(StatsListener.clas= s); + + private UsersActivityStatsService activityService; + + public UsersActivityStatsService getStatsService() + { + if (activityService =3D=3D null) + { + try + { + MBeanServer mbeanServer =3D MBeanServerLocator.locateJBoss(); + activityService =3D (UsersActivityStatsService) MBeanProxy.get= (UsersActivityStatsService.class, + new ObjectName("portal:service=3DModule,type=3DUsersActi= vityStatsService"), mbeanServer); + } + catch (MBeanProxyCreationException e) + { + log.error("could not obtain a proxy for User Activity Statisti= cs Service", e); + } + catch (MalformedObjectNameException e2) + { + log.error("object name to obtain User Activity Statistics Serv= ice is wrong", e2); + } + } + return activityService; + } + +} Modified: branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/= portal/core/samples/users/event/UserEventListener.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal= /core/samples/users/event/UserEventListener.java 2008-05-23 14:54:41 UTC (r= ev 10805) +++ branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal= /core/samples/users/event/UserEventListener.java 2008-05-23 22:00:51 UTC (r= ev 10806) @@ -22,84 +22,36 @@ *************************************************************************= *****/ package org.jboss.portal.core.samples.users.event; = -import org.apache.log4j.Logger; -import org.jboss.mx.util.MBeanProxy; -import org.jboss.mx.util.MBeanProxyCreationException; -import org.jboss.mx.util.MBeanServerLocator; import org.jboss.portal.api.event.PortalEvent; import org.jboss.portal.api.event.PortalEventContext; -import org.jboss.portal.api.event.PortalEventListener; import org.jboss.portal.api.user.event.UserAuthenticationEvent; import org.jboss.portal.core.identity.UserActivity; -import org.jboss.portal.core.identity.UsersActivityStatsService; = -import javax.management.MBeanServer; -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; - /** * @author Luca Stancapiano * @version $Revision: 1.1 $ */ -public class UserEventListener implements PortalEventListener +public class UserEventListener extends StatsListener { = - /** Our logger. */ - private static final Logger log =3D Logger - .getLogger(UserEventListener.class); - - private UsersActivityStatsService activityService; - - public UsersActivityStatsService getStatsService() - { - if (activityService =3D=3D null) - { - try - { - MBeanServer mbeanServer =3D MBeanServerLocator.locateJBoss(); - activityService =3D (UsersActivityStatsService)MBeanProxy - .get( - UsersActivityStatsService.class, - new ObjectName( - "portal:service=3DModule,type=3DUsersActivityStatsSer= vice"), - mbeanServer); - } - catch (MBeanProxyCreationException e) - { - log - .error( - "could not obtain a proxy for User Activity Statistics S= ervice", - e); - } - catch (MalformedObjectNameException e2) - { - log - .error( - "object name to obtain User Activity Statistics Service = is wrong", - e2); - } - } - return activityService; - } - public void onEvent(PortalEventContext eventContext, PortalEvent event) { if (event instanceof UserAuthenticationEvent) { = - UserAuthenticationEvent userEvent =3D (UserAuthenticationEvent)ev= ent; + UserAuthenticationEvent userEvent =3D (UserAuthenticationEvent) e= vent; = UserActivity userActivity =3D null; = if (userEvent.getType() =3D=3D UserAuthenticationEvent.SIGN_IN) { - userActivity =3D new UserActivity(userEvent.getUserId(), System - .currentTimeMillis(), UserActivity.NAVIGATION); + userActivity =3D new UserActivity(userEvent.getUserId(), event= Context.getPortalRuntimeContext().getSession() + .getId(), System.currentTimeMillis(), UserActivity.NAVIG= ATION); } else if (userEvent.getType() =3D=3D UserAuthenticationEvent.SIGN_= OUT) { - userActivity =3D new UserActivity(userEvent.getUserId(), System - .currentTimeMillis(), UserActivity.SIGN_OUT); + userActivity =3D new UserActivity(userEvent.getUserId(), event= Context.getPortalRuntimeContext().getSession() + .getId(), System.currentTimeMillis(), UserActivity.EXIT); } getStatsService().registerActivity(userActivity); } --===============3705336208958716780==--