de.zeigermann.xpa.tokenParser
Class BlockingLinkedListTokenQueue

java.lang.Object
  |
  +--de.zeigermann.xpa.tokenParser.BlockingLinkedListTokenQueue

public class BlockingLinkedListTokenQueue
extends Object

This is class is a special form of a LinkedListTokenQueue. It is intended for a concurrent environment and manages queueing and dequeueing if tokens following the well known producer/consumer strategy.

Communication of error states between consumer and producer is done via the dequeue() and setError(java.lang.Throwable) methods.


Field Summary
protected  Throwable error
           
protected  LinkedListTokenQueue lltq
           
protected  int maxBufferSize
           
 
Constructor Summary
BlockingLinkedListTokenQueue(int maxBufferSize)
          Creates a new token queue.
 
Method Summary
 Token dequeue()
          Removes a token from this queue and returns it.
 void queue(Token token)
          Adds a token to this queue.
 void setError(Throwable error)
          Sets an error state to communicate to consumer thread via the dequeue() method.
 int size()
          Gets the current size of the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lltq

protected LinkedListTokenQueue lltq

maxBufferSize

protected int maxBufferSize

error

protected Throwable error
Constructor Detail

BlockingLinkedListTokenQueue

public BlockingLinkedListTokenQueue(int maxBufferSize)
Creates a new token queue.

Parameters:
maxBufferSize - maximum size of the queue
See Also:
queue(antlr.Token)
Method Detail

queue

public void queue(Token token)
Adds a token to this queue. If the maximum queue size as set in ctor is reached this method blocks until another thread dequeues a token.

See Also:
dequeue(), setError(java.lang.Throwable)

dequeue

public Token dequeue()
              throws Throwable
Removes a token from this queue and returns it. If there is no token in the queue this method blocks until another thread queues a token. If an error has been set by setError(java.lang.Throwable) this method will not block, but throw this error as an excpetion. This allows for a communication of errors between the producer and consumer.

Throws:
Throwable - communicates an error state set by producer to consumer
See Also:
queue(antlr.Token), setError(java.lang.Throwable)

size

public int size()
Gets the current size of the queue. This means how many tokens are queued.


setError

public void setError(Throwable error)
Sets an error state to communicate to consumer thread via the dequeue() method. Normally this method is called by the thread that is also calling the queue(antlr.Token) method, i.e. the thread playing the role of the producer.

See Also:
queue(antlr.Token), dequeue()


Copyright © 1999-2003 Oliver Zeigermann. All Rights Reserved.