eneter.messaging.dataprocessing.messagequeueing
Class MessageQueue<TMessage>

java.lang.Object
  extended by eneter.messaging.dataprocessing.messagequeueing.MessageQueue<TMessage>
Type Parameters:
TMessage - Type of the message.

public class MessageQueue<TMessage>
extends java.lang.Object

Memory message queue. One or more threads can put messages into the queue and other threads can remove them. If the queue is empty the thread reading messages is blocked until a message is put to the queue or the thread is unblocked.


Constructor Summary
MessageQueue()
           
 
Method Summary
 void blockProcessingThreads()
          Sets the queue to the blocking mode.
 TMessage dequeueMessage()
          Removes the first message from the queue.
 void enqueueMessage(TMessage message)
          Puts message to the queue.
 int getCount()
          Returns number of messages in the queue.
 boolean isBlockingMode()
          Returns true if the queue blocks threads during dequeue and peek.
 TMessage peekMessage()
          Reads the first message from the queue.
 void unblockProcessingThreads()
          Releases all threads waiting for messages in DequeueMessage() and sets the queue to the unblocking mode.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageQueue

public MessageQueue()
Method Detail

enqueueMessage

public void enqueueMessage(TMessage message)
Puts message to the queue.

Parameters:
message - message that shall be enqueued

dequeueMessage

public TMessage dequeueMessage()
                        throws java.lang.Exception
Removes the first message from the queue. If the queue is empty the thread is blocked until a message is put to the queue. To unblock waiting threads, use UnblockProcesseingThreads().

Returns:
message, it returns null if the waiting thread was unblocked but there is no message in the queue.
Throws:
java.lang.Exception

peekMessage

public TMessage peekMessage()
                     throws java.lang.Exception
Reads the first message from the queue. If the queue is empty the thread is blocked until a message is put to the queue. To unblock waiting threads, use UnblockProcesseingThreads().

Returns:
message, it returns null if the waiting thread was unblocked but there is no message in the queue.
Throws:
java.lang.Exception

unblockProcessingThreads

public void unblockProcessingThreads()
Releases all threads waiting for messages in DequeueMessage() and sets the queue to the unblocking mode. When the queue is in unblocking mode, the dequeue or peek will not block if data is not available but it will return null.


blockProcessingThreads

public void blockProcessingThreads()
Sets the queue to the blocking mode. When the queue is in blocking mode, the dequeue and peek will block until data is available.


isBlockingMode

public boolean isBlockingMode()
Returns true if the queue blocks threads during dequeue and peek.

Returns:
true if the queue is in the blocking mode.

getCount

public int getCount()
Returns number of messages in the queue.

Returns:
number of messages in the queue.