p2ps.imp.discovery
Class QueryHandler

java.lang.Object
  extended byp2ps.imp.discovery.QueryHandler
All Implemented Interfaces:
PipeConnectionListener

public class QueryHandler
extends java.lang.Object
implements PipeConnectionListener

A class that handles adverts/queries.

Version:
$Revision: 295 $
Author:
Ian Wang

Constructor Summary
QueryHandler(DiscoveryCache cache, Peer peer)
           
 
Method Summary
 void cache(Advertisement advert)
          Adds an advert to the discovery cache (unless it is a direct query)
 DiscoveryCache getDiscoveryCache()
           
 void handleAdvert(Advertisement advert, OutputPipe replypipe)
          If the advert is a query, then searches the cache for adverts that match that specified query.
static boolean isDirectReplyQuery(Query query)
           
 void outpipeConnected(PipeConnectedEvent event)
          Called when an output pipe is successfully connected
 void outpipeConnectFailure(PipeConnectFailureEvent event)
          Called when an output pipe fails to connect.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryHandler

public QueryHandler(DiscoveryCache cache,
                    Peer peer)
Method Detail

getDiscoveryCache

public DiscoveryCache getDiscoveryCache()
Returns:
the discovery cache

cache

public void cache(Advertisement advert)
           throws java.io.IOException
Adds an advert to the discovery cache (unless it is a direct query)

Throws:
java.io.IOException

isDirectReplyQuery

public static boolean isDirectReplyQuery(Query query)
Returns:
true if the specified query is a direct reply query (no reply uri)

handleAdvert

public void handleAdvert(Advertisement advert,
                         OutputPipe replypipe)
                  throws java.io.IOException
If the advert is a query, then searches the cache for adverts that match that specified query. Any matches are sent to the query reply uri or, if no reply uri specified, returned using the receiving pipe.

Alternatively, queries that a requesting the advert are located from the cache and the advert is set to the query reply uri specified in those queries.

Parameters:
advert - the query advertisement
replypipe - an optional reply pipe to use if no direct pipe specified
Throws:
java.io.IOException

outpipeConnected

public void outpipeConnected(PipeConnectedEvent event)
Called when an output pipe is successfully connected

Specified by:
outpipeConnected in interface PipeConnectionListener

outpipeConnectFailure

public void outpipeConnectFailure(PipeConnectFailureEvent event)
Called when an output pipe fails to connect. Note that a pipe might have multiple connection failures before it succeeds.

Specified by:
outpipeConnectFailure in interface PipeConnectionListener