com.limegroup.gnutella.search
Class QueryHandler

java.lang.Object
  extended bycom.limegroup.gnutella.search.QueryHandler

public final class QueryHandler
extends java.lang.Object

This class is a factory for creating QueryRequest instances for dynamic queries. Dynamic queries adjust to the varying conditions of a query, such as the number of results received, the number of nodes hit or theoretically hit, etc. This class makes it convenient to rapidly generate QueryRequests with similar characteristics, such as guids, the query itself, the xml query, etc, but with customized settings, such as the TTL.


Field Summary
static int MAX_QUERY_TIME
          Constant for the maximum number of milliseconds the entire query can last.
 
Method Summary
static QueryHandler createHandler(QueryRequest query, ReplyHandler handler, ResultCounter counter)
          Factory constructor for generating a new QueryHandler for the given QueryRequest.
static QueryHandler createHandlerForNewLeaf(QueryRequest query, ReplyHandler handler, ResultCounter counter)
          Factory constructor for generating a new QueryHandler for the given QueryRequest.
static QueryHandler createHandlerForOldLeaf(QueryRequest query, ReplyHandler handler, ResultCounter counter)
          Factory constructor for generating a new QueryHandler for the given QueryRequest.
static QueryRequest createQuery(QueryRequest query, byte ttl)
          Factory method for creating new QueryRequest instances with the same guid, query, xml query, urn types, etc.
 byte[] getGUID()
           
 ReplyHandler getReplyHandler()
          Accessor for the ReplyHandler instance for the connection issuing this request.
 long getTimeToWaitPerHop()
          Accessor for the time to wait per hop, in milliseconds, for this QueryHandler.
 boolean hasEnoughResults()
          Returns whether or not this query has received enough results.
 void sendQuery()
          Sends the query to the current connections.
 java.lang.String toString()
           
 void updateLeafResults(int numResults)
          Use this to modify the number of results as reported by the leaf you are querying for.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_QUERY_TIME

public static final int MAX_QUERY_TIME
Constant for the maximum number of milliseconds the entire query can last. The query expires when this limit is reached.

See Also:
Constant Field Values
Method Detail

createHandler

public static QueryHandler createHandler(QueryRequest query,
                                         ReplyHandler handler,
                                         ResultCounter counter)
Factory constructor for generating a new QueryHandler for the given QueryRequest.

Parameters:
handler - the ReplyHandler for routing the replies
counter - the ResultCounter that keeps track of how many results have been returned for this query
Returns:
the QueryHandler instance for this query

createHandlerForOldLeaf

public static QueryHandler createHandlerForOldLeaf(QueryRequest query,
                                                   ReplyHandler handler,
                                                   ResultCounter counter)
Factory constructor for generating a new QueryHandler for the given QueryRequest.

Parameters:
handler - the ReplyHandler for routing the replies
counter - the ResultCounter that keeps track of how many results have been returned for this query
Returns:
the QueryHandler instance for this query

createHandlerForNewLeaf

public static QueryHandler createHandlerForNewLeaf(QueryRequest query,
                                                   ReplyHandler handler,
                                                   ResultCounter counter)
Factory constructor for generating a new QueryHandler for the given QueryRequest.

Parameters:
handler - the ReplyHandler for routing the replies
counter - the ResultCounter that keeps track of how many results have been returned for this query
Returns:
the QueryHandler instance for this query

createQuery

public static QueryRequest createQuery(QueryRequest query,
                                       byte ttl)
Factory method for creating new QueryRequest instances with the same guid, query, xml query, urn types, etc.

Parameters:
ttl - the time to live of the new query
Returns:
a new QueryRequest instance with all of the pre-defined parameters and the specified TTL

sendQuery

public void sendQuery()
Sends the query to the current connections. If the query is not yet ready to be processed, this returns immediately.


hasEnoughResults

public boolean hasEnoughResults()
Returns whether or not this query has received enough results.

Returns:
true if this query has received enough results, false otherwise

updateLeafResults

public void updateLeafResults(int numResults)
Use this to modify the number of results as reported by the leaf you are querying for.


getReplyHandler

public ReplyHandler getReplyHandler()
Accessor for the ReplyHandler instance for the connection issuing this request.

Returns:
the ReplyHandler for the connection issuing this request

getTimeToWaitPerHop

public long getTimeToWaitPerHop()
Accessor for the time to wait per hop, in milliseconds, for this QueryHandler.

Returns:
the time to wait per hop in milliseconds for this QueryHandler

toString

public java.lang.String toString()

getGUID

public byte[] getGUID()
Returns:
simply returns the guid of the query this is handling.