|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectibis.util.Ticket
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 |
public Ticket()
INIT_SIZE
tickets.
public Ticket(int initialSize)
initialSize
tickets.
initialSize
- the initial number of tickets.Method Detail |
public int get()
public void put(int ticket, java.lang.Object object)
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.
ticket
- the ticket number that gets an object associated with itobject
- the object that gets associatedpublic java.lang.Object collect(int ticket)
ticket
. The
ticket
is made available for reuse.
ticket
- the ticket number for which an object is now requested.
ticket
.public java.lang.Object peek(int ticket)
ticket
.
This version is non-destructive: it leaves the associated value intact.
ticket
- the ticket number for which an object is now requested.
ticket
.public java.lang.Object get(int ticket)
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.
ticket
- the ticket number for which an object is now requested.
ticket
.public void freeTicket(int ticket)
ticket
.
This makes the ticket available for reuse.
ticket
- the ticket number to be released.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |