Java Reference
In-Depth Information
The last step is to update our TheatreBooker class to use our new account representa-
tion:
private Account currentAccount;
@PostConstruct
public void createCustomer() {
currentAccount = new Account(100);
}
public void bookSeat(int seatId) {
logger.info("Booking seat " + seatId);
final int seatPrice =
theatreBox.getSeatPrice(seatId);
if (seatPrice > currentAccount.getBalance()) {
throw new IllegalArgumentException("Not enough
money!");
}
theatreBox.buyTicket(seatId);
currentAccount = currentAccount.charge(seatPrice);
logger.info("Seat booked.");
}
public Account getCurrentAccount() {
return currentAccount;
}
Note
The newest version of JAX-RS also supports server-side asynchronous responses. Thanks
to the @Suspended annotation and the AsyncResponse class, you can use a separate
(possibly delayed) thread to handle a request call.
Search WWH ::




Custom Search