6.4 Application Programming Interfaces 229
A migration strategy might include several transfers. As it must be an
atomic command that is executed either with all its transfers or none at all,
Kalong provides a common technique for transaction management, called
two-phase-commit (2PC) protocol.
The idea of the 2PC protocol is as follows: All commands that modify the
agent context information, either locally at the current agency or remotely at
any of the destination agencies, must be bracketed by the following transac-
tion management commands. To start a transaction, the following method
must be used.
public void startTransaction( String agentName ) throws KalongException
Starts a transaction. Throws an exception if a transaction is already running.
After this method has been called, no other thread can start a transaction
using this agent until the transaction terminates.
To explain the 2PC protocol, we assume that several connections have
been opened to different remote agencies. After all messages have been sent,
the agent manager must send a prepare message (ﬁrst phase) using the
public boolean prepare( String agentName )
Sends a prepare message to all receiver agencies. The reply informs about success.
Kalong maintains a list of all connections that were opened since the last
call of method startTransaction. Method prepare sends a prepare
message to all receiver agencies. Each receiver answers, whether the last
transfer was successful or not. Method prepare collects these reply mes-
sages and returns true if all receiver agencies have accepted the transfer
and false if at least one agency has not accepted the transfer.
The agent manager must now send either a commit or rollback message
to all receiver agencies (second phase) with regard to the result of the pre-
vious method. Both methods close all network connections and terminate
public void commit( String agentName )
Sends a commit message to all receiver agencies.