001: package chat.business;
002:
003: import chat.spec.*;
004:
005: public class DiscussionManagerImpl implements DiscussionManager {
006:
007: public DiscussionManagerImpl() {
008: }
009:
010: /**
011: * Add a message to the discussion. Any waiting clients will be
012: * instantly notified.
013: */
014: public void addMessage(String name, String txt) {
015: Discussion.addMessage(name, txt);
016: }
017:
018: /**
019: * Throw out all the current messages.
020: * All the waiting clients will be immediatly notified.
021: */
022: public void clear() {
023: Discussion.clear();
024: }
025:
026: /**
027: * Get a snapshot of the current state. Might block.
028: *
029: * @param currentState
030: * The state identifier that was returned last time this was called.
031: * This is the id of the state that the client currently has. It is
032: * asking for a snapshot of the state after things change and
033: * this id is not longer current. If this has already happened, the
034: * call will immediatly return. If it has not happned, the call will
035: * block (not return) until things change.
036: * @param wait
037: * The maxmimum number of seconds this call is allowed to block for.
038: * Send 0 for an instant response. If the call blocks and then
039: * runs out of time, a snapshot is returned.
040: * @return
041: * A Snapshot object. This is just a way to return two things at
042: * once: a Vector of Message objects and a state identifier.
043: * The client should use the state identifier for the next call to
044: * this method. The client should call this method again as soon as
045: * it is done displaying the results.
046: */
047: public Snapshot getContents(long currentState, long wait) {
048:
049: return Discussion.getContents(currentState, wait);
050: }
051:
052: /**
053: * How may clients are blocked on a read? This is, effectivly, the
054: * number of people participating in the discussion.
055: */
056: public int getNumWaiting() {
057: return Discussion.getNumWaiting();
058: }
059:
060: public long getTotalReceived() {
061: return Discussion.getTotalReceived();
062: }
063:
064: public long getCurrentSize() {
065: return Discussion.getCurrentSize();
066: }
067:
068: public void setMaxQueueSize(int maxQueueSize) {
069: Discussion.maxQueueSize = maxQueueSize;
070: }
071:
072: /**
073: * Call this function (only once) if you want to start the
074: * harverter thread. It runs in the background and periodically
075: * deletes messages that are too old. Most of the time the thread
076: * is sleeping. If this method is not called, then no age limit on
077: * messages will be enforced. <P>
078: *
079: * The longest a message can live is lifetimeSec + intervalSec seconds
080: * (in the extreme case). <P>
081: *
082: * The default value for the interval is a little shorter than the
083: * default value for the browser's timeout. This is so that if the
084: * browser is left idle (and messages start being deleted), the
085: * refresh cycle will sync up with this threads interval, and
086: * fewer updates will happen (delete, delete, delete... instead of
087: * timout, delete, timeout, delete, timeout, delete...). It's not
088: * a big deal, but hey...
089: *
090: * @param lifetimeSec
091: * How long should messages be kept for (seconds).
092: * @param
093: */
094: public void startHarvester(int lifetimeSec, int intervalSec) {
095:
096: Discussion.startHarvester(lifetimeSec, intervalSec);
097:
098: }
099:
100: public void stopHarvester() {
101: Discussion.stopHarvester();
102: }
103:
104: }
|