KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > web > talk > plugin > GroupList


1 package com.quikj.application.web.talk.plugin;
2
3 import com.quikj.server.framework.*;
4 import java.util.*;
5
6 public class GroupList
7 // synchronization not required for CP-CP interaction, since changes to list content come
8
// out of single ServiceController thread execution.
9
// (OAMP note for this class and EndPointList: update DB, then look in these lists
10
// to update Group/EndPointInfo. If item found immediately, update and done; otherwise,
11
// wait some time and look again (CP may have gotten old data from DB and is adding
12
// the item to the list). Or, run OAMP lower priority than CP.)
13
{
14     
15     public GroupList()
16     {
17         instance = this;
18     }
19     
20     public static GroupList Instance()
21     {
22         if (instance == null)
23         {
24             new GroupList();
25         }
26         
27         return instance;
28     }
29     
30     public void dispose()
31     {
32         activeGroups.clear();
33     }
34     
35     public int addGroup(GroupInfo groupinfo)
36     // returns number of active users associated with this group, after the add operation
37
{
38         String JavaDoc name = groupinfo.getName();
39         GroupInfo info = (GroupInfo) activeGroups.get(name);
40         if (info == null) // not currently in list
41
{
42             activeGroups.put(name, groupinfo);
43             groupinfo.setActiveUserCount(1);
44             return 1;
45         }
46         else
47         {
48             int new_count = info.incrementActiveUserCount();
49             activeGroups.remove(name);
50             activeGroups.put(name, groupinfo);
51             groupinfo.setActiveUserCount(new_count);
52             
53             return new_count;
54         }
55     }
56     
57     public int removeGroup(String JavaDoc name)
58     // returns the new number of active users associated with this group, if zero then removed from list
59
{
60         GroupInfo info = (GroupInfo) activeGroups.get(name);
61         if (info == null) // not currently in list
62
{
63             AceLogger.Instance().log(AceLogger.ERROR,
64             AceLogger.SYSTEM_LOG,
65             name
66             + " group - GroupList.removeGroup() -- Couldn't find group "
67             + name
68             + " in active group list.");
69             return 0;
70         }
71         
72         int ret = info.decrementActiveUserCount();
73         if (ret == 0)
74         {
75             activeGroups.remove(name);
76         }
77         
78         return ret;
79     }
80     
81     public GroupInfo findGroup(String JavaDoc name)
82     {
83         return (GroupInfo)activeGroups.get(name);
84     }
85     
86    
87     private static GroupList instance = null;
88     private Hashtable activeGroups = new Hashtable(); // key = name, value = GroupInfo
89

90 }
91
Popular Tags