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
===================================================================
---
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 10805)
+++
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 10806)
@@ -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 <a href="mailto:jedim@vige.it">Luca Stancapiano</a>
*/
-public class CurrentUsersPortlet extends GenericPortlet
-{
+public class CurrentUsersPortlet extends JBossPortlet {
- /** Logger */
- public static Logger log = Logger.getLogger(CurrentUsersPortlet.class);
+ /** Logger */
+ public static Logger log = Logger.getLogger(CurrentUsersPortlet.class);
- protected void doView(RenderRequest rRequest, RenderResponse rResponse)
- throws PortletException, IOException, UnavailableException
- {
- UsersActivityStatsService uass = (UsersActivityStatsService)this
- .getPortletContext().getAttribute("UsersActivityStats");
+ protected void doView(JBossRenderRequest rRequest,
+ JBossRenderResponse rResponse) throws PortletException,
+ IOException, UnavailableException {
+ UsersActivityStatsService uass = (UsersActivityStatsService) this
+ .getPortletContext().getAttribute("UsersActivityStats");
- rResponse.setContentType("text/html");
- PrintWriter writer = rResponse.getWriter();
+ rResponse.setContentType("text/html");
+ PrintWriter writer = rResponse.getWriter();
- //TODO: this is wrong - should pass period instead of current time - actually it
works by a coincedence...
- Set users = uass.getActiveUsersNames(System.currentTimeMillis());
+ long currentTime = System.currentTimeMillis();
- if (users.size() == 1)
- {
- DelegateContext ctx = new DelegateContext();
- ctx.put("USERS", users.toString());
- ctx.put("USERS_COUNT", Integer.toString(users.size()));
- rRequest.setAttribute(PortalJsp.CTX_REQUEST, ctx);
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/users/oneUser.jsp");
- rd.include(rRequest, rResponse);
- }
- else if (users.size() > 1)
- {
- DelegateContext ctx = new DelegateContext();
- ctx.put("USERS", users.toString());
- ctx.put("USERS_COUNT", Integer.toString(users.size()));
- rRequest.setAttribute(PortalJsp.CTX_REQUEST, ctx);
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/users/users.jsp");
- rd.include(rRequest, rResponse);
- }
- else
- {
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/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 = uass.getActiveUsersNames(currentTime);
+ int sessionCount = uass.getActiveSessionCount(currentTime);
- writer.close();
- }
+ int allLoggedSessions = uass.getUsersActivities(currentTime).size();
+
+ if (sessionCount == 1) {
+ DelegateContext ctx = new DelegateContext();
+ ctx.put("USERS", users.toString());
+ ctx.put("USERS_COUNT", Integer.toString(sessionCount));
+ rRequest.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ PortletRequestDispatcher rd = getPortletContext()
+ .getRequestDispatcher("/WEB-INF/jsp/users/oneUser.jsp");
+ rd.include(rRequest, rResponse);
+ } else if (sessionCount > 1) {
+ DelegateContext ctx = 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 = getPortletContext()
+ .getRequestDispatcher("/WEB-INF/jsp/users/users.jsp");
+ rd.include(rRequest, rResponse);
+ } else {
+ PortletRequestDispatcher rd = 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/portal/core/samples/users/event/PortalSessionEventListener.java
===================================================================
---
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 <a href="mailto:jedim@vige.it">Luca Stancapiano</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortalSessionEventListener extends StatsListener
+{
+
+ public void onEvent(PortalEventContext eventContext, PortalEvent event)
+ {
+ if (event instanceof PortalSessionEvent)
+ {
+ PortalSessionEvent portalEvent = (PortalSessionEvent) event;
+ UserActivity userActivity = null;
+
+ if (portalEvent.getType() == PortalSessionEvent.SESSION_CREATED)
+ {
+ userActivity = new UserActivity(UserActivity.GUEST,
eventContext.getPortalRuntimeContext().getSession()
+ .getId(), System.currentTimeMillis(), UserActivity.NAVIGATION);
+ }
+ else if (portalEvent.getType() == PortalSessionEvent.SESSION_DESTROYED)
+ {
+ userActivity = new UserActivity(UserActivity.GUEST,
eventContext.getPortalRuntimeContext().getSession()
+ .getId(), System.currentTimeMillis(), UserActivity.EXIT);
+ }
+ getStatsService().registerActivity(userActivity);
+ }
+ }
+}
Added:
branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/users/event/StatsListener.java
===================================================================
---
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 10806)
@@ -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 = Logger.getLogger(StatsListener.class);
+
+ private UsersActivityStatsService activityService;
+
+ public UsersActivityStatsService getStatsService()
+ {
+ if (activityService == null)
+ {
+ try
+ {
+ MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
+ activityService = (UsersActivityStatsService)
MBeanProxy.get(UsersActivityStatsService.class,
+ new
ObjectName("portal:service=Module,type=UsersActivityStatsService"),
mbeanServer);
+ }
+ catch (MBeanProxyCreationException e)
+ {
+ log.error("could not obtain a proxy for User Activity Statistics
Service", e);
+ }
+ catch (MalformedObjectNameException e2)
+ {
+ log.error("object name to obtain User Activity Statistics Service 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
===================================================================
---
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 (rev 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 (rev 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 <a href="mailto:jedim@vige.it">Luca Stancapiano</a>
* @version $Revision: 1.1 $
*/
-public class UserEventListener implements PortalEventListener
+public class UserEventListener extends StatsListener
{
- /** Our logger. */
- private static final Logger log = Logger
- .getLogger(UserEventListener.class);
-
- private UsersActivityStatsService activityService;
-
- public UsersActivityStatsService getStatsService()
- {
- if (activityService == null)
- {
- try
- {
- MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
- activityService = (UsersActivityStatsService)MBeanProxy
- .get(
- UsersActivityStatsService.class,
- new ObjectName(
- "portal:service=Module,type=UsersActivityStatsService"),
- mbeanServer);
- }
- catch (MBeanProxyCreationException e)
- {
- log
- .error(
- "could not obtain a proxy for User Activity Statistics
Service",
- 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 = (UserAuthenticationEvent)event;
+ UserAuthenticationEvent userEvent = (UserAuthenticationEvent) event;
UserActivity userActivity = null;
if (userEvent.getType() == UserAuthenticationEvent.SIGN_IN)
{
- userActivity = new UserActivity(userEvent.getUserId(), System
- .currentTimeMillis(), UserActivity.NAVIGATION);
+ userActivity = new UserActivity(userEvent.getUserId(),
eventContext.getPortalRuntimeContext().getSession()
+ .getId(), System.currentTimeMillis(), UserActivity.NAVIGATION);
}
else if (userEvent.getType() == UserAuthenticationEvent.SIGN_OUT)
{
- userActivity = new UserActivity(userEvent.getUserId(), System
- .currentTimeMillis(), UserActivity.SIGN_OUT);
+ userActivity = new UserActivity(userEvent.getUserId(),
eventContext.getPortalRuntimeContext().getSession()
+ .getId(), System.currentTimeMillis(), UserActivity.EXIT);
}
getStatsService().registerActivity(userActivity);
}