irssibot.core
Class OutputQueue

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--irssibot.core.OutputQueue
All Implemented Interfaces:
java.lang.Runnable

public class OutputQueue
extends java.lang.Thread

This class represents a buffered output queue for a server connection. It includes functionality for queuing mode pushes and traffic to the server.

IRC servers have a 1024 -byte buffer for each client (this might be outdated but should be accurate enough) and that buffer may not be overflown or else the client is disconnected with 'Excess Flood'.

Version:
$Name: $ $Revision: 1.7 $
Author:
Matti Dahlbom
See Also:
ModeQueueElement

Field Summary
private  boolean alive
          Indicates whether this queueing thread is running or not.
private  int intervalBytes
          Number of bytes sent during this interval
private  long intervalStarted
          Point of time when the current output flush interval started
private  long lastModeFlushTime
          Time of last mode flush
private static long modeFlushInterval
          Length of mode flushing interval (in milliseconds).
private  java.util.Hashtable modeQueue
          A Hashtable containing Vector objects as mode queues.
private static java.lang.String moduleName
           
private  java.io.BufferedOutputStream out
          Output stream for server connection
private  long outFlushTime
          Time interval (in milliseconds) during which max .outMaxBytes bytes are allowed to be sent to the server.
private  java.lang.Object outLock
          Lock object for queue operations
private  int outMaxBytes
          Maximum number of bytes to be sent to the server during a outFlushTime ms time period.
private  java.util.Vector outQueue
          The actual output queue.
private static long waitPeriod
          Timeout value (in milliseconds) for wait() in main loop.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
OutputQueue(java.io.BufferedOutputStream out, long outFlushTime, int outMaxBytes)
           
 
Method Summary
private  void doModeFlush(java.lang.String channelName, java.util.Vector queue)
          Flushes the mode queue to the server.
private  boolean doOutput()
          Flushes output queue to the server at maximum rate of outMaxBytes bytes per outFlushTime time interval (ms).
 void killQueue()
          Kills the queue
 void output(java.lang.String line)
          Adds an output line (irc command) to output queue.
 void priorityOutput(java.lang.String line)
          Outputs a line straight to the server past the queue.
 void pushMode(ModeQueueElement element)
          Pushes a mode to a channel's mode queue.
 void run()
          After certain interval flushes the mode queue.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

moduleName

private static java.lang.String moduleName

modeFlushInterval

private static final long modeFlushInterval
Length of mode flushing interval (in milliseconds).

See Also:
Constant Field Values

waitPeriod

private static final long waitPeriod
Timeout value (in milliseconds) for wait() in main loop.

See Also:
Constant Field Values

lastModeFlushTime

private long lastModeFlushTime
Time of last mode flush


out

private java.io.BufferedOutputStream out
Output stream for server connection


modeQueue

private java.util.Hashtable modeQueue
A Hashtable containing Vector objects as mode queues. Channel name Strings are used as keys.


outQueue

private java.util.Vector outQueue
The actual output queue. The elements are String objects whose content is irc commands to be sent to the server.


outFlushTime

private long outFlushTime
Time interval (in milliseconds) during which max .outMaxBytes bytes are allowed to be sent to the server.


outMaxBytes

private int outMaxBytes
Maximum number of bytes to be sent to the server during a outFlushTime ms time period.


outLock

private java.lang.Object outLock
Lock object for queue operations


intervalStarted

private long intervalStarted
Point of time when the current output flush interval started

See Also:
System.currentTimeMillis()

intervalBytes

private int intervalBytes
Number of bytes sent during this interval


alive

private boolean alive
Indicates whether this queueing thread is running or not.

Constructor Detail

OutputQueue

public OutputQueue(java.io.BufferedOutputStream out,
                   long outFlushTime,
                   int outMaxBytes)
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Thread

priorityOutput

public void priorityOutput(java.lang.String line)
Outputs a line straight to the server past the queue.

Parameters:
line - output line

output

public void output(java.lang.String line)
Adds an output line (irc command) to output queue. Lines longer than outMaxBytes are discarded without notice.

Parameters:
line - output line

doOutput

private boolean doOutput()
Flushes output queue to the server at maximum rate of outMaxBytes bytes per outFlushTime time interval (ms).

NOTE: this method is synchronized from outside (in run()) to outLock.

Returns:
true if there are lines in the queue but we cannot send any more during this interval. false if the queue is empty.
See Also:
outLock, run()

pushMode

public void pushMode(ModeQueueElement element)
Pushes a mode to a channel's mode queue.

Parameters:
element - the ModeQueueElement for the new mode
See Also:
ModeQueueElement

doModeFlush

private void doModeFlush(java.lang.String channelName,
                         java.util.Vector queue)
Flushes the mode queue to the server.

Parameters:
channelName - name of channel whose mode queue to push
queue - mode queue for the channel

run

public void run()
After certain interval flushes the mode queue. Pumps the contents of the output queue to the server at maximum rate of outMaxBytes bytes per outFlushTime time interval (ms).

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

killQueue

public void killQueue()
Kills the queue



IrssiBot (c) 2000-2002 Matti Dahlbom