Java Reference
In-Depth Information
@Stateless
public class AutomaticSellerService {
@Inject
private Logger logger;
@Inject
private TheatreBox theatreBox;
@Resource
private TimerService timerService;
@Schedule(hour = "*", minute = "*", second = "*/30",
persistent = false)
public void automaticCustomer() {
final Optional<Seat> seatOptional = findFreeSeat();
if (!seatOptional.isPresent()) {
cancelTimers();
logger.info("Scheduler gone!");
return; // No more seats
}
final Seat seat = seatOptional.get();
theatreBox.buyTicket(seat.getId());
logger.info("Somebody just booked seat number " +
seat.getId());
}
private Optional<Seat> findFreeSeat() {
final Collection<Seat> list = theatreBox.getSeats();
return list.stream().filter(seat ->
!seat.isBooked()).findFirst();
}
private void cancelTimers() {
Search WWH ::




Custom Search