Author: sviluppatorefico
Date: 2008-05-18 07:02:55 -0400 (Sun, 18 May 2008)
New Revision: 10774
Modified:
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/UserEventListener.java
Log:
this listener catches events about create and destroy of a portal session
Modified:
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/UserEventListener.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/UserEventListener.java 2008-05-18
11:01:48 UTC (rev 10773)
+++
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/UserEventListener.java 2008-05-18
11:02:55 UTC (rev 10774)
@@ -22,86 +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);
+ public void onEvent(PortalEventContext eventContext, PortalEvent event) {
+ if (event instanceof UserAuthenticationEvent) {
- private UsersActivityStatsService activityService;
+ UserAuthenticationEvent userEvent = (UserAuthenticationEvent) event;
- 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;
- }
+ UserActivity userActivity = null;
- public void onEvent(PortalEventContext eventContext, PortalEvent event)
- {
- if (event instanceof UserAuthenticationEvent)
- {
-
- UserAuthenticationEvent userEvent = (UserAuthenticationEvent)event;
-
- UserActivity userActivity = null;
-
- if (userEvent.getType() == UserAuthenticationEvent.SIGN_IN)
- {
- userActivity = new UserActivity(userEvent.getUserId(), System
- .currentTimeMillis(), UserActivity.NAVIGATION);
- }
- else if (userEvent.getType() == UserAuthenticationEvent.SIGN_OUT)
- {
- userActivity = new UserActivity(userEvent.getUserId(), System
- .currentTimeMillis(), UserActivity.SIGN_OUT);
- }
- getStatsService().registerActivity(userActivity);
- }
- }
+ if (userEvent.getType() == UserAuthenticationEvent.SIGN_IN) {
+ 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(),
+ eventContext.getPortalRuntimeContext().getSession().getId()
+ , System.currentTimeMillis(),
+ UserActivity.EXIT);
+ }
+ getStatsService().registerActivity(userActivity);
+ }
+ }
}
Show replies by date