O'Reilly logo

Mobile Agents by Wilhelm R. Rossak, Peter Braun

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

228 Chapter 6 Specifications of the Kalong Mobility Model
Table 6.1
Comparison of the four agency types
Agency type Data items Code units Cardinality
Home  1
Remote 1
Code server 0..n
Mirror 0..1
6.4 Application Programming Interfaces
6.4.1 Interface IKalong
Interface IKalong defines the main functions of the Kalong component.
It is used by the agent manager to access an agent’s context and to
define a migration strategy. The protocol definition is given as a set of
methods with arguments and results in Java syntax. A description of the
function of each method should provide enough infor mation to allow its
implementation.
The agent manager at the sender agency communicates with Kalong in
two phases. First, it registers an agent with Kalong so that Kalong can verify
that all used classes are available for transmission and the agent as well as all
its components are serializable. Second, it uses the services of this interface
to conduct the migration process.
We divide the methods of IKalong in four groups:
1. Methods to start and stop transactions.
2. Methods to register agents and define code units.
3. Methods to modify a local agent context.
4. Methods to transfer agent information via the network.
Almost all methods receive an agent name as a parameter to identify
the agent context. All methods of interface IKalong are assumed to work
synchronously.
Throughout this book the term current agency always refers to the agency
on which the commands are executed.
6.4 Application Programming Interfaces 229
Manage Transactions
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 (first phase) using the
following method.
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
the transaction.
public void commit( String agentName )
Sends a commit message to all receiver agencies.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required