Java Reference
In-Depth Information
seat.setBooked(true);
}
}
Let's see our application code in detail; the void method setupTheatre is invoked
as soon as the application is deployed and takes care of assembling the theatre
seats, creating a simple list of Seat objects. Each Seat object is constructed using a
set of three field constructors that includes the seat ID, its description, and the price:
public class Seat {
public Seat(int id, String seat, int price) {
this.id = id;
this.seatName = seat;
this.price = price;
}
// Fields and Getters/Setters omitted for
brevity
}
Next, the singleton bean exposes three public methods; the getSeatList method
returns a list of Seat objects that will return to the user the information regarding
whether they have been reserved or not.
The getSeatPrice method is a utility method that will pick up the seat price and
return it as int so it can be used to verify the user is able to afford buying the ticket.
Finally, the buyTicket method is the one that actually buys the ticket and therefore
sets up the ticket as booked.
Controlling bean concurrency
As you might have noticed, the bean includes an @Lock annotation on top of the
methods managing our collection of Seat objects. This kind of annotation is used to
control the concurrency of the singleton.
Search WWH ::




Custom Search