thread
Class Deque

java.lang.Object
  extended by thread.Deque
All Implemented Interfaces:
java.io.Serializable

public class Deque
extends java.lang.Object
implements java.io.Serializable

This Deque class implements a double ended queue in a similar way as the class BoundedBuffer does. It has some capacity to store objects. With the method put objects are placed into the buffer. With the get method objects are taken from the buffer in FIFO order and with pop objects are taken from the buffer in LIFO order. put blocks if there is no space to place a object into the buffer. get and pop block if there are no objects in the channel. This class is safe against Thread InterruptedException.

Author:
Akitoshi Yoshida, Heinz Kredel.
See Also:
see Channel see Queue see Deque see MemoryChannel see SyncChannel see Stack, Serialized Form

Field Summary
private  java.lang.Object[] buffer
          the buffer is the deque contents.
private  Semaphore empty
          a semaphore indicating an empty cell.
private  int front
          index to the first filled cell.
private  Semaphore full
          a semaphore indicating a filled cell.
private  java.lang.Object rcv
          mutex for receive.
private  int rear
          index to the first empty cell.
private  int size
          the buffer's size.
private  java.lang.Object snd
          mutex for send.
static java.lang.String undefined
          Declares an undefined value of type String.
 
Constructor Summary
Deque(int init)
          Construct a Deque.
 
Method Summary
 boolean empty()
          Tests if the deque is empty.
 java.lang.Object get()
          Get an object from the deque, FIFO order.
 java.lang.Object get(int m)
          Get an object from the deque within given timeout, FIFO order.
 java.lang.Object pop()
          Pop an object from the deque, LIFO order.
 java.lang.Object pop(int m)
          Pop an object from the deque within given timeout, LIFO order.
 void push(java.lang.Object v)
          Push an object to the deque.
 void put(java.lang.Object v)
          Put an object to the deque.
 int size()
          Get the number of elements in the deque.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

private java.lang.Object[] buffer
the buffer is the deque contents.


size

private int size
the buffer's size.


front

private int front
index to the first filled cell.


rear

private int rear
index to the first empty cell.


empty

private Semaphore empty
a semaphore indicating an empty cell.


full

private Semaphore full
a semaphore indicating a filled cell.


snd

private java.lang.Object snd
mutex for send.


rcv

private java.lang.Object rcv
mutex for receive.


undefined

public static final java.lang.String undefined
Declares an undefined value of type String.

See Also:
Constant Field Values
Constructor Detail

Deque

public Deque(int init)
Construct a Deque.

Parameters:
init - An integer which defines the deques size.
Method Detail

put

public void put(java.lang.Object v)
         throws java.lang.InterruptedException
Put an object to the deque. Return without object put if Interrupted.

Throws:
InterruptedException.
java.lang.InterruptedException

push

public void push(java.lang.Object v)
          throws java.lang.InterruptedException
Push an object to the deque. Return without object pushed if Interrupted.

Throws:
InterruptedException.
java.lang.InterruptedException

get

public java.lang.Object get()
                     throws java.lang.InterruptedException
Get an object from the deque, FIFO order.

Returns:
null object if Interrupted.
Throws:
InterruptedException.
java.lang.InterruptedException

get

public java.lang.Object get(int m)
                     throws java.lang.InterruptedException
Get an object from the deque within given timeout, FIFO order.

Returns:
null object if Interrupted.
Throws:
InterruptedException.
java.lang.InterruptedException

pop

public java.lang.Object pop()
                     throws java.lang.InterruptedException
Pop an object from the deque, LIFO order.

Returns:
null object if Interrupted.
Throws:
InterruptedException.
java.lang.InterruptedException

pop

public java.lang.Object pop(int m)
                     throws java.lang.InterruptedException
Pop an object from the deque within given timeout, LIFO order.

Returns:
null object if Interrupted.
Throws:
InterruptedException.
java.lang.InterruptedException

empty

public boolean empty()
Tests if the deque is empty.


size

public int size()
Get the number of elements in the deque.

Returns:
size of deque.