Aglets Workbench

To Aglets Workbench Home pageThe Searcher Application

Description

Troubleshooting

Program Description

This program is composed of the following classes:

The Searcher Class

The Searcher class inherits the SampleAglet abstract class for a stationary aglet (see a description of the SampleAglet abstract class here). Its go method creates the slave aglet.

    private final static String SlaveClassName
              = "ibm.aglets.samples.SearcherSlave";

    void go(Vector destinations, String str) { 
      super.go((URL)(destinations.firstElement()));
      try {
         Slave.create(null, SlaveClassName, getAgletContext(), 
                      this, new SeqItinerary(destinations), str);
      } catch (IOException ae) {
        .....
      }
    }   

The slave is given an itinerary of several remote aglet servers (specified by destination parameter which is a vector of URLs) and a string to be matched against file names (the str parameter) . The Searcher aglet is considered the slave's master (specified by the this parameter to the Slave.create method).

In every remote aglet server, the slave creates a new SearcherInfo object which includes the name of the host and a vector with the names of the matched files. These objects are accumulated and finally become the result of the slave (see ahead).

The Searcher aglet, as a master, receives the slave's result (handled by the callback method) and error messages which are sent by the slave whenever its fails to perform a local search (handled by the inError method). The callback method is overwritten to receive the slave's result (a vector of SearcherInfo objects) and to display (via the addResultList method) the names of all the matched files on the result panel of the dialog window.

   protected synchronized void callback(Object arg) {
      String ni;

      // Slave is back...
      setTheMessage("Searcher has returned");

      _fileList = (Vector)arg;

      for (int i = 0; i < _fileList.size(); i++) {
         SearcherInfo si= (SearcherInfo)(_fileList.elementAt(i));
         Vector v  = si.getFileList();
         String URLString = si.getURLString();
         for (int j=0; j < v.size(); j++) { 
             ((SearcherWindow)_msw).addResultList(
                SearcherInfo.getFullPathName(URLString,
                                             (String)(v.elementAt(j))));
         }
      }
   }

The handleMessage of the SampleAglet class is overwritten to accept a "status report" kind of messages which are sent by the SearcherSlave to indicate successful completion of local searches. The handling of these messages is done in the private statusReport method.

   public boolean handleMessage(Message msg) {
     if ("status report".equals(msg.kind)) { 
        statusReport((String)(msg.getArg()));    
        return false;
     }
     else 
        return super.handleMessage(msg);
   }


The SearcherSlave Class

The SearcherSlave class implements the abstract methods of the Slave class. These are initializeJob() and doJob(). In initializeJob(), the result instance variable of the slave class (used to save the final result of the task of the slave) is initialized to an empty vector which will accumulate all the local information (SearcherInfo objects) gathered in every remote aglet server.

   protected synchronized void initializeJob ()  {
      RESULT = new Vector();
   }
   protected synchronized void doJob() throws AgletException {
      String filename, readPath;

      filename = (String)ARGUMENT;
      _fileList = new Vector();

      //-- a slave is always untrusted
      readPath = getAgletContext().getProperty("aglets.tahiti.untrusted.read", "");

      //-- match the file names and collect into the _fileList variable
      if (!readPath.equals("")) {
         find(filename.toLowerCase(),    //-- case insensitive
              readPath.toLowerCase());
      } 

      ((Vector)RESULT).addElement(
         new SearcherInfo( getAgletContext().getHostingURL(), _fileList));

      //-- send "status report" message to the master
      reportMaster("Completed search");
   }

In doJob(), the slave retrieves the local directories (files) which are allowed to be accessed (read) and recursively traverse them to search all the files whose names includes the given string. The matched file names and the host name are saved in a new SearcherInfo object which is added to the result instance variable.

Source Code

You can further study the Searcher aglet in more detail by directly traversing the source code.


IBM home page | IBM Japan home page | Copyright | Trademark
Last modified: Fri December 27 12:00:00 JST 1996