| By P.G. Sarang, Ninad Kamerkar | Article Rating: |
|
| February 4, 2007 05:00 PM EST | Reads: |
12,089 |
Once the FilesearchAglet reaches the remote machine, it sends itself the atRemote message. The message handler for this calls the atRemote method. The code inside the atRemote method creates a separate thread for searching the files on the remote system. The search is done in a thread so it can be interrupted when desired. If we don't create a separate thread for searching the FileSearchAglet won't be able to listen to the messages sent by the MainFileAglet.
Below is the code snippet for the atRemote method of FileSearchAglet:
private void atRemote()
{
//.....
//Creating a thread for searching the file.
thread = new SearchThread();
//Start the thread.
thread.start();
//.....
}
When the search thread is started it calls the run method of the SearchThread class, which is the inner class of the FileSearchAglet. The run method of the SearchThread Class contains the code that controls the search operation. The code first checks the search criteria to see if the user wants to search the entire system or just a particular folder. If it's a particular folder then the code checks to see if the folder exists on the remote machine. If it does then the search method is called with the folder to search and the file name as an argument. If it doesn't then a message is sent to the MainFileAglet saying that the folder doesn't exist on the remote machine:
if(searchData.folder) //Specified folder.
{
File dir = new File(""+searchData.folder
ToSearch);
if (dir.exists())
{
//call the serach method.
search(dir,""+searchData.fileName);
}
else
{
//Send the file name and the remote url
//where the file if found to the user.
MainAgletProxy.sendOnewayMessage(
new Message("Results",
""+dir.getAbsolutePath()+" DOES NOT EXIST ON "
+""+searchData.remoteUrl));
}
}
If the user wants to search the entire system the code finds the list of drives on the remote machine and searches for the required file one by one on each drive by calling the search method with the appropriate arguments:
File[] roots=File.listRoots();
//Searching the file in all drives one-by-one of the remote system.
for(int x=0;x<roots.length;x++)
{
//call the serach method.
search(roots[x],""+searchData.fileName);
}
The search method contains the actual logic of the file search. This method is a recursive method. It checks whether the file in the argument is a file or directory.
If it's a file it checks whether the name matches the required file name and then sends a Results message to the MainFileAglet with the entire path of the file. If the argument file is a directory then it lists the files and folders in the directory and recursively checks this list of files and folders one by one by calling itself.
Below is the code snippet of the search method of the FileSearchAglet:
private void search(File dir, String name)
{
//Check whether the current file name matches
//the specified file name or not.
if(dir.getName().toLowerCase().indexOf(name.toLowerCase())!=-1)
{
//......
MainAgletProxy.sendOnewayMessage(
new Message(
"Results", ""+dir.getAbsolutePath()+" | "+searchData.remoteUrl));
//......
}
else if(dir.isDirectory()) //if the file is a folder.
{
//Get the list of files in this folder.
String[] children=dir.list();
for(int i=0;i<children.length;i++)
{
//......
search(new File(dir,children[i]),name);
//......
}
}
}
Published February 4, 2007 Reads 12,089
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 Now Open
- 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
- Industry Experts Discuss the State of Cloud Computing
- Deputy CIO of the CIA to Keynote 1st Annual GovIT Expo
- SOA World Power Panel on SYS-CON.TV
- CIA was Headed to an Enterprise Cloud All Along: Jill Tummler Singer
- Cloud Expo New York Call for Papers Now Open
- 1st Annual Government IT Conference & Expo: Themes & Topics
- 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









Cloud computing is a game changer. The cloud ...

















