ISSearch
Class ISPeerTools

java.lang.Object
  extended byISSearch.ISPeerTools

public final class ISPeerTools
extends Object

This class provides some useful functions for RMI calls of the distributed Peer-to-Peer ISSEarch search engine.


Constructor Summary
ISPeerTools()
           
 
Method Summary
static byte[] getLocalIP()
          Returns the IP address of the current machine.
static ISPeerServerInterface getServer(String host, int port, String serviceName)
          Returns the reference to the RMI Server (Peer) of the distributed search engine.
static byte[] ID2IP(long id)
          Converts the numerical ID of the host into its IP address.
static long IP2ID(byte[] ipAddr)
          Converts the IP address represented by 4-byte array to the host ID of the ISSearch engine.
static String IP2String(byte[] ip)
          Converts the array representation of the IP address (array of 4 bytes) into text string.
static ISPeerResultInterface[] search(ISPeerServerInterface server, String query, int numResults)
          Invokes the remote search method of the RMI server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ISPeerTools

public ISPeerTools()
Method Detail

getServer

public static ISPeerServerInterface getServer(String host,
                                              int port,
                                              String serviceName)
                                       throws Exception
Returns the reference to the RMI Server (Peer) of the distributed search engine. The connection to the server is specified by three parameters: the hostname, the port, and the service name. When the new peer server starts, it submits these parameters to the central database of the ISSearch framework. The parameters are used by the client to establish the connection to the chosen server.

Parameters:
host - The hostname of the RMI server.
port - The port of the RMI service (default 1099).
serviceName - The service name of the ISSerach search engine on this RMI server.
Throws:
RemoteException - if the connection to the remote service cannot be established or fails.
Exception

search

public static ISPeerResultInterface[] search(ISPeerServerInterface server,
                                             String query,
                                             int numResults)
                                      throws Exception
Invokes the remote search method of the RMI server.

Parameters:
query - The query that is submitted by the client. The query syntax is prescribed by Assignment 4 (Query Processor).
numResults - The max number of matches that can be returned as search results for the query.
Returns:
The array of search results that contains up to numResults matches, sorted in descending order of similarity.
Throws:
RemoteException - or NotBoundException if the remote invocation of the search fails or the connection was not established.
Exception

IP2ID

public static long IP2ID(byte[] ipAddr)
Converts the IP address represented by 4-byte array to the host ID of the ISSearch engine. The host IDs are used to identify remote ISSearch servers.

Returns:
The numerical host ID.

ID2IP

public static byte[] ID2IP(long id)
Converts the numerical ID of the host into its IP address.

Returns:
The IP address that corresponds to this ID, as 4-byte array.

IP2String

public static String IP2String(byte[] ip)
                        throws UnknownHostException
Converts the array representation of the IP address (array of 4 bytes) into text string.

Parameters:
ip - The specified IP address as an 4-byte array.
Returns:
The textual representation of this IP address.
Throws:
UnknownHostException, - if the conversion fails.
UnknownHostException

getLocalIP

public static byte[] getLocalIP()
                         throws UnknownHostException
Returns the IP address of the current machine.

Returns:
The IP address of the current machine as an array of 4 bytes.
Throws:
UnknownHostException, - if the machine has no default network connection.
UnknownHostException