You can get a good understanding of what's going on by looking at the test programms that are located in the test directory, namely test/TTAClient.java, test/TTAServer.java for the transfer part of the txlayer, and test/ETAClient.java and test/ETAServer.java for the exchange part. All test programms are driven by test/TTAMain.java, but that should not bother you too much.
Objects that do a transfer are called TransferTransaction, objects that do an exchange are called ExchangeTransaction.
The things that you want to transfer are given to the Transfer-/ExchangeTransaction upon instantiation.
The Transfer-/ExchangeTransaction itself must be prepared in some way to do what you want from it. You can either prepare it for sending or receiving in the case of a transfer, or prepare it for originating or responding to an exchange.
Both have as a parameter an object called a TXContext, which contains means for communication. Upon creation of a TXContext parameters such as the hostname must be specified, and you must explicitely tell the TXContext to offer a connection request to a peer or to accept such a request.
After the transactions are prepared on both sides, they can be started by calling the begin() method. This spawns a thread that runs the transaction. Naturally, you can afterwards call join() on the transaction to wait for its completion, or you can call beginAndBlock() right from the begining.
A result can be obtained by calling getObject() after completion, that is, after join() or beginAndBlock() returned.
Now into real life:
/* First, create a TXContext. */ TXContext txc_send = new TXContext(peerHostname, claddress); /* Now we can offer the context to the peer specified * in the TXAddress. The peer must run now an acceptContext(), * see below. */ txc_send.offerContext(userdata); /* Create some goods that can be transferred. */ Container tc = new Container(); tc.append(new ItemA("Good so and so")); /* Ask the container for a suitable TransferTransaction. */ TransferTransaction sender = tc.getTransferTransaction(); /* Now prepare the sender side. */ sender.prepareSender(txc_send.getSubContext(1)); /* Start it and wait until we are finished. */ sender.beginAndBlock();
/* First create a TXContext. */ TXContext txc_rec = new TXContext(claddress); /* Now we can accept the context from the peer specified * in the TXAddress. The peer must run now an offerContext(), * see above. */ userdata = txc_rec.acceptContext(); /* Now we have to create a suitable TransferTransaction... .*/ TransferTransaction receiver = new ContainerTransfer(); /* Now prepare the Receiver side. */ receiver.prepareReceiver( txc_rec.getSubContext(1)); /* Start. */ receiver.begin(); /* Obtain the results. */ Result = receiver.getObject();