| By P.G. Sarang, Ninad Kamerkar | Article Rating: |
|
| February 4, 2007 05:00 PM EST | Reads: |
12,089 |
Starting the File Transfer
The search results are displayed on the MainFileAglet GUI in a Search Results list box. The user can select an element containing the path to the located file from this list box and click the FETCH & OPEN button to call the createFileTransferAglet method on the MainFileAglet with the file path and Remote URL as an argument:
MainAglet.createFileTransferAglet(
filePath.replace('\\','/'),remoteUrl.trim());
In the createFileTransferAglet the code actually creates the FileTransferAglet on the local machine. FileTransferAglet is responsible for bringing the sought file from the remote machine to the local machine. As with the FileSearchAglet, the FileTransferAglet is first created on the local machine and the proxy of the MainFileAglet is passed as an argument:
AgletProxy proxy=context.createAglet(homeUrl,
"examples.newfilesearch.FileTransferAglet",getProxy());
When the FileTransferAglet is created, its onCreation method is executed. The method receives a reference to the MailFileAglet as its argument. This proxy is used by the FileTransferAglet to send messages to the MainFileAglet.
Below is the code snippet of the onCreation method of FileTransferAglet:
public void onCreation(Object proxy)
{
//Getting the proxy of the aglet who created this aglet.
MainAgletProxy=(AgletProxy)proxy;
//....
We also create an itinerary for the FileTransferAglet that dispatches this aglet from one machine to another:
//Creating an itinerary object to control
//the travel path of this aglet.
itinerary = new SimpleItinerary(this);
The code then compiles data for the file transfer by instantiating the FileTransferData class. The file transfer data contains the remote file path and the Remote URL that contains the file sought:
//Creating an object of the "FileTransferData" class.
FileTransferData fileTransferObj=
new FileTransferData(filePath,remoteUrl);
It then sends a message called Go to the created FileTransferAglet with the FileTransferData object as an argument:
//Sending message "Go" to the "File Transfer Agent" //with an argument with it.
proxy.sendOnewayMessage(new Message("Go",(Object)fileTransferObj));
The Go message is processed by the handleMessage method of the FileTransferAglet. The message handler retrieves the file transfer data from the message and then calls the startTrip method:
public boolean handleMessage(Message msg)
{
//.....
else if(msg.sameKind("Go"))
{
//Getting the argument send with this message.
fileTransObj=(FileTransferData)msg.getArg();
remoteUrl=fileTransObj.remoteUrl;
filePath=fileTransObj.filePath;
startTrip();
}
//....
}
The startTrip method dispatches the aglet to the appropriate machine:
private void startTrip()
{
//.....
//Dispatch this aglet to remote machine as specified
//in file search criteria and sends message "atRemote"
//to itself when it reaches the remote machine.
itinerary.go(""+remoteUrl, "atRemote");
//.....
}
Once the FileTransferAglet reaches the remote machine, it sends itself the atRemote message. The message handler for this aglet calls the atRemote method. The code inside the atRemote method creates an inputstream to read from the required file and then reads the bytes into a byte buffer. Once it's read the bytes from the file it dispatches itself back to the home location, i.e., the user machine:
private void atRemote()
{
//....
//Creating byte array to hold the contents of the file.
fileTransObj.bytes = new byte[(int)len];
int offset = 0;
int numRead = 0;
//Putting the contents of the file into the bytes array.
while(offset< fileTransObj.bytes.length
&& (numRead=is.read(fileTransObj.bytes, offset,
fileTransObj.bytes.length - offset )) >= 0)
{
offset += numRead;
}
// Dispatch this agent to user machine.
itinerary.go(homeUrl, "atHome");
//....
}
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 ...






















