![]() |
Distributed Systems Lab 2003 |
||||||||||||||||||||||||||||||||
|
![]() |
Lab 2: Searching for fileGeneral ExplanationsOverviewIf you still have not read the overview description , ... hmmm, but wait: how did you implement lab 1? Anyway, we encourage you to do it now (and not continue cheating)! This example teaches RMI client and server programming. In a first step, you create the client functionality to search for files, i.e., iterate through all available peers and ask them whether they have shareable files matching the search string. In the second task, you implement the server part of the RMI communication. This requires you to create an RMI registry and register your search engine so that it can be looked up by other clients. In the end, you can search for files and will receive search results from all available hosts. (Guess what ... you are implementing something like Kazaa, FreeNet, Napster or similar) Reading SuggestionsThe one crucial resource for this lab is the RMI tutorial ! There you'll find all necessary explanations on how RMI works and what it means to write an RMI client and an RMI server. Read the RMI tutorial carfully and make sure you understand what a remote interface and its implementation is, how the rmic compiler works, and why a RMI registry is necessary. Hint: Note that in the lab you MUST NOT use an RMI security manager (or any other security manager for this matter). Deliverable (Submission)Execute the following command line (in a single line!) in the $HOME/src directory of your lab account. Recall that your submissions are only accepted if they are done from your lab account! tar cvfz - `find . -name "*.java"` | uuencode submission.tgz | mail -s 2 rnabgabe@dslab.tuwien.ac.at Task DescriptionsTask 2.1: Searching for filesThe first task is to implement the RMI client to search for files. The idea is to specify a search string and check all available peers whether they have files whose names match the given criteria. We start with the implementation of the search() method in the ShareMeImpl class. Use the search string as first parameter to create a new ISearchRequest instance using the given SearchRequestImpl class. If null is passed in as search parameter, throw a ShareMeException . The second parameter is the signature of the request - we currently use null . The third parameter is the human readable name of your peer as specified in the properties with the IConstants.HUMAN_READABLE_NAME key. Next, create an empty ISearchResult by instantiating a new object from the SearchResultImpl class. Hint: Note that the human readable name from the property file is NOT the same as the RMI URL! Iterate through your host list and extract the RMI registry host, the registry port and the RMI service name from the IHostInfoMessage objects of the currently available hosts and create the RMI URL conforming to the syntax described below: (again, do not use the curly brackets as part of the RMI URL!) rmi://{RMIRegistryHost}:{RMIRegistryPort}/{ServiceName} For each RMI URL get the remote ISearchEngine via the lookup() method of the Naming class. Then you can issue the search with the request created before and get the ISearchResponse back (this is the remote method call!). If a peer becomes unavailable in the mean time, catch the resulting exception and continue processing with the next host list entry. From the search response extract the IFileList and add it to the ISearchResult . When you finished iterating the host list, return the ISearchResult which contains all the IFileList objects. If no matches are found, return an empty ISearchResult object. Now you can compile your sources using ant lab2_1 and test your implementation with the at.ac.tuwien.infosys.rnue.helpers.search.SearchMain helper class. The command line looks like shown below: // check 'ant run2_1' for the exact command java -cp {Classpath} at.ac.tuwien.infosys.rnue.helpers.search.SearchMain {property-file} Hint: Expect that some of the servers might not work because they are not implemented yet (although they send 'IAmAlive' messages!) and thus not registered in the RMI registry. The DSG servers, however, will respond correctly! Start your searches with single letters to maximize the chance that another ShareMe peer will respond. Once you know what files are available on the server, limit your search to few hits to avoid too high loads on the servers. Hint: Note that also empty search strings are valid! A list of all files should be returned in this case. Hint: Since your host list also includes your own host you also search your own file base. Task 2.2: Share files with other peersAlthough we now can search for files, we cannot offer files on our own. The RMI server implementation will provide the necessary functionality. Every peer has a so-called 'file base' (defined in your property file) which denotes the directory where the files which you want to share with others are placed. Hint: Do not use your home-directory as filebase. If you do so others can peek into your home-directory and after you have implemented lab 4 they are also able to download your files! Instead create separate directories for the document and for the file base. To implement an RMI server, you first have to implement the at.ac.tuwien.infosys.rnue.implementation.search.SearchEngineImpl class which extends UnicastRemoteObject and implements the remote interface ( ISearchEngine ). In the constructor create an instance of the IFileSystemHelper interface using the FileSystemHelperImpl class. The constructor takes the file base of your server as string, a download prefix (another string) and an instance of ISecurityHelper ; expect the security helper parameter to be null for the moment. We'll add it later. The constructor can throw a ShareMeException or RemoteException . Now implement the search() method of the ISearchEngine interface. The method gets the search request (of type ISearchRequest ) as parameter. You only have to retrieve the search string from the request and call the IFileSystemHelper.searchFor() method. The returned array of IFile objects has to be added to a new IFileList instance of the FileListImpl class. Eventually, return a new ISearchResponse (using the SearchResponseImpl class); again use null for the signature parameter of the SearchResponseImpl constructor. It will be added in lab 3. As before, the final task is to integrate the new functionality with the ShareMeImpl class. In the ShareMeImpl.start() method, create a local registry using the LocateRegistry.createRegistry(int port) method with the port of your local registry as specified in the property file (use IConstants.RMI_REGISTRY_PORT as key). Then create a new instance of your SearchEngineImpl class with the filebase retrieved from the properties using the IConstants.FILE_BASE key. The second parameter of the constructor is the download URL prefix. This string represents the full HTTP URL where the file can be downloaded. This includes the protocol (http), the host name, the port and the path descriptor as specified in IConstants.DOWNLOAD_PREFIX . This is necessary to return a fully qualified download location in the search result - later in lab 4 the client will depend on this information. The security helper parameter remains null for lab 2. Then Register your server object with the registry using the Naming.rebind() method. Use the full RMI URL as name parameter of the rebind() method. In the ShareMeImpl.stop() method you have to unregister the server object from the registry (using Naming.unbind() ) and additionally call UnicastRemoteObject.unexportObject() to remove the reference to the server object (the unbind() method only unregisters the stub from the registry!). After finishing the implementation of the server, you can compile all your sources using the provided build.xml file and the lab2_2 target. Look at the build.xml file to understand (and remember for the exam) how the rmic (RMI compiler) is executed on the SearchEngineImpl class! Only then, the necessary stubs will be created. Hint: If you encounter problems creating or using the registry, take a look at the FAQ entry discussing various uses of the registry and naming classes. Now you can again test your RMI implementation using the command line described above. Check again 'ant run2_2' for the exact command to be executed. Your server should now respond correctly to search requests. |
![]() |
||||||||||||||||||||||||||||||
![]() |
![]() |
||||||||||||||||||||||||||||||||
Powered by MyXML |
Last update on:
2003-03-13
© 2001 Distributed Systems Group |