Java Reference
In-Depth Information
if (seat.getPrice() > money) {
throw new NotEnoughMoneyException("You
don't have enough money to buy this ticket!");
}
logger.info("Booking issued");
theatreBox.buyTicket(seat);
money = money -seat.getPrice();
logger.info("Booking successful");
}
As you can see, this method does not return anything; we will need to use some oth-
er instruments to check if the transaction was completed successfully. For example,
we can check from the theatre list if the seat has been booked successfully.
Returning a Future object to the client
The other available option consists of returning a
java.util.concurrent.Future object that can later be inspected by our clients
so that they know the outcome of our transaction:
@Asynchronous
public Future<String> bookSeatAsync(int seatId)
{
Seat seat =
theatreBox.getSeatList().get(seatId);
if (seat.isBooked()) {
return new AsyncResult<String>("Seat
"+seatId+" Already booked!");
}
if (seat.getPrice() > money) {
return new AsyncResult<String>("You don't
Search WWH ::




Custom Search