Java Reference
In-Depth Information
For this purpose, let's add a bookasync command to TicketAgencyClient , which
will issue asynchronous booking and a mail command that will simulate the reading of the
outcome by e-mail, as shown in the following code snippet:
private final List<Future<String>> lastBookings = new
ArrayList<>(); [1]
// Some code
case BOOKASYNC:
handleBookAsync();
break;
case MAIL:
handleMail();
break;
// Some code
private void handleBookAsync() {
String text = IOUtils.readLine("Enter SeatId: ");
int seatId;
try {
seatId = Integer.parseInt(text);
} catch (NumberFormatException e1) {
logger.warning("Wrong seatId format!");
return;
}
lastBookings.add(theatreBooker.bookSeatAsync(seatId));
[2]
logger.info("Booking issued. Verify your mail!");
}
private void handleMail() {
boolean displayed = false;
final List<Future<String>> notFinished = new
ArrayList<>();
for (Future<String> booking : lastBookings) {
if (booking.isDone()) { [3]
try {
final String result = booking.get();
logger.info("Mail received: " + result);
Search WWH ::




Custom Search