edu.rit.m2mp
Class MessageQueue

java.lang.Object
  extended by edu.rit.m2mp.MessageQueue

public class MessageQueue
extends Object

Class MessageQueue provides a FIFO queue of incoming M2MP messages (type MessageInputStream).

Note: Class MessageQueue is multiple thread safe.


Constructor Summary
MessageQueue()
          Construct a new message queue.
 
Method Summary
 MessageInputStream get()
          Get a message from the beginning of this message queue.
 MessageInputStream get(long timeout)
          Get a message from the beginning of this message queue, with a timeout.
 void put(MessageInputStream theMessage)
          Put the given message at the end of this message queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageQueue

public MessageQueue()
Construct a new message queue.

Method Detail

put

public void put(MessageInputStream theMessage)
Put the given message at the end of this message queue.

Parameters:
theMessage - Message.

get

public MessageInputStream get()
                       throws InterruptedException
Get a message from the beginning of this message queue. This method blocks until a message is available.

Returns:
Message.
Throws:
InterruptedException - Thrown if the calling thread was interrupted while blocked in this method.

get

public MessageInputStream get(long timeout)
                       throws InterruptedException
Get a message from the beginning of this message queue, with a timeout. This method blocks until a message is available or until the specified timeout interval has elapsed, whichever happens first. The timeout interval is timeout milliseconds. If the timeout interval is 0, this method immediately returns a message if one is available, otherwise this method immediately returns null.

Parameters:
timeout - Timeout interval (milliseconds), or 0 for a non-blocking call.
Returns:
Message, or null if a timeout occurred.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if timeout < 0.
InterruptedException - Thrown if the calling thread was interrupted while blocked in this method.


Copyright © 2001-2006 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.