Welcome!

SOA & WOA Authors: David Deans, Salvatore Genovese, Yeshim Deniz, Christopher Keene, Mark O'Neill

Related Topics: PowerBuilder

PowerBuilder: Article

Mobile Agent-Based File Search Utility

Creating a utility that can search for any desired document on multiple remote machines simultaneously

File Transfer Agent (Slave)
The File Transfer Agent (Slave) is the third agent in our application and like the File Search Agent it doesn't have a GUI. Figure 3 shows the Master Agent screen containing the search results. When the user selects one of the files from the search results and clicks the Fetch & Open button, this agent is created and dispatched to the remote machine on which the File Search Agent found the file. This agent is responsible for bringing the actual contents of the selected file to the sender machine. So it moves to the remote machine to read the contents from the selected file. After gathering the contents it comes back to the sender machine and gives the fetched contents to the Main File Agent. The Main File Agent then asks the user to save the contents to a file on the local disk. After saving the contents, the Main File Agent opens the file in its registered native editor for the user to review or edit. This agent disposes of itself once it's transferred a file.

It is created again when the user wants to do the next file transfer operation. In the similar way the user can select another file from the list and send this agent to bring the contents of the next file maybe from another remote machine by clicking on the Fetch & Open button.

Application Dataflow
Figure 4 depicts the complete dataflow in the application.

The communication between the requestor and the remote machine takes place as follows:

  1. The user creates and sends a File Search Agent to the remote machine to search for a specified file.
  2. After reaching the remote machine the File Search Agent searches for the required file and sends the results back to the client machine.
  3. The user selects the required file from a list of results displayed on the file search GUI and sends a File Transfer Agent to bring back the contents of that file.
  4. The File Transfer Agent comes back with the required file and asks the user to save it on the local disk so he can view it.
  5. The user can stop the search operation at any point simply by sending a message to stop the search to the File Search Agent.
A Closer Look at the GUI
The GUI contains an input box called File Name\Extension where the user can enter the file name\extension to be searched on the remote machine. The user has the option of searching the entire remote system or only a particular remote folder. Next he has to enter the remote URL in the URL input box. The Search Path (Drive\Folder) input box should contain the folder to be searched. When the user clicks the ADD button the remote URL and search path is added to the Remote URL list box. This way the user can enter any number of Remote URL and search paths to the Remote URL list box. He can also delete any of these elements from the Remote URL using the delete button. Once the list as specified above is ready, the user can click the START button. This sends one copy of FileSearchAglet per Remote URL so that the search can be done in parallel on all specified remote machines.

A search in progress can be stopped in two ways. The user can select a desired path from the Remote URL list box and click the STOP button to stop the search on that remote location. The user can stop the entire search on all the remote machines by clicking the STOP ALL button.

As the search progresses on remote machines, the results are displayed in the Search Result list box. The results contain the remote path on which the required file was found and the URL of that remote machine as shown in Figure 3. The user can select the required file from that list box and click on the Fetch & Open button to get the contents of the file from the Remote URL mentioned in the element selected from the list box.

Application Code
The MainFileAglet is the main and the starting aglet of our file search utility. This agent is also called the Master Agent because it controls the other agents. It is a stationary aglet because it doesn't move on the network. This aglet stores the IDs of the created FileSearchAglets in a vector:

//This vector stores the IDs of the aglets created for search.
Vector agletIdVector=new Vector();

The MainFileAglet creates a FileSearchAglet for each search path. Each aglet is identified by a unique ID that's used to obtain its proxy. All the aglets communicate with each other using their proxies.

MainFileAglet provides the GUI through which the user enters the file search criteria and controls the other agents. When this aglet is first launched on the Tahiti server (the installation of the Aglet development kit and the Tahiti server is provided at the end of the document), its onCreation method is executed first where we create the user interface:

//Creating object of MainAgletGui class to show the GUI for this aglet.
SearchGUI=new MainAgletGui(this);

We pass a reference to the MainFileAglet in the constructor of the MainAgletGui. Using this reference the GUI code obtains a reference to SearchGUI object that contains the search criteria. The user interface is depicted in Figure 2.

Starting the Search
Once the list containing the Remote URL and the Search folder is ready the user can click the START button. When the START button is clicked the code checks if a search is in progress. If so then the user gets a warning message that asks him to stop the current search and start a new one:

//checking whether any aglets exist or not
if(MainAglet.agletIdVector.size()>0)
{
JOptionPane.showMessageDialog(frame,
"Please stop all the agents before"
+" starting new search.","WARNING",JOptionPane.WARNING_MESSAGE);
}

The code checks if a search is in progress by getting the size of the vector that contains the IDs of the aglet that have been created in the previous search.

If no aglet exits it checks to see if the Remote URL list box and File Name input box are empty. It then calls the broadCastAglets method on the MainFileAglet:

else
{
   //checking whether Remote URL list box & whether
//txtFileName input box is empty or not.
if (addressVector.size()>0 && txtFileName.getText()!="")
{
     MainAglet. broadCastAglets();
}
else
{
     JOptionPane.showMessageDialog(frame,"Please enter filename"
       +"& remote location to search in \"Remote Url\"." ,
       "WARNING", JOptionPane.WARNING_MESSAGE);
}
}


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.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.