public boolean bookSeats(int how_many)
{
RestaurantView restaurantView = RestaurantView.getSingletonInstance();
RestaurantManager restaurantManager = RestaurantManager.getSingletonInstance();
BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
// get the transaction context of this thread:
String transactionId = null;
try
{
transactionId = activityManager.currentTransaction().toString();
}
catch (SystemException e)
{
System.err.println("bookSeats: unable to obtain a transaction context!");
e.printStackTrace(System.err);
return false;
}
// log the event:
System.out.println("RestaurantServiceBA transaction id =" + transactionId);
restaurantView.addMessage("******************************");
restaurantView.addPrepareMessage("id:" + transactionId + ". Received a booking request for one table of " + how_many + " people");
restaurantView.updateFields();
// invoke the backend business logic:
restaurantManager.bookSeats(transactionId, how_many);
// attempt to finalise the booking
// (it will be compensated later if necessary)
if (restaurantManager.prepareSeats(transactionId))
{
restaurantView.addMessage("id:" + transactionId + ". Seats prepared, trying to commit and enlist compensation Participant");
restaurantView.updateFields();
// it worked, so now we need a participant enlisted in case of compensation:
RestaurantParticipantBA restaurantParticipant = new RestaurantParticipantBA(transactionId, how_many);
// enlist the Participant for this service:
BAParticipantManager participantManager = null;
try
{
participantManager = activityManager.enlistForBusinessAgreementWithParticipantCompletion(restaurantParticipant, new Uid().toString());
}
catch (Exception e)
{
restaurantView.addMessage("id:" + transactionId + ". Participant enrolement failed");
System.err.println("bookSeats: Participant enlistment failed");