Author: sviluppatorefico
Date: 2008-05-18 07:06:15 -0400 (Sun, 18 May 2008)
New Revision: 10776
Added:
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/PortalSessionEventListener.java
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/StatsListener.java
Log:
this listeners catches create and destroy of a portal session
Added:
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/PortalSessionEventListener.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/PortalSessionEventListener.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/PortalSessionEventListener.java 2008-05-18
11:06:15 UTC (rev 10776)
@@ -0,0 +1,60 @@
+/******************************************************************************
+ * 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.event.PortalEventListener;
+import org.jboss.portal.api.session.event.PortalSessionEvent;
+import org.jboss.portal.api.user.event.UserAuthenticationEvent;
+import org.jboss.portal.core.identity.UserActivity;
+
+import EDU.oswego.cs.dl.util.concurrent.SynchronizedLong;
+
+/**
+ * @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() == portalEvent.SESSION_CREATED)
+ {
+ userActivity = new UserActivity(UserActivity.GUEST,
+ eventContext.getPortalRuntimeContext().getSession().getId(), System
+ .currentTimeMillis(), UserActivity.NAVIGATION);
+ }
+ else if (portalEvent.getType() == portalEvent.SESSION_DESTROYED)
+ {
+ userActivity = new UserActivity(UserActivity.GUEST,
+ eventContext.getPortalRuntimeContext().getSession().getId(), System
+ .currentTimeMillis(), UserActivity.EXIT);
+ }
+ getStatsService().registerActivity(userActivity);
+ }
+ }
+}
Property changes on:
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/PortalSessionEventListener.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/StatsListener.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/StatsListener.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/StatsListener.java 2008-05-18
11:06:15 UTC (rev 10776)
@@ -0,0 +1,46 @@
+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;
+ }
+
+}