org.mmbase.remote
Class Queue

java.lang.Object
  |
  +--org.mmbase.remote.Queue

public class Queue
extends java.lang.Object

Version:
$Revision: 1.7 $ $Date: 2001/04/20 14:15:49 $
Author:
?

Field Summary
 int appendTimeoutTime
           
static int DEFAULT_APPEND_TIMEOUT
          Default timeout of 0 for a blocking append call
static int DEFAULT_GET_TIMEOUT
          Default timeout of 0 for a blocking get call
static int DEFAULT_QUEUE_SIZE
          Default size of 32 for the queue if none is specified.
 int getTimeoutTime
           
 java.util.Vector items
           
 
Constructor Summary
Queue()
          Constructs the queue with the default queue size set to DEFAULT_QUEUE_SIZE, and the append timeout set to DEFAULT_APPEND_TIMEOUT
Queue(int size)
          Constructs the queue, sets the max number of queueable items to the given size, sets the append timeout to DEFAULT_APPEND_TIMEOUT, and sets the get timeout to DEFAULT_GET_TIMEOUT
Queue(int size, int appendTimeout, int getTimeout)
          Constructs the queue, sets the max number of queueable items to the given size, and sets the append() and get() timeouts to the given values.
 
Method Summary
 void append(java.lang.Object item)
          Appends the given item to the queue.
 void appendTimeout()
          This is called every time we timeout while waiting to append something to the queue.
 int count()
          Returns the number of items currently in the queue.
 java.lang.Object get()
          Pulls an item off of the queue.
 void getTimeout()
          Pretty much the same thing as the getTimeout() method, but for blocking get() timeouts.
 void newQueue(int size, int appendTimeout, int getTimeout)
           
 int queueSize()
          Returns the size of the queue
 void resize(int newsize)
          Resizes the queue so that it can contain at most the given number of items in it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

items

public java.util.Vector items

appendTimeoutTime

public int appendTimeoutTime

getTimeoutTime

public int getTimeoutTime

DEFAULT_QUEUE_SIZE

public static int DEFAULT_QUEUE_SIZE
Default size of 32 for the queue if none is specified.

DEFAULT_APPEND_TIMEOUT

public static int DEFAULT_APPEND_TIMEOUT
Default timeout of 0 for a blocking append call

DEFAULT_GET_TIMEOUT

public static int DEFAULT_GET_TIMEOUT
Default timeout of 0 for a blocking get call
Constructor Detail

Queue

public Queue()
Constructs the queue with the default queue size set to DEFAULT_QUEUE_SIZE, and the append timeout set to DEFAULT_APPEND_TIMEOUT
See Also:
DEFAULT_QUEUE_SIZE, DEFAULT_APPEND_TIMEOUT

Queue

public Queue(int size)
Constructs the queue, sets the max number of queueable items to the given size, sets the append timeout to DEFAULT_APPEND_TIMEOUT, and sets the get timeout to DEFAULT_GET_TIMEOUT
Parameters:
size - The maximum size of the queue
See Also:
DEFAULT_APPEND_TIMEOUT

Queue

public Queue(int size,
             int appendTimeout,
             int getTimeout)
Constructs the queue, sets the max number of queueable items to the given size, and sets the append() and get() timeouts to the given values.
Parameters:
size - The maximum size of the queue
appendTimeout - If we can't append() within this many milliseconds, the appendTimeout() method is called before retrying.
getTimeout - If we can't get() something within this many milliseconds, the getTimeout() method is called.
See Also:
appendTimeout(), getTimeout()
Method Detail

newQueue

public void newQueue(int size,
                     int appendTimeout,
                     int getTimeout)

queueSize

public int queueSize()
Returns the size of the queue

count

public int count()
Returns the number of items currently in the queue.

append

public void append(java.lang.Object item)
Appends the given item to the queue. This method calls a synchronized append method, so that it won't interfere with a get call. The method will block if the queue is full, and it won't block otherwise.
Parameters:
item - The item to be appended to the queue

get

public java.lang.Object get()
Pulls an item off of the queue. This method will block until something is found. This method is synchronized so it doesn't interfere with the append call.
Returns:
The bottom object of the queue.

appendTimeout

public void appendTimeout()
This is called every time we timeout while waiting to append something to the queue. You can use this to figure out if you want to increase the queue size. A real hacker could override this to keep statistics, and use the resize() function to increase the size of the queue after a bunch of timeouts. NOTE - DON'T use the resize() method from within this method - the code will hang forever. You should instead flag another thread to do the resize.
See Also:
appendTimeoutTime

getTimeout

public void getTimeout()
Pretty much the same thing as the getTimeout() method, but for blocking get() timeouts. REMEMBER: DON'T call resize() from within this method.
See Also:
getTimeoutTime

resize

public void resize(int newsize)
Resizes the queue so that it can contain at most the given number of items in it. Note - the queue may already have more than the given number of items in it, if so, nothing will be allowed in the queue until it shrinks to contain fewer than the new maximum number of elements in it.
Parameters:
newsize - The new maximum size of the queue


MMBase 2001