I will start by talking about remote method invocation before I move down to agent mobility. Remote Method Invocation (RMI) is a common way nowadays via which we can have services or objects residing on remote machines and can call those functions from a local machine.

It’s pretty interesting how it is done. Over here we will not go into the details of how it works, but here is a picture that might help you visualize what is going on.

The coding complexity is not huge but what is happening under the hood is a bit tricky to understand. So lets get this straight using RMI we can actually call a function of an object which is not residing in the same machine my code is running.

Now what if instead of our software being able to call a function on the remote object we could have our object himself travel over the network. Sounds interesting, then fasten your seat belt and read on how it is done.

This is a pretty interesting concept called Object or Agent mobility. We can send in an object over the network which will wake up on another machine and then it can do some specified task, and then come back. Pretty interesting isn’t it. Here is a picture to visualize it.


So now what we have here is instead of calling a function of a remote object we are sending our own object to go to another remote machine and do some processing over there and then come back with results. If we can make our objects intelligent and they have mobility then we can do wonders.

An example and usage of this agent mobility is distributed search, where we can have multiple agents with different AI in them traveling to different servers and extracting information and then coming back from where they started. All the results of the agents can be deduced to a meaningful search result. For a moment think wild and I am sure you will come up with dozen of other useful things you can do, since now you know something like this can be done. And top of it is it not cool that your software is actually roaming around the network.

The implementation portion is not rocket science at all so here is a bit of idea how it is done. The implementation is two folded.

1- How to transfer objects from one machine to another.
2 – How to receive and send back the object

The first question is simple to answer. We need to learn how to transfer objects via networks. In Java for both TCP and UDP transfer we have functions to pass a serialized object. So this can be used to throw our object to the remote machine.

For the second question, we should make our server aware of the fact that they will and can receive such objects, so on receiving such an object it will know which function of the object to call to start the object and the object should in turn know which function of the server to call to be able to go back home. As the Sever should have some mechanism to throw back an object, the server will get the home address (home ip) of the object from its data and then throw him back functions. Therefore in short there should be a specified interface an agent should follow so that based on that interface the remote machine can call up some functions of the agent. And also the server should have a defined interface so that the agent can call the remote machines function. For a bit of more clarification here are interfaces that may get you started off.

Interface Mobile Agents


Interface of Agent Receiving Server


Apart from the implementations of this interfaces you will need another class or function which will create, initialize the object and throw it to a server and wait to receive the object back, when it is thrown back by the server.

Please note, the server should be listening on a specified port all the time and will receive the objects. On getting an object it will call the objects agentArrived(…) function. When the object decides it wants to go back to home it will call the servers agentSendBackToHome (…) function. The agent might or can travel to another server instead of going home and that can be achieved by calling the servers agentMigrate(..) function.

I hope this post sheds a bit of light on agent mobility. And now its time to play around with this and make interesting stuff. Have fun !