Java Reference
In-Depth Information
Adding a stateful bean
In order to keep track of how much money our customer has got in his pocket, we will need
a session-aware component. Turning a Java class into a stateful session bean is just a matter
of adding a @Stateful annotation on top of it, as in our example
com.packtpub.wflydevelopment.chapter3.boundary.TheatreBooker
class. This is shown in the following code:
@Stateful
@Remote(TheatreBookerRemote.class)
@AccessTimeout(value = 5, unit = TimeUnit.MINUTES)
public class TheatreBooker implements TheatreBookerRemote {
private static final Logger logger =
Logger.getLogger(TheatreBooker.class);
@EJB
private TheatreBox theatreBox;
private int money;
@PostConstruct
public void createCustomer() {
this.money = 100;
}
@Override
public int getAccountBalance() {
return money;
}
@Override
public String bookSeat(int seatId) throws
SeatBookedException, NotEnoughMoneyException,
NoSuchSeatException {
final int seatPrice =
theatreBox.getSeatPrice(seatId);
if (seatPrice > money) {
throw new NotEnoughMoneyException("You don't
have enough money to buy this " + seatId + " seat!");
Search WWH ::




Custom Search