Now that we've seen an example of JOTM-BTP, let see what is JOTM-BTP.
At the beginning of JOTM-BTP, the goals were:
The main Roles defined in the BTP specification (like
Participant, Decider or SubCoordinator) are
implemented as java classes, to be deployed as Web Services on
Axis. Some embeds a JOTM transaction manager (like Decider or
Subcoordinator, that can create and manage transactions), some don't
(like Participant, that has some BTP capabilities to be enrolled in a
transaction as a resource, but can't create and manage its own
transactions).
The transaction-related messages between a coordinator and a participant are undertaken by a ``BTP Resource'' object, enrolled in JOTM as a Resource, and exchanging XML messages with the participant it represents under the control of the transaction manager (eg. a prepare() call on the resource results in a PREPARE BTP message to be sent to the participant, etc.).
Note: the sample code below does not exactly reflect our current
(prototype) APIs, but what we have is very near from what we propose
here. Of course, it is subject of changes, and comments are
welcome.
public class DemoParticipant extends org.objectweb.jotm.btp.roles.Participant { public void enrolled(String transactionid) { System.out.println("Just enrolled in " + transactionid); } public int prepare(String transactionid) { System.out.println("Requested to prepare transaction " + transactionid); return Participant.VOTE_PREPARED; } public boolean confirm(String transactionid) throws Exception { System.out.println("Requested to confirm transaction " + transactionid); return true; } public boolean cancel(String transactionid) throws Exception { System.out.println("Requested to cancel transaction " + transactionid); return true; } public void contradiction(String transactionid) { } public String applicationMessage(String transactionid, org.objectweb.xml.util.XElement message) { System.out.println("Got an application message: " + message.toString()); return "<greetings>Hello World !</greetings>"; } }
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <!-- Demo Participant --> <service name="BtpDemoService" provider="java:RPC"> <parameter name="scope" value="Application"/> <parameter name="className" value="DemoParticipant"/> <parameter name="allowedMethods" value="messages"/> </service> <!-- Decider (the transaction manager) --> <service name="Decider" provider="java:RPC"> <parameter name="scope" value="Application"/> <parameter name="className" value="org.objectweb.jotm.btp.roles.Decider"/> <parameter name="allowedMethods" value="messages"/> </service> </deployment>
import org.objectweb.jotm.btp.client.BtpClient; import org.objectweb.jotm.btp.messages.*; .... String deciderAddr = "http://localhost:8080/axis/services/TravelAgency"; String participantAddr = "http://localhost:8080/axis/services/HotelReservation"; // Begin the transaction BtpClient client = new BtpClient(); BtpMessage context = client.begin(deciderAddr); if(context != null && context.getType() == BtpMessage.CONTEXT) { // Build application message ApplicationMessage app = new ApplicationMessage("<greetings>Hi there !</greetings>"); // Send it along with the context to the participant BtpMessage replyContext = client.sendCtxApp(participantAddr, (Context)context, app); } // Confirm the transaction BtpMessage outcome = client.confirmTransaction(deciderAddr, (Context)context); ...