KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > chat > business > DiscussionManagerImpl


1 package chat.business;
2
3 import chat.spec.*;
4
5 public class DiscussionManagerImpl implements DiscussionManager {
6
7    
8     public DiscussionManagerImpl() {
9     }
10
11
12     /**
13      * Add a message to the discussion. Any waiting clients will be
14      * instantly notified.
15      */

16     public void addMessage(String JavaDoc name, String JavaDoc txt) {
17       Discussion.addMessage(name,txt);
18     }
19
20
21
22
23
24
25     /**
26      * Throw out all the current messages.
27      * All the waiting clients will be immediatly notified.
28      */

29     public void clear() {
30       Discussion.clear();
31     }
32
33  
34
35
36     /**
37      * Get a snapshot of the current state. Might block.
38      *
39      * @param currentState
40      * The state identifier that was returned last time this was called.
41      * This is the id of the state that the client currently has. It is
42      * asking for a snapshot of the state after things change and
43      * this id is not longer current. If this has already happened, the
44      * call will immediatly return. If it has not happned, the call will
45      * block (not return) until things change.
46      * @param wait
47      * The maxmimum number of seconds this call is allowed to block for.
48      * Send 0 for an instant response. If the call blocks and then
49      * runs out of time, a snapshot is returned.
50      * @return
51      * A Snapshot object. This is just a way to return two things at
52      * once: a Vector of Message objects and a state identifier.
53      * The client should use the state identifier for the next call to
54      * this method. The client should call this method again as soon as
55      * it is done displaying the results.
56      */

57     public Snapshot getContents(long currentState, long wait) {
58       
59         return Discussion.getContents(currentState, wait);
60     }
61
62
63
64     /**
65      * How may clients are blocked on a read? This is, effectivly, the
66      * number of people participating in the discussion.
67      */

68     public int getNumWaiting() {
69         return Discussion.getNumWaiting();
70     }
71
72    public long getTotalReceived(){
73         return Discussion.getTotalReceived();
74    }
75
76    public long getCurrentSize(){
77        return Discussion.getCurrentSize();
78    }
79    
80        
81
82   public void setMaxQueueSize(int maxQueueSize){
83     Discussion.maxQueueSize=maxQueueSize;
84    }
85   
86
87
88
89     /**
90      * Call this function (only once) if you want to start the
91      * harverter thread. It runs in the background and periodically
92      * deletes messages that are too old. Most of the time the thread
93      * is sleeping. If this method is not called, then no age limit on
94      * messages will be enforced. <P>
95      *
96      * The longest a message can live is lifetimeSec + intervalSec seconds
97      * (in the extreme case). <P>
98      *
99      * The default value for the interval is a little shorter than the
100      * default value for the browser's timeout. This is so that if the
101      * browser is left idle (and messages start being deleted), the
102      * refresh cycle will sync up with this threads interval, and
103      * fewer updates will happen (delete, delete, delete... instead of
104      * timout, delete, timeout, delete, timeout, delete...). It's not
105      * a big deal, but hey...
106      *
107      * @param lifetimeSec
108      * How long should messages be kept for (seconds).
109      * @param
110      */

111     public void startHarvester(int lifetimeSec, int intervalSec) {
112        
113            Discussion.startHarvester(lifetimeSec,intervalSec);
114         
115     }
116 public void stopHarvester(){
117    Discussion.stopHarvester();
118   }
119
120 }
121
122      
123
Popular Tags