| By P.G. Sarang, Ninad Kamerkar | Article Rating: |
|
| February 4, 2007 05:00 PM EST | Reads: |
12,079 |
In the broadcastAglets method of the MainFileAglet, FileSearchAglet is created. To create the FileSearchAglet we first have to get the context in which the MainFileAglet is launched and that's done by calling the getAgletContext method, which returns the context of the MainFileAglet:
//Getting the context in which this aglet is running.
AgletContext context = getAgletContext();
Once we have the context, we call the createAglet method on this context. The createAglet method takes three arguments. The first one is the URL where we launch the aglet. In our case we create the FileSearchAglet on the same machine on which the MainFileAglet is created, i.e., the user machine. We write the first argument as the return value of the getCodeBase method. The getCodeBase method returns the URL where MainFileAglet is running. The second argument is the name of the aglet file that contains the code of the FileSearchAglet. In the third argument we pass the proxy of the MainFileAglet using the method getProxy. The FileSearchAglet gets the proxy in its onCreation method when it's created:
//Creating the "File Search Agent".
AgletProxy proxy = context.createAglet(
getCodeBase(),
examples.newfilesearch.FileSearchAglet", getProxy());
When the FileSearchAglet is created, its onCreation method is executed. The method receives a reference to MailFileAglet as its argument. This proxy is used by the FileSearchAglet to send messages to the MainFileAglet:
public void onCreation(Object proxy)
{
//Getting the proxy of the aglet who created this aglet.
MainAgletProxy=(AgletProxy)proxy;
//
Then we create an itinerary for the FileSearchAglet, which dispatches this aglet from one machine to another. The SimpleItinerary class is a built-in class that helps us create an itinerary object that can specify a destination and a message to send to the owner aglet when it arrives at its destination. This is a very flexible class that lets us change both the destination and the message easily. We pass the current aglet as an argument to the constructor of the SimpleItinerary class to create the itinerary object for this aglet:
//Creating an itinerary object to control
//the travel path of this aglet
itinerary = new SimpleItinerary(this);
After the aglet is created, the ID of each aglet that was created is stored in the vector for future use. To create the ID, we call the getAgletID method on the proxy object that returns the ID of the aglet that holds that proxy. This ID is very important if the MainFileAglet wants to communicate with the aglet that it created, i.e., the FileSearchAglet. The ID is unique and can be used to get the proxy of that aglet for communicating with that aglet:
//Adding the AgletID of the aglet created to a vector.
agletIdVector.addElement((Object)proxy.getAgletID());
The code then compiles data for file searching by instantiating the SearchData class. The data for the file search contains the file name, the folder to search, the Remote URL, and whether to search the whole system or just a particular folder. It is called the File Search Criterion:
SearchData obj=new SearchData();
//Putting the search criteria in the SearchData object.
obj.fileName=SearchGUI.txtFileName.getText();
obj.folderToSearch= (
(String)SearchGUI.folderToSearchVector.elementAt(i)).replace('\\','/');
obj.remoteUrl=(String)SearchGUI.addressVector.elementAt(i);
if (((String)SearchGUI.folderOrSystemVector.elementAt(i)).equals(
"FOLDER"))
{
obj.folder=true;
}
else
{
obj.folder=false;
}
After the File Search Criterion is compiled this way, the code sends a message called FileSearchCriterion to the created FileSearchAglet with FileSearchCriterion as an argument:
//Send message "FileSearchCriterion" to the aglet
//created with the SearchData object as argument.
proxy.sendOnewayMessage(
new Message("FileSearchCriterion", (Object)obj));
Up until now the FileSearchAglet was created on the local machine. When the FileSearchAglet gets the FileSearchCriterion message, it retrieves the File Search Criterion from the SearchData object and dispatches itself to the URL specified in the File Search Criterion. The FileSearchAglet dispatches itself to the remote machine by calling the go method on the itinerary object. The go method takes two arguments. The first argument is the remote URL to which the FileSearchAglet needs to be dispatched. The second argument is the message to be sent by FileSearchAglet to itself when it reaches the destination machine. In this case the message is called atRemote:
public boolean handleMessage(Message msg)
{
//Handling the message "FileSearchCriteria" send by
//"Main File Agent".
if(msg.sameKind("FileSearchCriteria"))
{
//Retrieving the SearchData object sent by
//"Main File Agent". This SearchData object contains
//the file search criteria for searching.
searchData=(SearchData)msg.getArg();
//Dispatch this aglet to remote machine as specified in
//file search criteria and send message "atRemote"
//to itself when it reaches the remote machine.
//.....
itinerary.go(""+searchData.remoteUrl, "atRemote");
//......
}
//......
}
Published February 4, 2007 Reads 12,079
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By P.G. Sarang
Dr. Sarang in his long tenure of 20+ years has worked in various capacities in the IT industry. Dr. Sarang currently holds the position of Director (Architecture) with Kynetia, Spain and has been a Consultant to Sun Microsystems for last several years. He has previously worked as a Visiting Professor of Computer Engineering at University of Notre Dame, USA and is currently an adjunct faculty in the Univ. Dept. of Computer Science at University of Mumbai. Dr. Sarang has spoken in number of prestigious international conferences on Java/CORBA/XML/.NET and has authored several articles, research papers, courseware and books.
More Stories By Ninad Kamerkar
Ninad Kamerkar is currently pursuing a master's degree in computer science at the University of Mumbai in India. His research interests involve mobile agents, networking, and distributed systems. Besides his studies, he is interested in painting and listening to music.
- The Top 150 Players in Cloud Computing
- Commercial vs Federal Cloud Computing
- Why IBM’s Server Chief Got Busted
- Industry Experts Discuss the State of Cloud Computing
- Cloud Expo New York Call for Papers Deadline December 15
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- US Federal Government is Major Cloud Computing Innovator
- Google Wave
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Adaptivity & Cloud Computing: Exclusive Q&A with CEO Tony Bishop
- 4th International Cloud Expo: Photo Album
- The Top 150 Players in Cloud Computing
- SYS-CON.TV: Cloud Computing Expo Power Panel
- Commercial vs Federal Cloud Computing
- Why IBM’s Server Chief Got Busted
- 1st Annual GovIT Expo: Letter from the Technical Chair
- Deputy CIO of the CIA to Keynote 1st Annual GovIT Expo
- Industry Experts Discuss the State of Cloud Computing
- SOA World Power Panel on SYS-CON.TV
- CIA was Headed to an Enterprise Cloud All Along: Jill Tummler Singer
- 1st Annual Government IT Conference & Expo: Themes & Topics
- Cloud Expo New York Call for Papers Deadline December 15
- Stock in Focus: Dragon Capital
- The i-Technology Right Stuff
- Who Are The All-Time Heroes of i-Technology?
- Get the Message
- Where Are RIA Technologies Headed in 2008?
- i-Technology Viewpoint: Is Web 2.0 the Global SOA?
- i-Technology Viewpoint: Thinking Outside the VC Box
- ESB Myth Busters: 10 Enterprise Service Bus Myths Debunked
- i-Technology Viewpoint: When to Leave Your First IT Job
- SOA Web Services Edge Conference Coverage on SYS-CON.TV
- Five Reasons Why Web 2.0 Matters
- SYS-CON.TV's "SOA Web Services" and "Enterprise Open Source" Programs To Air in December
- SOA World Conference & Expo SYS-CON.TV Power Panel Live From Times Square









There are a variety of applications that supp...

























