ibis.util
Class Ticket

java.lang.Object
  extended byibis.util.Ticket

public class Ticket
extends java.lang.Object

The Ticket class provides a mechanism that enables a user to first obtain an identification number, give that identification number to someone else, and then wait until that someone connects an object to that identification number, and then collect that object. So, an "object" consumer first calls get(). This gives him an identification ("ticket"). He gives this ticket to an "object" producer. This producer at some point produces an object and calls put(ticket, object). Meanwhile, the consumer calls collect(ticket), which will block until an object has been connected to the ticket, and then return that object.


Constructor Summary
Ticket()
          Creates the initial data structure for INIT_SIZE tickets.
Ticket(int initialSize)
          Creates the initial data structure for initialSize tickets.
 
Method Summary
 java.lang.Object collect(int ticket)
          Returns the object that gets associated with ticket.
 void freeTicket(int ticket)
          Releases ticket.
 int get()
          Returns a new ticket.
 java.lang.Object get(int ticket)
          Returns the object that gets associated with ticket.
 java.lang.Object peek(int ticket)
          Returns the object that gets associated with ticket.
 void put(int ticket, java.lang.Object object)
          Associates object with ticket and notifies anyone waiting on the corresponding lock.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Ticket

public Ticket()
Creates the initial data structure for INIT_SIZE tickets.


Ticket

public Ticket(int initialSize)
Creates the initial data structure for initialSize tickets.

Parameters:
initialSize - the initial number of tickets.
Method Detail

get

public int get()
Returns a new ticket. If not available, the data structure is doubled in size.

Returns:
a new ticket number.

put

public void put(int ticket,
                java.lang.Object object)
Associates object with ticket and notifies anyone waiting on the corresponding lock. If an object is already associated with this ticket, the method blocks until the ticket is made available (by means of a get(ticket) call.

Parameters:
ticket - the ticket number that gets an object associated with it
object - the object that gets associated

collect

public java.lang.Object collect(int ticket)
Returns the object that gets associated with ticket. The ticket is made available for reuse.

Parameters:
ticket - the ticket number for which an object is now requested.
Returns:
the object that got associated with ticket.

peek

public java.lang.Object peek(int ticket)
Returns the object that gets associated with ticket. This version is non-destructive: it leaves the associated value intact.

Parameters:
ticket - the ticket number for which an object is now requested.
Returns:
the object that got associated with ticket.

get

public java.lang.Object get(int ticket)
Returns the object that gets associated with ticket. This version is destructive (makes the ticket available for another put), but does not release the ticket. To release the ticket, collect must be used.

Parameters:
ticket - the ticket number for which an object is now requested.
Returns:
the object that got associated with ticket.

freeTicket

public void freeTicket(int ticket)
Releases ticket. This makes the ticket available for reuse.

Parameters:
ticket - the ticket number to be released.


The Ibis project