Author: sviluppatorefico
Date: 2008-05-20 18:12:48 -0400 (Tue, 20 May 2008)
New Revision: 10787
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UserActivity.java
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsService.java
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsServiceImpl.java
Log:
reformatted using jboss formatter for eclipse
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UserActivity.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UserActivity.java 2008-05-20
22:10:24 UTC (rev 10786)
+++
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UserActivity.java 2008-05-20
22:12:48 UTC (rev 10787)
@@ -43,7 +43,7 @@
private long timestamp;
private final int type;
-
+
public final static String GUEST = "guest";
private UserActivity()
@@ -96,7 +96,6 @@
return type;
}
-
public boolean equals(Object o)
{
if (this == o)
@@ -108,7 +107,7 @@
return false;
}
- UserActivity that = (UserActivity)o;
+ UserActivity that = (UserActivity) o;
if (!id.equals(that.id) || !sessionId.equals(that.sessionId))
{
@@ -121,7 +120,7 @@
public int hashCode()
{
int result;
- result = id.hashCode()+sessionId.hashCode();
+ result = id.hashCode() + sessionId.hashCode();
return result;
}
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsService.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsService.java 2008-05-20
22:10:24 UTC (rev 10786)
+++
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsService.java 2008-05-20
22:12:48 UTC (rev 10787)
@@ -32,7 +32,7 @@
{
public Set getActiveUsersIds(long period);
-
+
public int getActiveSessionCount(long period);
public Set getActiveUsersNames(long period);
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsServiceImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsServiceImpl.java 2008-05-20
22:10:24 UTC (rev 10786)
+++
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsServiceImpl.java 2008-05-20
22:12:48 UTC (rev 10787)
@@ -48,243 +48,286 @@
* @version $Revision$
*/
public class UsersActivityStatsServiceImpl extends AbstractJBossService
- implements UsersActivityStatsService, NotificationListener {
- /** Our logger. */
- private static final Logger log = Logger
- .getLogger(UsersActivityStatsServiceImpl.class);
+ implements
+ UsersActivityStatsService,
+ NotificationListener
+{
+ /** Our logger. */
+ private static final Logger log =
Logger.getLogger(UsersActivityStatsServiceImpl.class);
- // TODO: some value just to begin - find some good default
- private int userTrackerThreadsNumber = 10;
+ // TODO: some value just to begin - find some good default
+ private int userTrackerThreadsNumber = 10;
- private int updaterThreadsNumber = 1;
+ private int updaterThreadsNumber = 1;
- private int updaterInterval = 1000;
+ private int updaterInterval = 1000;
- private int activityQueueLimit = 1000;
+ private int activityQueueLimit = 1000;
- private long activityTimeout = 1800000;
+ private long activityTimeout = 1800000;
- private Executor userTrackerExecutor;
+ private Executor userTrackerExecutor;
- private ScheduledExecutorService updaterExecutor;
+ private ScheduledExecutorService updaterExecutor;
- private Queue activityQueue;
+ private Queue activityQueue;
- private volatile Set activityResults = new HashSet();
+ private volatile Set activityResults = new HashSet();
- private String activityBroadcasterName;
+ private String activityBroadcasterName;
- public UsersActivityStatsServiceImpl() {
- }
+ public UsersActivityStatsServiceImpl()
+ {
+ }
- protected void startService() throws Exception {
- super.startService();
+ protected void startService() throws Exception
+ {
+ super.startService();
- activityQueue = new LinkedBlockingQueue(getActivityQueueLimit());
+ activityQueue = new LinkedBlockingQueue(getActivityQueueLimit());
- userTrackerExecutor = Executors
- .newFixedThreadPool(getUserTrackerThreadsNumber());
+ userTrackerExecutor = Executors.newFixedThreadPool(getUserTrackerThreadsNumber());
- updaterExecutor = Executors
- .newScheduledThreadPool(getUpdaterThreadsNumber());
+ 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) {
- server.addNotificationListener(new ObjectName(
- activityBroadcasterName), this, null, null);
- } else {
- addNotificationListener(this, null, null);
- }
+ if (activityBroadcasterName != null)
+ {
+ server.addNotificationListener(new ObjectName(activityBroadcasterName), this,
null, null);
+ }
+ else
+ {
+ addNotificationListener(this, null, null);
+ }
- }
+ }
- protected void stopService() throws Exception {
- super.stopService();
+ protected void stopService() throws Exception
+ {
+ super.stopService();
- // /TODO: stop all the threads
- }
+ // /TODO: stop all the threads
+ }
- public Set getActiveUsersIds(long period) {
- long currentTime = System.currentTimeMillis();
+ public Set getActiveUsersIds(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
- && !ua.getId().equals(UserActivity.GUEST)) {
- results.add(ua.getSessionId());
- }
- }
- return results;
- }
+ Set results = new HashSet();
+ for (Iterator iterator = activityResults.iterator(); iterator.hasNext();)
+ {
+ UserActivity ua = (UserActivity) iterator.next();
+ if (currentTime - ua.getTimestamp() < period &&
!ua.getId().equals(UserActivity.GUEST))
+ {
+ results.add(ua.getSessionId());
+ }
+ }
+ return results;
+ }
- public int getActiveSessionCount(long period) {
- long currentTime = System.currentTimeMillis();
+ 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;
- }
+ 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
- && !ua.getId().equals(UserActivity.GUEST)) {
- results.add(ua.getId());
- }
- }
- 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 &&
!ua.getId().equals(UserActivity.GUEST))
+ {
+ results.add(ua.getId());
+ }
+ }
+ return results;
+ }
- public Set getUsersActivities(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) {
- results.add(ua);
- }
- }
- return results;
- }
+ public Set getUsersActivities(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)
+ {
+ results.add(ua);
+ }
+ }
+ return results;
+ }
- public void registerActivity(final UserActivity userActivity) {
- try {
- Notification notification = new Notification(Integer
- .toString(userActivity.getType()), this.getServiceName(),
- userActivity.getTimestamp(), userActivity.getTimestamp(),
- userActivity.getId() + "_" + userActivity.getSessionId());
+ public void registerActivity(final UserActivity userActivity)
+ {
+ try
+ {
+ 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 ");
+ if (activityBroadcasterName != null)
+ {
+ log.debug("Broadcasting user activity notification ");
- server.invoke(new ObjectName(activityBroadcasterName),
- "sendNotification", new Object[] { notification },
- new String[] { Notification.class.getName() });
- } else {
- log.debug("Sending local user activity notification ");
- sendNotification(notification);
- }
+ server.invoke(new ObjectName(activityBroadcasterName),
"sendNotification", new Object[]
+ {notification}, new String[]
+ {Notification.class.getName()});
+ }
+ else
+ {
+ log.debug("Sending local user activity notification ");
+ sendNotification(notification);
+ }
- } catch (Exception e) {
- log.error("Failed to send user activity notification: ", e);
- }
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to send user activity notification: ", e);
+ }
- }
+ }
- public void handleNotification(Notification notification, Object object) {
- log.debug("Handling user activity notification ");
- final UserActivity ac = new UserActivity(notification);
+ public void handleNotification(Notification notification, Object object)
+ {
+ log.debug("Handling user activity notification ");
+ final UserActivity ac = new UserActivity(notification);
- FutureTask task = new FutureTask(new Callable() {
- public Object call() throws Exception {
+ FutureTask task = new FutureTask(new Callable()
+ {
+ public Object call() throws Exception
+ {
- boolean success = activityQueue.offer(ac);
- if (log.isTraceEnabled()) {
- if (!success) {
- log
- .trace("Failed track user activity - activityQueue is full ");
- }
- }
- return null;
- }
- });
+ boolean success = activityQueue.offer(ac);
+ if (log.isTraceEnabled())
+ {
+ if (!success)
+ {
+ log.trace("Failed track user activity - activityQueue is full
");
+ }
+ }
+ return null;
+ }
+ });
- userTrackerExecutor.execute(task);
- }
+ userTrackerExecutor.execute(task);
+ }
- public int getUserTrackerThreadsNumber() {
- return userTrackerThreadsNumber;
- }
+ public int getUserTrackerThreadsNumber()
+ {
+ return userTrackerThreadsNumber;
+ }
- public void setUserTrackerThreadsNumber(int userTrackerThreadsNumber) {
- this.userTrackerThreadsNumber = userTrackerThreadsNumber;
- }
+ public void setUserTrackerThreadsNumber(int userTrackerThreadsNumber)
+ {
+ this.userTrackerThreadsNumber = userTrackerThreadsNumber;
+ }
- public int getUpdaterThreadsNumber() {
- return updaterThreadsNumber;
- }
+ public int getUpdaterThreadsNumber()
+ {
+ return updaterThreadsNumber;
+ }
- public void setUpdaterThreadsNumber(int updaterThreadsNumber) {
- this.updaterThreadsNumber = updaterThreadsNumber;
- }
+ public void setUpdaterThreadsNumber(int updaterThreadsNumber)
+ {
+ this.updaterThreadsNumber = updaterThreadsNumber;
+ }
- public int getUpdaterInterval() {
- return updaterInterval;
- }
+ public int getUpdaterInterval()
+ {
+ return updaterInterval;
+ }
- public void setUpdaterInterval(int updaterInterval) {
- this.updaterInterval = updaterInterval;
- }
+ public void setUpdaterInterval(int updaterInterval)
+ {
+ this.updaterInterval = updaterInterval;
+ }
- public int getActivityQueueLimit() {
- return activityQueueLimit;
- }
+ public int getActivityQueueLimit()
+ {
+ return activityQueueLimit;
+ }
- public void setActivityQueueLimit(int activityQueueLimit) {
- this.activityQueueLimit = activityQueueLimit;
- }
+ public void setActivityQueueLimit(int activityQueueLimit)
+ {
+ this.activityQueueLimit = activityQueueLimit;
+ }
- public long getActivityTimeout() {
- return activityTimeout;
- }
+ public long getActivityTimeout()
+ {
+ return activityTimeout;
+ }
- public void setActivityTimeout(long activityTimeout) {
- this.activityTimeout = activityTimeout;
- }
+ public void setActivityTimeout(long activityTimeout)
+ {
+ this.activityTimeout = activityTimeout;
+ }
- public String getActivityBroadcasterName() {
- return activityBroadcasterName;
- }
+ public String getActivityBroadcasterName()
+ {
+ return activityBroadcasterName;
+ }
- public void setActivityBroadcasterName(String activityBroadcasterName) {
- this.activityBroadcasterName = activityBroadcasterName;
- }
+ public void setActivityBroadcasterName(String activityBroadcasterName)
+ {
+ this.activityBroadcasterName = activityBroadcasterName;
+ }
- private class Updater implements Runnable {
- private final Queue activityQueue;
+ private class Updater implements Runnable
+ {
+ private final Queue activityQueue;
- public Updater(Queue activityQueue) {
- this.activityQueue = activityQueue;
- }
+ public Updater(Queue activityQueue)
+ {
+ this.activityQueue = activityQueue;
+ }
- // never run
- private Updater() {
- this.activityQueue = null;
- }
+ // never run
+ private Updater()
+ {
+ this.activityQueue = null;
+ }
- public void run() {
- long currentTime = System.currentTimeMillis();
+ public void run()
+ {
+ long currentTime = System.currentTimeMillis();
- Set stillActive = getUsersActivities(activityTimeout);
+ Set stillActive = getUsersActivities(activityTimeout);
- while (!activityQueue.isEmpty()) {
- UserActivity activity = (UserActivity) activityQueue.poll();
- if (activity != null
- && ((currentTime - activity.getTimestamp()) < activityTimeout)) {
- if (activity.getType() != UserActivity.EXIT) {
- stillActive.add(activity);
- } else {
- stillActive.remove(activity);
- }
- }
- }
+ while (!activityQueue.isEmpty())
+ {
+ UserActivity activity = (UserActivity) activityQueue.poll();
+ if (activity != null && ((currentTime - activity.getTimestamp()) <
activityTimeout))
+ {
+ if (activity.getType() != UserActivity.EXIT)
+ {
+ stillActive.add(activity);
+ }
+ else
+ {
+ stillActive.remove(activity);
+ }
+ }
+ }
- activityResults = Collections.unmodifiableSet(stillActive);
+ activityResults = Collections.unmodifiableSet(stillActive);
- }
- }
+ }
+ }
}