Transactional Queue Class
The queue is a traditional FIFO queue, where elements are added to the front and removed from the back. The operations provided by the queue class allow the values to be placed on to the queue (enqueue) and to be removed from it (dequeue), and values of elements in the queue can also be changed or inspected. In this example implementation, an array represents the queue. A limit of QUEUE_SIZE elements has been imposed for this example. Example 6.1. Java interface definition of class queue public class TransactionalQueue extends LockManager { public TransactionalQueue (Uid uid); public TransactionalQueue (); public void finalize (); public void enqueue (int v) throws OverFlow, UnderFlow, QueueError, Conflict; public int dequeue () throws OverFlow, UnderFlow, QueueError, Conflict; public int queueSize (); public int inspectValue (int i) throws OverFlow, UnderFlow, QueueError, Conflict; public void setValue (int i, int v) throws OverFlow, UnderFlow, QueueError, Conflict; public boolean save_state (OutputObjectState os, int ObjectType); public boolean restore_state (InputObjectState os, int ObjectType); public String type (); public static final int QUEUE_SIZE = 40; // maximum size of the queue private int[QUEUE_SIZE] elements; private int numberOfElements; };