Class HandleResolver

java.lang.Object
net.handle.hdllib.HandleResolver
All Implemented Interfaces:
RequestProcessor

public class HandleResolver extends Object implements RequestProcessor
Responsible for locating and retrieving the value of handles using a caching server, or on the internet.
  • Field Details

    • traceMessages

      public boolean traceMessages
  • Constructor Details

    • HandleResolver

      public HandleResolver()
  • Method Details

    • getExecutorService

      public ExecutorService getExecutorService()
    • setExecutorService

      public void setExecutorService(ExecutorService execServ)
    • protocolsByPreference

      public int[] protocolsByPreference()
      Return a copy of preferredProtocols[], wherein protocols are listed in order of preference. For use by methods which do not have access to the private int-array.
    • retrieveHandleIndexData

      public byte[] retrieveHandleIndexData(byte[] handle, int index) throws Exception
      this method will retrieve the handle values by the given handle/index pair Now only used to retrieve public key data in veryfying the session setup data.
      Throws:
      Exception
    • setCache

      public void setCache(Cache cache)
      Gives the resolver a Cache object to use when resolving. When sending requests, the cache will be checked for the handle instead of always using the network. Setting the cache object to null will cause the resolver to not use any cache.
    • setCertifiedCache

      public void setCertifiedCache(Cache cache)
      Gives the resolver a Cache object to use for certified resolutions. When sening certified resolution requests, this cache will be checked for the handle instead of always using the network. Setting the cache object to null will cause the resolver to not use any cache for certified resolutions. Note: It is important to never use the same cache (or backing storage) for the certified and regular cache. Doing so could poison the certified cache with uncertified values.
    • clearCaches

      public void clearCaches() throws Exception
      Clear any caches being used by this resolver
      Throws:
      Exception
    • setSessionTracker

      public void setSessionTracker(ClientSessionTracker sessionTracker)
      Gives the resolver a session tracker object to use when resolving. When sending administrative requests and the resolver's session tracker is non-null, it is used to establish (or continue) a session with whatever server is being communicated with. Note: If there is a sessionInfo or session tracker already associated with a request, then the resolver's session tracker is ignored. Warning: If this resolver is going to be used in several administrative contexts (ie with several different admin IDs) because authenticated sessions could possibly be used by a different administrator than was intended.
    • getSessionTracker

      public ClientSessionTracker getSessionTracker()
      Returns the current default session tracker.
    • setConfiguration

      public void setConfiguration(Configuration config)
      Set the configuration used for resolution. This configuration indicates whether requests are processed using a network cache (ala DNS) or if we determine the appropriate server via global.
    • setPreferredProtocols

      public void setPreferredProtocols(int[] prefProtocols)
      Set the protocols and the order of preference used for resolution For every server that this resolver talks to, it attempts to communicate via the given protocols either until it succeeds or all attempts to communicate fail. If a client is behind a firewall and not using a caching server then it would be best to set the preferred protocols to Interface.SP_HDL_TCP and Interface.SP_HDL_HTTP since the Interface.SP_HDL_UDP will probably just get blocked by firewalls and be a big waste of time.
    • setMaxUDPDataSize

      public void setMaxUDPDataSize(int newMaxUDPDataSize)
      Set the maximum size of the data part of a message before it is split into multiple messages when using UDP.
    • getMaxUDPDataSize

      public int getMaxUDPDataSize()
      Return the maximum size of the data part of a message before it is split into multiple messages when using UDP.
    • getConfiguration

      public Configuration getConfiguration()
      Get the resolution configuration
    • setTcpTimeout

      public void setTcpTimeout(int newTcpTimeout)
      Set how long to wait for responses to TCP and HTTP requests.
    • getTcpTimeout

      public int getTcpTimeout()
      Get how long to wait for responses to TCP requests.
    • isUseIPv6FastFallback

      public boolean isUseIPv6FastFallback()
    • setUseIPv6FastFallback

      public void setUseIPv6FastFallback(boolean useIPv6FastFallback)
    • getSiteFilter

      public SiteFilter getSiteFilter()
    • setSiteFilter

      public void setSiteFilter(SiteFilter siteFilter)
    • getUdpRetryScheme

      public int[] getUdpRetryScheme()
      Get the array that specifies how long to wait for responses to each UDP request. The length of this array will indicate how many UDP requests to send before giving up. The default scheme is something like {1000, 2000, 3000} which is 1 second, 2 seconds, 3 seconds.
    • setUdpRetryScheme

      public void setUdpRetryScheme(int[] newudpRetryScheme)
      Set the array that specifies how long to wait for responses to each UDP request. The length of this array will indicate how many UDP requests to send before giving up. The default scheme is something like {1000, 2000, 3000} which is 1 second, 2 seconds, 3 seconds.
    • setCheckSignatures

      public void setCheckSignatures(boolean checkSigs)
      Set whether or not this object should check the signatures of server responses to certified requests. The default is to check signatures and throw an exception if a signature to any certified message is missing or invalid.
    • resolveHandle

      public HandleValue[] resolveHandle(String sHandle, String[] sTypes, int[] indexes) throws HandleException
      Locate and return the values of the given handle that have the specified types or indexes. This method simply creates a ResolutionRequest object from the given parameters and calls processRequest with that request object. The requested handle values are then extracted from the response and returned (or an exception is thrown if there was an error). Creating your own ResolutionRequest objects and calling processRequest directly allows more flexibility since you can set the certified, authoritative, and recursive flags of the request. When specifying both a set of types or indexes, a server will return all handle values that have the requested types as well as all handle values that have the requested indexes. Essentially, the union of the set of handles with the requested types and the set of handles with the requested indexes is returned. An empty index or type list indicates that any index or type is acceptable. The following examples describe how the type and index lists are used in resolutions:
        Type-List       Index List       Returns
         [ URL ]         [ 0, 12 ]       Any URL values, as well as values
                                          with indexes 0 and 12 if they exist.
         [ ]             [ 1 ]           The value with index one only
         [ EMAIL ]       [ ]             Any values with type EMAIL
         [ ]             [ ]             All of the values associated with the
                                          given handle
      
      Throws:
      HandleException
    • resolveHandle

      public HandleValue[] resolveHandle(byte[] handle, byte[][] types, int[] indexes) throws HandleException
      Throws:
      HandleException
    • resolveHandle

      public HandleValue[] resolveHandle(String sHandle) throws HandleException
      Throws:
      HandleException
    • resolveHandle

      public HandleValue[] resolveHandle(byte[] handle) throws HandleException
      Throws:
      HandleException
    • resolveValueReference

      public HandleValue resolveValueReference(ValueReference valueReference) throws HandleException
      Throws:
      HandleException
    • listHandlesUnderPrefix

      public void listHandlesUnderPrefix(String prefixHandle, AuthenticationInfo authInfo, ScanCallback callback) throws HandleException
      Throws:
      HandleException
    • listHandlesUnderPrefixAtSite

      public void listHandlesUnderPrefixAtSite(String prefixHandle, SiteInfo site, AuthenticationInfo authInfo, ScanCallback callback) throws HandleException
      Throws:
      HandleException
    • processRequest

      public AbstractResponse processRequest(AbstractRequest req, ResponseMessageCallback callback) throws HandleException
      This method processes the given request using the currently configured method (global resolution, resolution against a caching server, etc), and returns the response. If a Cache object is available it will be used if the request is a ResolutionRequest and the authoritative flag of the request is not set. The AbstractResponse object that is returned can be either an ErrorResponse or a ResolutionResponse object. Check the responseCode of the AbstractResponse (or use the instanceof keyword) to determine if the response can safely be casted to a ResolutionResponse or not. If you determine that the response is a ResolutionResponse then you can cast the response and call getHandleValues() on it. The following is an example that requests all of the URL values associated with the handle 123/abc, and prints them to System.out.
      
       HandleResolver resolver = new HandleResolver();
       AbstractResponse aResponse = resolver.resolveHandle("123/abc",
                                                          new String[]{"URL"},
                                                          null);
       if(aResponse.responseCode==AbstractMessage.RC_SUCCESS) {
         ResolutionResponse response = (ResolutionResponse)aResponse;
         HandleValue values[] = response.getHandleValues();
         System.out.println("Received values: ");
         for(int i=0; i<values.length; i++) {
           System.out.println(String.valueOf(values[i]));
         }
       }
       
      Throws:
      HandleException
    • processRequest

      public AbstractResponse processRequest(AbstractRequest req) throws HandleException
      Shortcut to processRequest(req, null);
      Throws:
      HandleException
    • processRequest

      public AbstractResponse processRequest(AbstractRequest req, InetAddress caller) throws HandleException
      Specified by:
      processRequest in interface RequestProcessor
      Throws:
      HandleException
    • processRequest

      public void processRequest(AbstractRequest req, InetAddress caller, ResponseMessageCallback callback) throws HandleException
      Specified by:
      processRequest in interface RequestProcessor
      Throws:
      HandleException
    • processRequestGlobally

      public AbstractResponse processRequestGlobally(AbstractRequest req) throws HandleException
      Shortcut to processRequestGlobally(req, null);
      Throws:
      HandleException
    • findLocalSitesForNA

      public SiteInfo[] findLocalSitesForNA(byte[] naHandle) throws HandleException
      Throws:
      HandleException
    • findLocalSites

      public SiteInfo[] findLocalSites(AbstractRequest req) throws HandleException
      Get the site information for the service that is responsible for this handle while at the same time populating the namespace
      Throws:
      HandleException
    • getNAHandle

      @Deprecated public byte[] getNAHandle(byte[] handle)
      Deprecated.
      Legacy of slash-based delegation; use Util.getZeroNAHandle
      Find the prefix handle for a handle
    • getNAHandle

      @Deprecated public byte[] getNAHandle(ResolutionRequest resReq)
      Deprecated.
    • getNamespaceInfo

      public NamespaceInfo getNamespaceInfo(ResolutionRequest resReq) throws HandleException
      Throws:
      HandleException
    • sendRequestToService

      public final AbstractResponse sendRequestToService(AbstractRequest req, SiteInfo[] sites, ResponseMessageCallback callback) throws HandleException
      Throws:
      HandleException
    • sendRequestToService

      public AbstractResponse sendRequestToService(AbstractRequest req, SiteInfo[] sites) throws HandleException
      Shortcut to sendRequestToService(AbstractRequest, SiteInfo[], null);
      Throws:
      HandleException
    • sendRequestToSite

      public AbstractResponse sendRequestToSite(AbstractRequest req, SiteInfo site, int protocol) throws HandleException
      Shortcut to sendRequestToSite(AbstractRequest, site, protocol, null);
      Throws:
      HandleException
    • sendRequestToSite

      public AbstractResponse sendRequestToSite(AbstractRequest req, SiteInfo site, int protocol, ResponseMessageCallback callback) throws HandleException
      Throws:
      HandleException
    • sendRequestToServerInSiteByProtocol

      public AbstractResponse sendRequestToServerInSiteByProtocol(AbstractRequest req, SiteInfo site, ServerInfo server, int protocol, ResponseMessageCallback callback) throws HandleException
      Throws:
      HandleException
    • sendRequestToServer

      public AbstractResponse sendRequestToServer(AbstractRequest req, ServerInfo server) throws HandleException
      Shortcut to sendRequestToServer(AbstractRequest, ServerInfo, null);
      Throws:
      HandleException
    • sendRequestToServer

      public AbstractResponse sendRequestToServer(AbstractRequest req, SiteInfo site, ServerInfo server) throws HandleException
      Throws:
      HandleException
    • sendRequestToServer

      public AbstractResponse sendRequestToServer(AbstractRequest req, ServerInfo server, ResponseMessageCallback callback) throws HandleException
      Wrapper around sendRequestToServerByProtocol(), which used to have this name and signature. This is invoked by the code which formerly invoked the older method.
      Throws:
      HandleException
    • sendRequestToServer

      public AbstractResponse sendRequestToServer(AbstractRequest req, SiteInfo site, ServerInfo server, ResponseMessageCallback callback) throws HandleException
      Throws:
      HandleException
    • sendRequestToSite

      public AbstractResponse sendRequestToSite(AbstractRequest req, SiteInfo site) throws HandleException
      Sends the given request to the appropriate server in the given site and returns the response. This will try to contact the appropriate server by trying each of the preferred protocols, in order.
      Throws:
      HandleException
    • sendRequestToSite

      public AbstractResponse sendRequestToSite(AbstractRequest req, SiteInfo site, ResponseMessageCallback callback) throws HandleException
      Sends the given request to the appropriate server in the given site and returns the response. This will try to contact the appropriate server by trying each of the preferred protocols, in order.
      Throws:
      HandleException
    • setupSessionWithServer

      public ClientSideSessionInfo setupSessionWithServer(AbstractRequest req, SessionSetupInfo sessionOptions, ServerInfo server) throws Exception
      Create a new session to handle the given request.
      Throws:
      Exception
    • sendRequestToInterface

      public AbstractResponse sendRequestToInterface(AbstractRequest req, ServerInfo server, Interface interfce) throws HandleException
      Shortcut to sendRequestToInterface(AbstractRequest, ServerInfo, Interface, null);
      Throws:
      HandleException
    • sendRequestToInterface

      public AbstractResponse sendRequestToInterface(AbstractRequest req, ServerInfo server, Interface interfce, ResponseMessageCallback callback) throws HandleException
      Throws:
      HandleException
    • sendHdlUdpRequest

      public AbstractResponse sendHdlUdpRequest(AbstractRequest req, InetAddress addr, int port) throws HandleException
      Shortcut to sendHdlUdpRequest(req, addr, port, null);
      Throws:
      HandleException
    • sendHdlUdpRequest

      public AbstractResponse sendHdlUdpRequest(AbstractRequest req, InetAddress addr, int port, ResponseMessageCallback callback) throws HandleException
      Throws:
      HandleException
    • sendHdlTcpRequest

      public AbstractResponse sendHdlTcpRequest(AbstractRequest req, InetAddress addr, int port) throws HandleException
      Shortcut to sendHdlTcpRequest(req, addr, port, null);
      Throws:
      HandleException
    • sendHdlTcpRequest

      public AbstractResponse sendHdlTcpRequest(AbstractRequest req, InetAddress addr, int port, ResponseMessageCallback callback) throws HandleException
      Throws:
      HandleException
    • sendHttpRequest

      public AbstractResponse sendHttpRequest(AbstractRequest req, InetAddress addr, int port) throws HandleException
      Shortcut to sendHttpRequest(req, addr, port, null);
      Throws:
      HandleException
    • sendHttpRequest

      public AbstractResponse sendHttpRequest(AbstractRequest req, InetAddress addr, int port, ResponseMessageCallback callback) throws HandleException
      Throws:
      HandleException
    • sendHttpsRequest

      public AbstractResponse sendHttpsRequest(AbstractRequest req, InetAddress addr, int port, ResponseMessageCallback callback) throws HandleException
      Throws:
      HandleException