Author: sviluppatorefico
Date: 2008-05-23 18:02:29 -0400 (Fri, 23 May 2008)
New Revision: 10807
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/identity/UserActivity.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsService.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsServiceImpl.java
Log:
added support for session and guest
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/identity/UserActivity.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/identity/UserActivity.java 2008-05-23
22:00:51 UTC (rev 10806)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/identity/UserActivity.java 2008-05-23
22:02:29 UTC (rev 10807)
@@ -34,20 +34,24 @@
public static final int NAVIGATION = 0;
- public static final int SIGN_OUT = 1;
+ public static final int EXIT = 1;
private String id;
+ private String sessionId;
+
private long timestamp;
private final int type;
+ public final static String GUEST = "guest";
+
private UserActivity()
{
this.type = NAVIGATION;
}
- public UserActivity(String id, long timestamp, int type)
+ public UserActivity(String id, String sessionId, long timestamp, int type)
{
if (id == null)
{
@@ -55,6 +59,7 @@
}
this.id = id;
+ this.sessionId = sessionId;
this.timestamp = timestamp;
this.type = type;
}
@@ -65,7 +70,8 @@
{
throw new IllegalArgumentException("Id (notification message) cannot be
null");
}
- this.id = notification.getMessage();
+ this.id = notification.getMessage().substring(0,
notification.getMessage().indexOf("_"));
+ this.sessionId =
notification.getMessage().substring(notification.getMessage().indexOf("_"));
this.timestamp = notification.getTimeStamp();
this.type = Integer.parseInt(notification.getType());
}
@@ -75,6 +81,11 @@
return id;
}
+ public String getSessionId()
+ {
+ return sessionId;
+ }
+
public long getTimestamp()
{
return timestamp;
@@ -85,7 +96,6 @@
return type;
}
-
public boolean equals(Object o)
{
if (this == o)
@@ -97,9 +107,9 @@
return false;
}
- UserActivity that = (UserActivity)o;
+ UserActivity that = (UserActivity) o;
- if (!id.equals(that.id))
+ if (!id.equals(that.id) || !sessionId.equals(that.sessionId))
{
return false;
}
@@ -110,7 +120,7 @@
public int hashCode()
{
int result;
- result = id.hashCode();
+ result = id.hashCode() + sessionId.hashCode();
return result;
}
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsService.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsService.java 2008-05-23
22:00:51 UTC (rev 10806)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsService.java 2008-05-23
22:02:29 UTC (rev 10807)
@@ -33,6 +33,8 @@
public Set getActiveUsersIds(long period);
+ public int getActiveSessionCount(long period);
+
public Set getActiveUsersNames(long period);
public Set getUsersActivities(long period);
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsServiceImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsServiceImpl.java 2008-05-23
22:00:51 UTC (rev 10806)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsServiceImpl.java 2008-05-23
22:02:29 UTC (rev 10807)
@@ -1,24 +1,24 @@
/*
-* 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.
-*/
+ * 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.identity;
@@ -42,16 +42,20 @@
import java.util.Set;
/**
- * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
+ * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
+ * com">Boleslaw Dawidowicz</a>
* @author <a href="mailto:jedim@vige.it">Luca Stancapiano</a>
* @version $Revision$
*/
-public class UsersActivityStatsServiceImpl extends AbstractJBossService implements
UsersActivityStatsService, NotificationListener
+public class UsersActivityStatsServiceImpl extends AbstractJBossService
+ implements
+ UsersActivityStatsService,
+ NotificationListener
{
/** Our logger. */
private static final Logger log =
Logger.getLogger(UsersActivityStatsServiceImpl.class);
- //TODO: some value just to begin - find some good default
+ // TODO: some value just to begin - find some good default
private int userTrackerThreadsNumber = 10;
private int updaterThreadsNumber = 1;
@@ -86,7 +90,8 @@
updaterExecutor = Executors.newScheduledThreadPool(getUpdaterThreadsNumber());
- updaterExecutor.scheduleWithFixedDelay(new Updater(activityQueue),
getUpdaterInterval(), getUpdaterInterval(), TimeUnit.MILLISECONDS);
+ updaterExecutor.scheduleWithFixedDelay(new Updater(activityQueue),
getUpdaterInterval(), getUpdaterInterval(),
+ TimeUnit.MILLISECONDS);
if (activityBroadcasterName != null)
{
@@ -97,7 +102,6 @@
addNotificationListener(this, null, null);
}
-
}
protected void stopService() throws Exception
@@ -114,23 +118,39 @@
Set results = new HashSet();
for (Iterator iterator = activityResults.iterator(); iterator.hasNext();)
{
- UserActivity ua = (UserActivity)iterator.next();
- if (currentTime - ua.getTimestamp() < period)
+ UserActivity ua = (UserActivity) iterator.next();
+ if (currentTime - ua.getTimestamp() < period &&
!ua.getId().equals(UserActivity.GUEST))
{
- results.add(ua.getId());
+ results.add(ua.getSessionId());
}
}
return results;
}
+ public int getActiveSessionCount(long period)
+ {
+ long currentTime = System.currentTimeMillis();
+
+ int results = 0;
+ for (Iterator iterator = activityResults.iterator(); iterator.hasNext();)
+ {
+ UserActivity ua = (UserActivity) iterator.next();
+ if (currentTime - ua.getTimestamp() < period &&
ua.getId().equals(UserActivity.GUEST))
+ {
+ results++;
+ }
+ }
+ return results;
+ }
+
public Set getActiveUsersNames(long period)
{
long currentTime = System.currentTimeMillis();
Set results = new HashSet();
for (Iterator iterator = activityResults.iterator(); iterator.hasNext();)
{
- UserActivity ua = (UserActivity)iterator.next();
- if (currentTime - ua.getTimestamp() < period)
+ UserActivity ua = (UserActivity) iterator.next();
+ if (currentTime - ua.getTimestamp() < period &&
!ua.getId().equals(UserActivity.GUEST))
{
results.add(ua.getId());
}
@@ -144,7 +164,7 @@
Set results = new HashSet();
for (Iterator iterator = activityResults.iterator(); iterator.hasNext();)
{
- UserActivity ua = (UserActivity)iterator.next();
+ UserActivity ua = (UserActivity) iterator.next();
if (currentTime - ua.getTimestamp() < period)
{
results.add(ua);
@@ -157,21 +177,17 @@
{
try
{
- Notification notification = new
Notification(Integer.toString(userActivity.getType()),
- this.getServiceName(),
- userActivity.getTimestamp(),
- userActivity.getTimestamp(),
- userActivity.getId());
+ Notification notification = new
Notification(Integer.toString(userActivity.getType()), this.getServiceName(),
+ userActivity.getTimestamp(), userActivity.getTimestamp(),
userActivity.getId() + "_"
+ + userActivity.getSessionId());
-
if (activityBroadcasterName != null)
{
log.debug("Broadcasting user activity notification ");
- server.invoke(new ObjectName(activityBroadcasterName),
- "sendNotification",
- new Object[]{notification},
- new String[]{Notification.class.getName()});
+ server.invoke(new ObjectName(activityBroadcasterName),
"sendNotification", new Object[]
+ {notification}, new String[]
+ {Notification.class.getName()});
}
else
{
@@ -185,7 +201,6 @@
log.error("Failed to send user activity notification: ", e);
}
-
}
public void handleNotification(Notification notification, Object object)
@@ -213,7 +228,6 @@
userTrackerExecutor.execute(task);
}
-
public int getUserTrackerThreadsNumber()
{
return userTrackerThreadsNumber;
@@ -283,7 +297,7 @@
this.activityQueue = activityQueue;
}
- //never run
+ // never run
private Updater()
{
this.activityQueue = null;
@@ -297,10 +311,10 @@
while (!activityQueue.isEmpty())
{
- UserActivity activity = (UserActivity)activityQueue.poll();
+ UserActivity activity = (UserActivity) activityQueue.poll();
if (activity != null && ((currentTime - activity.getTimestamp()) <
activityTimeout))
{
- if (activity.getType() != UserActivity.SIGN_OUT)
+ if (activity.getType() != UserActivity.EXIT)
{
stillActive.add(activity);
}
@@ -316,6 +330,4 @@
}
}
-
}
-