+\r
+ public static List getLoggedInUsers() {\r
+ List result = new Vector();\r
+\r
+ synchronized (loggedInUsers) {\r
+ Iterator i = loggedInUsers.entrySet().iterator();\r
+\r
+ while (i.hasNext()) {\r
+ Map.Entry entry = (Map.Entry) i.next();\r
+\r
+ Map item = new HashMap();\r
+ item.put("name", entry.getKey());\r
+ item.put("count", entry.getValue());\r
+ result.add(item);\r
+ }\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ public static void registerLogin(String aName) {\r
+ modifyLoggedInCount(aName, 1);\r
+ }\r
+\r
+ public static void registerLogout(String aName) {\r
+ modifyLoggedInCount(aName, -1);\r
+ }\r
+\r
+ private static void modifyLoggedInCount(String aName, int aModifier) {\r
+ synchronized (loggedInUsers) {\r
+ Integer count = (Integer) loggedInUsers.get(aName);\r
+ if (count==null)\r
+ count = new Integer(0);\r
+\r
+ if (count.intValue()+aModifier<=0) {\r
+ loggedInUsers.remove(aName);\r
+ }\r
+ else {\r
+ loggedInUsers.put(aName, new Integer(count.intValue() + aModifier));\r
+ }\r
+ }\r
+ }\r