T
- The type of object being reserved. Compared using equals.public class ReservationService<T>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ReservationService.Reservation<T>
A token used as proof of a reservation.
|
Constructor and Description |
---|
ReservationService() |
Modifier and Type | Method and Description |
---|---|
protected ReservationService.Reservation<T> |
createReservation(T item)
Creates a reservation containing the supplied item.
|
boolean |
isReserved(T item)
Checks whether the supplied item is already reserved.
|
ReservationService.Reservation<T> |
reserve(T item)
Attempts to reserve the supplied item.
|
ReservationService.Reservation<T> |
tryReserve(T item)
Attempts to reserve the supplied item.
|
boolean |
tryWithReservation(T item,
java.lang.Runnable r)
Runs the supplied Runnable after trying to establishing a reservation for
the supplied item.
|
void |
unreserve(ReservationService.Reservation<T> reservation)
Releases the supplied Reservation, making its contained item available
for waiting reservations.
|
boolean |
withReservation(T item,
java.lang.Runnable r)
Runs the supplied Runnable after establishing a reservation for the
supplied item.
|
public boolean isReserved(T item)
item
- The item to check for reservation.public ReservationService.Reservation<T> reserve(T item)
item
- The item to be reserved.public ReservationService.Reservation<T> tryReserve(T item)
item
- The item to be reserved.public boolean tryWithReservation(T item, java.lang.Runnable r)
item
- The item to be reserved while the Runnable executes.r
- The Runnable to be executed while the item is reserved.public void unreserve(ReservationService.Reservation<T> reservation)
reservation
- The Reservation to be released.public boolean withReservation(T item, java.lang.Runnable r)
item
- The item to be reserved while the Runnable executes.r
- The Runnable to be executed while the item is reserved.protected ReservationService.Reservation<T> createReservation(T item)
item
- The item being reserved.