p2ps.imp.endpoint
Class AbstractEndpointResolver

java.lang.Object
  extended byp2ps.imp.endpoint.AbstractEndpointResolver
All Implemented Interfaces:
EndpointMessageListener, EndpointResolver
Direct Known Subclasses:
TCPResolver, UDPResolver

public abstract class AbstractEndpointResolver
extends java.lang.Object
implements EndpointResolver, EndpointMessageListener

Version:
$Revision: 295 $
Author:
Ian Wang

Constructor Summary
AbstractEndpointResolver()
           
AbstractEndpointResolver(MessageProtocolHandlerFactory factory)
           
 
Method Summary
 void dataMessageReceived(DataMessageEvent event)
          Called when the endpoint receives a data message
 EndpointResolverAdvertisement getAdvertisement()
           
 java.lang.String[] getGroupIDs(java.net.URI uri)
           
 MessageProtocolHandlerFactory getMessageProtocolHandlerFactory()
           
protected  Peer getPeer()
           
 java.lang.String getPeerID(java.net.URI uri)
           
 java.lang.String getPipeID(java.net.URI uri)
           
 Endpoint[] getResolverEndpoints()
           
 java.net.URI getResolverEndpointURI(java.lang.String scheme)
           
 java.net.URI[] getResolverEndpointURIs()
           
 java.lang.String[] getResolverForPeerIDs()
           
 void handleEndpointQuery(EndpointQuery query)
          Replies to a resolver query (if the pipe is known to this resolver)
 void init(Peer peer)
          Initialises the endpoint resolver
protected abstract  Endpoint initResolverSocket()
          Initialize and return an endpoint for receive EndpointQueries (or null if EndpointQueries not handled)
 boolean isEndpointScheme(java.lang.String scheme)
           
 boolean isPipeScheme(java.lang.String scheme)
           
 boolean isSchemeInputEnabled(java.lang.String scheme)
           
 boolean isSchemeOutputEnabled(java.lang.String scheme)
           
protected  void registerEndpoint(java.lang.String pipeid, Endpoint endpoint, boolean discovery)
          Adds an endpoint for the specified pipe id to the endpoint cache
 void resolveEndpoint(byte[] query, java.net.URI resolveruri)
          Sends out a pipe resolution query for the specified pipe to the specified pipe resolver address.
 void setSchemeEnabled(java.lang.String scheme, boolean input, boolean output)
          Sets whether input and output using the specified scheme is enabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface p2ps.endpoint.EndpointResolver
connectOutputEndpoint, createInputEndpoint, createInputEndpoint, getEndpointSchemes, getPipeSchemes
 

Constructor Detail

AbstractEndpointResolver

public AbstractEndpointResolver()

AbstractEndpointResolver

public AbstractEndpointResolver(MessageProtocolHandlerFactory factory)
Method Detail

init

public void init(Peer peer)
          throws java.io.IOException
Initialises the endpoint resolver

Specified by:
init in interface EndpointResolver
Throws:
java.io.IOException

initResolverSocket

protected abstract Endpoint initResolverSocket()
                                        throws java.io.IOException
Initialize and return an endpoint for receive EndpointQueries (or null if EndpointQueries not handled)

Throws:
java.io.IOException

getPeer

protected Peer getPeer()
Returns:
the peer instance

getMessageProtocolHandlerFactory

public MessageProtocolHandlerFactory getMessageProtocolHandlerFactory()
Returns:
the MessageProtocolHandlerFactory

getPipeID

public java.lang.String getPipeID(java.net.URI uri)
Specified by:
getPipeID in interface EndpointResolver
Returns:
the pipe id from a URI (null if unkown scheme or uri does not contain pipe id)

getPeerID

public java.lang.String getPeerID(java.net.URI uri)
Specified by:
getPeerID in interface EndpointResolver
Returns:
the peer id from a URI (null if unkown scheme or uri does not contain the peer id)

getGroupIDs

public java.lang.String[] getGroupIDs(java.net.URI uri)
Specified by:
getGroupIDs in interface EndpointResolver
Returns:
an array of group ids from a URI (null if unkown scheme)

isEndpointScheme

public boolean isEndpointScheme(java.lang.String scheme)
Specified by:
isEndpointScheme in interface EndpointResolver
Returns:
true if the specified scheme is an endpoint scheme

isPipeScheme

public boolean isPipeScheme(java.lang.String scheme)
Specified by:
isPipeScheme in interface EndpointResolver
Returns:
true if the specified scheme is an pipe scheme

setSchemeEnabled

public void setSchemeEnabled(java.lang.String scheme,
                             boolean input,
                             boolean output)
Sets whether input and output using the specified scheme is enabled

Specified by:
setSchemeEnabled in interface EndpointResolver

isSchemeInputEnabled

public boolean isSchemeInputEnabled(java.lang.String scheme)
Specified by:
isSchemeInputEnabled in interface EndpointResolver
Returns:
true if input using the specified scheme is enabled

isSchemeOutputEnabled

public boolean isSchemeOutputEnabled(java.lang.String scheme)
Specified by:
isSchemeOutputEnabled in interface EndpointResolver
Returns:
true if output using the specified scheme is enabled

getResolverEndpoints

public Endpoint[] getResolverEndpoints()
Specified by:
getResolverEndpoints in interface EndpointResolver
Returns:
the resolver endpoint

getResolverEndpointURIs

public java.net.URI[] getResolverEndpointURIs()
                                       throws java.io.IOException
Specified by:
getResolverEndpointURIs in interface EndpointResolver
Returns:
the address of the resolver socket
Throws:
java.io.IOException

getResolverEndpointURI

public java.net.URI getResolverEndpointURI(java.lang.String scheme)
                                    throws java.io.IOException
Specified by:
getResolverEndpointURI in interface EndpointResolver
Returns:
the address of the resolver endpoint for the specified scheme (null if no endpoint for specified scheme)
Throws:
java.io.IOException

getResolverForPeerIDs

public java.lang.String[] getResolverForPeerIDs()
Specified by:
getResolverForPeerIDs in interface EndpointResolver
Returns:
the ids of the peers this resolver handles enpoint resolution for

getAdvertisement

public EndpointResolverAdvertisement getAdvertisement()
                                               throws java.io.IOException
Specified by:
getAdvertisement in interface EndpointResolver
Returns:
a pipe resolver advert for this resolver
Throws:
java.io.IOException

resolveEndpoint

public void resolveEndpoint(byte[] query,
                            java.net.URI resolveruri)
                     throws java.io.IOException
Sends out a pipe resolution query for the specified pipe to the specified pipe resolver address.

Specified by:
resolveEndpoint in interface EndpointResolver
Parameters:
query - the id of the pipe being resolved
resolveruri - the address of the endpoint resolver
Throws:
java.io.IOException

registerEndpoint

protected void registerEndpoint(java.lang.String pipeid,
                                Endpoint endpoint,
                                boolean discovery)
                         throws java.io.IOException
Adds an endpoint for the specified pipe id to the endpoint cache

Throws:
java.io.IOException

handleEndpointQuery

public void handleEndpointQuery(EndpointQuery query)
                         throws java.io.IOException
Replies to a resolver query (if the pipe is known to this resolver)

Throws:
java.io.IOException

dataMessageReceived

public void dataMessageReceived(DataMessageEvent event)
Description copied from interface: EndpointMessageListener
Called when the endpoint receives a data message

Specified by:
dataMessageReceived in interface EndpointMessageListener