Mobile Agent platform Analysis and Comparison

Source: Internet
Author: User
1.1 mobile agent platform Analysis and Comparison

Although the essence of the mobile agent is the status when the mobile code and code are suspended, that is, when the object is moved from one host to another, we can implement it ourselves, for example, Java can be implemented through the serialization mechanism of Java. In C ++, we can also use DCOM. However, to implement mobile agents, we generally need to select a mature mobile agent development platform to accelerate development and save costs. The mobile agent development platform provides various public services for us to develop mobile agent-based programs. According to the existing implementation technology, the mobile agent system can be divided into two types: one is based on mobile code, such as telescript; the other is based on remote objects, such as aglet. The following is an analysis and comparison of the current mature Mobile Agent System Platform:

1. d' agent

D' agent (formerly known as Agent TCL) is a mobile agent system researched by Dartmouth University in the United States. It has evolved from supporting the single language Tcl to currently supporting multiple languages such as TCL, Java, and scheme. D' agent can automatically capture and restore the complete status of the mobile agent, which means that the agent can interrupt execution at any point and then move to another environment for further execution.

Communication basis: d'agent's high-level communication mechanism adopts different communication methods, such as RMI and kiaml. Its service program is multi-threaded and each proxy is executed in a separate process, this method simplifies implementation, but increases the communication overhead between processes.

Fault Tolerance service: the agent can be stored on physical media to prevent exceptions.

Security Service: d' agent uses a public key system to authenticate the agent. It uses static resource management to manage the access to resources by the agent. It can not only authorize access to a certain resource, but also restrict the use of the agent.

Communication Service: supports asynchronous or synchronous communication mode.

Lifecycle service: supports copying, cloning, and remote creation.

2. aglet

Aglet is a mobile agent technology developed by IBM in Japan using pure Java. It provides a practical platform-aglet workbench, allowing people to develop or execute mobile agent systems. So far, aglet is one of the most successful and comprehensive systems in the above case, mainly manifested in the following aspects:

(1) provides a simple and comprehensive mobile agent programming model.

(2) provides a dynamic and effective communication mechanism between agents.

(3) provides a detailed and easy-to-use security mechanism.

The word aglet is synthesized by the characters "agent" and "applet. In short, aglet is a Java Applet object with Agent behavior. But aglet transmits the Code and its status at the same time, while applet only transmits the code. The aglet is generated on one machine in the form of a thread, and the execution can be paused at any time. Then, the entire agent can be assigned to another machine and re-start the execution task. Because it occupies threads, it does not consume too much system resources.

3. Concordia

Concordia is a mobile agent system developed based on the Java language. It consists of the agent manager, security manager, queue manager, event manager, and service bridge modules. On each network node, Concordia is running a server on the Java Virtual Machine and is responsible for mobile, persistent, secure, and communication of the agent. Concordia focuses on system security and fault tolerance. The system security measures are bidirectional, protecting node resources and the mobile agent itself. Concordia's permission limit on the agent is mainly determined by the user, which is a difference between it and the Aglet system. Concordia
Communication uses the existing TCP/IP communication service. Its communication module provides the asynchronous communication mode and does not provide the synchronous communication mode. This is a shortcoming of the system.

4. Voyager

The Voyager of recursion can be regarded as an enhanced Object Request proxy (ORB). Compared with other mobile agent systems, Voyager is more closely integrated with the Java language, it can be used to develop mobile agent systems or to create traditional distributed systems. Voyager is a pure Java distributed computing platform that can be used to quickly generate high-performance distributed applications. It is an excellent mobile agent development platform that represents the current technical level.

5. grasshoper

Grasshoper is currently the first mobile agent system that complies with the masif and FIPA standards. The grasshoper environment includes the agent and domain registrar, which are interconnected through proprietary ORB (grasshoper orb. Agency (equivalent to the place in masif) is the actual runtime environment of the proxy. Several agency fields can be combined to form communication through Java RMI and socket connections. The entire communication structure adopts plug-in technology and has good scalability. In terms of Fault Tolerance services, the original execution status of the agent can be restored from the storage media after the system crashes.
The x09 certificate is implemented, and the security in transmission is guaranteed by SSL. Access control is implemented through custom security management, and digital authentication is implemented. Communication Service supports asynchronous or synchronous communication, dynamic message mechanism and multi-point transmission: supports replication, remote creation, cloning, and other operations in the lifecycle.

2.2
Mobile Agent support platform aglet

1. aglet System Framework

The aglet system framework 2.1 is shown in:


Figure 2.1 aglet System Framework

 

First, when an ongoing aglet wants to migrate itself to the remote end, it will send a request to the Aglet runtime layer; then, the Aglet runtime layer converts the Aglet status information and code into a serialized byte array. If the communication succeeds, the system sends the byte array to the ATCI (Agent transport and communication) interface. ATP is a simple application layer protocol. Then, the system attaches the relevant system information, such as the system name and aglet ID, to the byte array and transmits the information to the remote machine through the network in bit stream mode, the remote machine receives the byte array and system information from the system through the ATP interface provided by the ATCI layer. Finally, aglet
The runtime layer deserializes byte arrays to obtain the status information and code of aglet. At this time, aglet can be executed on a remote machine.

2. aglet Lifecycle

The aglet system provides a context to manage the basic behaviors of aglet, including create agent, clone agent, and dispatch) the process is as follows:


Figure 2.2 aglet Lifecycle

 

3. The package structure of the Aglet workbench and aglet

The aglet workbench is a visual environment used to build network applications using mobile agents. Currently, it provides the following tools:

(1) mobile agent framework.

(2) ATP ----- agent transmission protocol.

(3) tazza ----- visualization of the personalized mobile agent required for application development.

(4) JDBC ----- used to access the DB2 database.

(5) jodax ------ access unit data.

(6) Tahiti ----- visual Agent Management page.

(7) Fiji ----- implement lifecycle control on the web page.

Aglet contains the following packages:

Com. IBM. aglet: this package defines some APIs of aglet and provides common methods for managing the agent Context Environment and sending and receiving information.

Com. IBM. aglet. Event: this package implements the lifecycle in the object model.

Com. IBM. aglet. System: Mainly used to manage some functions in the runtime layer of aglet.

Com. IBM. aglet. util: provides some public classes, such as letaudioclip.

Com. IBM. aglet. patterns: contains common message transmission modes, such as master-slave and notifier-notification.

3 aglet practice 3.1 case requirements

Distributed Computing implements matrix multiplication.

Two machines in the LAN, one as the master and the other as the slave. The master creates a matrix class, creates a calculator class, and sends it to the slave machine for running. The master machine recycles the agent (result) after running the Server Load balancer, merges the running result with the machine, and displays the final result.

3.2 Program Implementation

Package examples. matrix;

Import com. IBM. aglet .*;

Import com. IBM. aglet. event .*;

Import com. IBM. aglet. util .*;

Import java. Lang. interruptedexception;

Import java. Io. externalizable;

Import java. Io. objectinput;

Import java. Io. objectoutput;

Import java. Io. ioexception;

Import java.net .*;

Import java. AWT .*;

Import java. AWT. event .*;

Import java. util. enumeration;

/** Author: Zhang Hua **/

Public class Matrix extends aglet {

Transient mydialog my_dialog = NULL; // no serialization

Url dgp = NULL; // client address

String message = NULL;

// Matrix Initialization

Int Matone [] [] = new int [10] [10];

Int mattwo [] [] = new int [10] [10];

Int matthr [] [] = new int [10] [10];

Boolean flag; // you can specify the flag quantity.

Int all = 0;

Agletproxy outer; // agent client address

// Set the initial window

Public void oncreation (Object init ){

Flag = true;

Setmessage ("choose remote machine and go! "); // Window display information

Creategui (); // create a window

}

// Create a window

Protected void creategui (){

My_dialog = new mydialog (this );

My_dialog.pack ();

My_dialog.setsize (my_dialog.getpreferredsize ());

My_dialog.setvisible (true );

}

// Window display information

Public void setmessage (string message ){

This. Message = message;

}

// Process Information

Public Boolean handlemessage (Message MSG ){

If (msg. samekind ("finish ")){

Output (MSG );

} Else if (msg. samekind ("starttrip ")){

Starttrip (MSG );

}Else {

Return false;

};

Return true;

}

// Report has been returned and destroyed

Public void output (Message MSG ){

Settext ("output begin ");

While (FLAG ){

Waitmessage (5*10 );

};

My_dialog.msg.append ("/N" + msg. getarg ("Answer"). tostring () + "/N ");

}

Public synchronized void starttrip (Message MSG) {// remote machine arrival

String Destination = (string) msg. getarg (); // obtain the remote machine address.

// Obtain the agent content from the client.

Try {

Outer = getagletcontext (). createaglet (null, "examples. matrix. Calculator", getproxy ());

} Catch (exception e) {settext ("wrong! ");};

Try {

DGP = new URL (destination); // DGP is the client address

} Catch (malformedurlexception e) {settext ("wrong! ");};

Try {

Outer. Dispatch (DGP); // send it to the client

} Catch (exception e) {settext ("wrong! ");};

Matrixrun (); // The task starts running on the local machine.

}

// Program on the local machine

Public void matrixrun (){

Settext ("matrixrun begin ");

For (INT x = 0; x <10; X ++ ){

For (INT y = 0; y <10; y ++ ){

Matone [x] [Y] = 1;

Mattwo [x] [Y] = 1;

Matthr [x] [Y] = 0;

}

};

For (INT x = 0; x <5; X ++ ){

For (INT y = 0; y <10; y ++ ){

For (INT z = 0; Z <10; Z ++ ){

Matthr [x] [Y] = matthr [x] [Y] + Matone [x] [Z] * mattwo [Z] [Y];

}

}

};

Flag = false;

String result = "";

For (INT x = 0; x <5; X ++ ){

For (INT y = 0; y <10; y ++ ){

Result = Result + "A [" + x + "] [" + Y + "] =" + matthr [x] [Y] + "";

}

}

// Print the local result

My_dialog.msg.append ("The result shows down:" + "/N" + Result + "/N" + "local is over! ");

Settext ("matrixrun over ");

}

}

// Mydialog window

Class mydialog extends frame implements windowlistener, actionlistener {

Private matrix aglet = NULL;

// Below are some gui Components

Private addresschooser DEST = new addresschooser ();

Public textarea MSG =

New textarea ("", 10, 20, textarea. scrollbars_vertical_only );

Private button Go = new button ("Go! ");

Private button close = new button ("close ");

// Create dialog box

Mydialog (matrix aglet ){

This. aglet = aglet;

Layoutcomponents ();

Addwindowlistener (this );

Go. addactionlistener (this );

Close. addactionlistener (this );

}

// Component Layout

Private void layoutcomponents (){

MSG. settext (aglet. Message );

Gridbaglayout grid = new gridbaglayout ();

Gridbagconstraints CNS = new gridbagconstraints ();

Setlayout (GRID );

CNS. weightx = 0.5;

Central. ipadx = Central. ipady = 5;

CNS. Fill = gridbagconstraints. horizontal;

CNS. insets = new insets (5, 5, 5 );

CNS. weightx = 1.0;

Central. gridwidth = gridbagconstraints. remainder;

Grid. setconstraints (DEST, CNS );

Add (DEST );

Central. gridwidth = gridbagconstraints. remainder;

CNS. Fill = gridbagconstraints. Both;

CNS. weightx = 1.0;

CNS. weighty = 1.0;

CNS. gridheight = 2;

Grid. setconstraints (MSG, CNS );

Add (MSG );

CNS. weighty = 0.0;

CNS. Fill = gridbagconstraints. None;

CNS. gridheight = 1;

Panel P = new Panel ();

Grid. setconstraints (p, CNS );

Add (P );

P. setlayout (New flowlayout ());

P. Add (GO );

P. Add (close );

}

// Event handling

Public void actionreceivmed (actionevent AE ){

// Process the "go" button

If ("Go! ". Equals (AE. getactioncommand ())){

Aglet. setmessage (msg. gettext ());

MSG. settext ("");

Try {

Agletproxy P = aglet. getproxy ();

P. sendonewaymessage (New message ("starttrip", dest. getaddress ()));

} Catch (exception e ){

E. printstacktrace ();

}

}

// Process the "close" button

Else if ("close". Equals (AE. getactioncommand ())){

Setvisible (false );

}

}

Public void windowclosing (incluwevent we ){

Dispose ();

}

Public void windowopened (incluwevent we ){

}

Public void incluwiconified (incluwevent we ){

}

Public void windowdeiconified (incluwevent we ){

}

Public void windowclosed (incluwevent we ){

}

Public void windowactivated (incluwevent we ){

}

Public void windowdeactivated (incluwevent we ){

}

}

// Calculator. Java

Package examples. matrix;

Import java. Lang. interruptedexception;

Import java. Io. externalizable;

Import java. Io. objectinput;

Import java. Io. objectoutput;

Import java. Io. ioexception;

Import java.net .*;

Import java. util. enumeration;

Import com. IBM. aglet .*;

/** Author: Zhang Hua **/

Public class calculator extends aglet {

Agletproxy proxy = NULL;

Int Matone [] [] = new int [10] [10];

Int mattwo [] [] = new int [10] [10];

Int matthr [] [] = new int [10] [10];

Public void oncreation (Object init ){

Settext ("creation begin ");

Try {

Proxy = (agletproxy) Init;

} Catch (exception e) {settext ("wrong! 1 ");};

}

Public void run (){

Settext ("Calculator begin ");

For (INT x = 0; x <10; X ++ ){

For (INT y = 0; y <10; y ++ ){

Matone [x] [Y] = 1;

Mattwo [x] [Y] = 1;

Matthr [x] [Y] = 0;

}

};

For (INT x = 0; x <5; X ++ ){

For (INT y = 0; y <10; y ++ ){

For (INT z = 0; Z <10; Z ++ ){

Matthr [x + 5] [Y] = matthr [x + 5] [Y] + Matone [x + 5] [Z] * mattwo [Z] [Y];

}

}

};

String result = "";

Settext ("sendonewaymsg begin ");

// Start from 5 on the client

For (INT x = 5; x <10; X ++ ){

For (INT y = 0; y <10; y ++ ){

Result = Result + "A [" + x + "] [" + Y + "] =" + matthr [x] [Y] + "";

}

};

// Return the result to the host

Try {

Message MSG = new message ("finish ");

MSG. setarg ("Answer", result );

System. Out. println (msg. getarg ("Answer "));

This. Proxy. sendonewaymessage (MSG );

} Catch (exception e) {settext ("wrong! 2 ");};

}

}

3.3 code analysis

In implementation, we adopt the master-slave mode, which is one of the many modes supported by aglet. It allows the master aglet to dispatch the task (dispatch) to the slave aglet,The code and status carried by aglet are moved to the specified target host. After combined with the local data resources for calculation, the calculated results are returned to the primary aglet..

1. First, notify the master agent to send a call command to a slave agent.

// Proxy of the master agent

Agletproxy P = aglet. getproxy ();

// Send a message to the master agent,

P. sendonewaymessage (

New message ("agletclient1", "ATP: // localhost: 82 "));

Communication between aglet and aglet refers to the delivery of message objects through message transmission. In addition, based on security considerations, aglet does not allow the outside world to directly access its information, but provides corresponding interfaces through a proxy to communicate with the outside world. The advantage of doing so is that the location of the Aglet will be transparent, that is, when the Aglet wants to communicate with the remote aglet, it will only generate a proxy corresponding to the remote aglet in the context of the local host, you can directly communicate with the proxy without having to directly handle network connection and communication issues.

2. Enter the message loop.

Public Boolean handlemessage (Message MSG)

{

If (msg. samekind ("finish "))

{

Processrosponseresult (MSG );

}

Else if (msg. samekind ("agletclient1 "))

{

Processagletclient1 (MSG );

}

Else

{

Return false;

};

Return true;

}

Both the master agent and slave agent must inherit from the agent class and overwrite the handlemessage () function of the message loop processing function of the super agent class. For example, the message received is agletclient1, the processagletclient1 (MSG) method will be executed.

3. In message processing functions, first obtain the local agent from the Environment (context), and then distribute the agent to the target host.


Figure 3.1 Message Processing Method

 

4. The data resources on the agent and the local host are combined for calculation, and the calculation result is returned through the message.


Figure 3.2 Sample Code from Agent

3.4 run the program

1) download the Aglet framework from the Internet. I downloaded: aglets-2.0.2.jar

2) unzip: jar xvf aglets-2.0.2.jar(Note: it cannot be installed in the Chinese directory)

3) execute the ant command:

4) set Java policy:


5) set environment variables:

Aglets_home = E:/Java/aglets2.02

Aglets_path = % aglets_home %

Path = % PATH %; % aglets_home %/bin

6) Put the compiled code in the % aglets_home %/public directory, for example:


7) Start aglet (the default user name is anonymous and the default password is aglets)

Shows the started agent platform:

8) create a primary agent (that is, the matrix class). Click "CREATE", as shown in the following figure:


Enter the full path name (package name and class name) of the matrix class in the Aglet Name field, and then click the create button, for example:


9) Send the Aglet to the slave machine for running and recycle the results.

Enter the address from aglet at adress: ATP: // localhost: 4434

(Note: Because I use a local machine, I write localhost to ensure that the Aglet service is enabled on the Agent machine)

The running result is shown in:


10) OK

4 Application Ideas of mobile agent technology in unified Jee cluster management

The mobile agent code can be moved on machines in various domains and calculated based on local machine resources.

1) centralized cluster management can be achieved through the master-slave structure of the mobile agent. For example, after an application is deployed on the master node of the cluster (equivalent to the master agent in aglet ), it is completely possible to switch the application from the agent to the word throttling and then move it to the nodes in the cluster for automatic deployment. In this way, this allows you to deploy a cluster application on only one machine, improving the user experience.

2) If the master node of the cluster wants to know the information of each slave node (such as the status information of the application itself, the JVM heap information, and even the memory CPU usage of the operating system) you can send the information collected from the agent to the node machine before returning it.

3) If the master node wants to control the slave node (such as start and stop), after the Protocol is defined, you can simply move from the agent code to the node machine to execute the operations required by the Protocol.

4) if the mobile agent is combined with the Ali command line framework, all management operations can be completed in the command line.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.