com.mischiefbox.dmud.util
Class InputQueue
java.lang.Object
|
+--com.mischiefbox.dmud.util.Queue
|
+--com.mischiefbox.dmud.util.InputQueue
- public class InputQueue
- extends Queue
Input queue and manager.
Accepts partial or complete messages. Holds partial messages until
a complete message is composed, or discards messages beyond a
hard-coded message size limit. Complete messages become a new
Message object which are put onto the message handler queue.
This class is a specialization of the generic Queue class.
The queue is a linked list. New elements are added to the tail,
available elements are removed from the front.
- Version:
- $Id: InputQueue.java,v 1.1.1.1 2001/06/27 01:33:17 cjones Exp $
- Author:
- Chris Jones
- See Also:
Message,
Queue
|
Constructor Summary |
InputQueue()
Create a new InputQueue. |
|
Method Summary |
void |
incomingMessage(String sConnectionId,
byte[] baMessageContent)
Convert partial messages into Message objects. |
static int |
scanByteArray(byte[] baContent,
byte[] baSpec)
Scan a byte array for a pattern. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MAX_MESSAGE_SIZE
protected static final int MAX_MESSAGE_SIZE
- The maximum incomplete message size.
htMessages
protected Hashtable htMessages
- The dictionary (Hashtable) of partial messages.
A Hashtable is used because the class is thread-safe
(synchronized so that multiple connection handlers can work
with it at once).
Key is connection id, value is a byte array partial message.
baMessageHeader
protected static byte[] baMessageHeader
- Message header byte signature.
Used in partial-message matching.
baMessageFooter
protected static byte[] baMessageFooter
- Message footer byte signature.
Used in partial-message matching.
InputQueue
public InputQueue()
- Create a new InputQueue.
Do the housekeeping necessary to make the input queue usable.
incomingMessage
public void incomingMessage(String sConnectionId,
byte[] baMessageContent)
throws MessageTooLargeException
- Convert partial messages into Message objects.
Accepts a partial message and connection. Attempts to
create a complete Message object from the partial message and
previous partial messages. Inserts the completed message object
onto the queue. Discards incomplete messages that are larger
than the maximum message size.
Partial messages are stored in a dictionary-type object
(Hashtable, so multiple connection handlers can use this
method).
- Parameters:
sConnectionId - the incoming connection id.baMessageContent - the incoming message content.- Throws:
MessageTooLargeException - on overly long messages.
scanByteArray
public static int scanByteArray(byte[] baContent,
byte[] baSpec)
- Scan a byte array for a pattern.
Arrays in Java may not be larger than int (32-bit), so it is
safe to return int from this method.
- Parameters:
baContent - the searched byte array.baSpec - the specified byte array to find.- Returns:
- the offset of the specified byte array inside the
searched byte array, or -1 if not found.
Copyright © 2001 by Christopher R. Jones. All Rights Reserved.