public boolean bookTaxi()
{
TaxiView taxiView = TaxiView.getSingletonInstance();
TaxiManager taxiManager = TaxiManager.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("bookTaxi: unable to obtain a transaction context!");
e.printStackTrace(System.err);
return false;
}
// log the event:
System.out.println("TaxiServiceBA transaction id =" + transactionId);
taxiView.addMessage("******************************");
taxiView.addPrepareMessage("id:" + transactionId.toString() + ". Received a taxi booking request");
taxiView.updateFields();
// invoke the backend business logic:
taxiManager.bookTaxi(transactionId);
// attempt to finalise the booking
if (taxiManager.prepareTaxi(transactionId))
{
taxiView.addMessage("id:" + transactionId + ". Seats prepared, trying to commit and enlist compensation Participant");
taxiView.updateFields();
// it worked, so now we need a participant enlisted in case of compensation:
TaxiParticipantBA taxiParticipant = new TaxiParticipantBA(transactionId);
// enlist the Participant for this service:
BAParticipantManager participantManager = null;
try
{
participantManager = activityManager.enlistForBusinessAgreementWithParticipantCompletion(taxiParticipant, "org.jboss.jbossts.xts-demo:restaurantBA:" + new Uid().toString());
}
catch (Exception e)
{
taxiView.addMessage("id:" + transactionId + ". Participant enrolement failed");
taxiManager.cancelTaxi(transactionId);