Package uk.num.numlib.api
Class NumAPIImpl
- java.lang.Object
-
- uk.num.numlib.api.NumAPIImpl
-
- All Implemented Interfaces:
NumAPI
public class NumAPIImpl extends java.lang.Object implements NumAPI
This is the main class for using the num-client-library. Use the default constructor to use the DNS servers configured on your local machine, or override these by supplying a specific DNS host domain name using the alternative constructor.
-
-
Constructor Summary
Constructors Constructor Description NumAPIImpl()Default constructor to initialise the default DNS services and MODL services.NumAPIImpl(java.lang.String[] dnsHosts)Support multiple DNS hosts.NumAPIImpl(java.lang.String dnsHost, int port)Alternative constructor used to override the default DNS host and port.NumAPIImpl(DNSServices dnsServices, java.lang.String dnsHost)Alternative constructor used to override the default DNS hosts.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NumAPIContextbegin(java.lang.String moduleId, java.lang.String numId, int timeoutMillis)Initialise a new NumAPIContextBase object for a specific module/NUM ID combination.java.util.concurrent.Future<java.lang.String>retrieveNumRecord(NumAPIContext ctx, NumAPICallbacks handler, int timeoutMillis)This method uses the module context and the supplied Required User Variable values to obtain a fully expanded JSON object from DNS.voidsetPopulatorTopLevelZone(java.lang.String populatorTopLevelZone)Override the populatortop-level zone from 'num.uk' to 'myzone.com' for example.voidsetTCPOnly(boolean flag)Tell dnsjava to use TCP and not UDP.voidsetTopLevelZone(java.lang.String zone)Override the top-level zone from 'num.uk' to 'myzone.com' for example.voidshutdown()Stop any outstanding DNS queries still in the Executor.
-
-
-
Constructor Detail
-
NumAPIImpl
public NumAPIImpl()
Default constructor to initialise the default DNS services and MODL services.
-
NumAPIImpl
public NumAPIImpl(DNSServices dnsServices, java.lang.String dnsHost) throws NumInvalidDNSHostException
Alternative constructor used to override the default DNS hosts. Unit tests rely on this constructor.- Parameters:
dnsHost- The DNS host to override the defaults configured for the local machine.dnsServices- used to inject dummy DNS services for testing.- Throws:
NumInvalidDNSHostException- on error
-
NumAPIImpl
public NumAPIImpl(java.lang.String[] dnsHosts) throws NumInvalidDNSHostException, NumInvalidParameterExceptionSupport multiple DNS hosts.- Parameters:
dnsHosts- The DNS host String arraymto override the defaults configured for the local machine.- Throws:
NumInvalidDNSHostException- on errorNumInvalidParameterException- on error
-
NumAPIImpl
public NumAPIImpl(java.lang.String dnsHost, int port) throws NumInvalidDNSHostExceptionAlternative constructor used to override the default DNS host and port.- Parameters:
dnsHost- The DNS host to override the defaults configured for the local machine.port- The port to use on the DNS host.- Throws:
NumInvalidDNSHostException- on error
-
-
Method Detail
-
setTCPOnly
public void setTCPOnly(boolean flag)
Tell dnsjava to use TCP and not UDP.- Specified by:
setTCPOnlyin interfaceNumAPI- Parameters:
flag- true to use TCP only.
-
setTopLevelZone
public void setTopLevelZone(java.lang.String zone) throws NumInvalidParameterExceptionOverride the top-level zone from 'num.uk' to 'myzone.com' for example.- Specified by:
setTopLevelZonein interfaceNumAPI- Parameters:
zone- The top level zone to use for DNS lookups. Replaces the default of 'num.uk'- Throws:
NumInvalidParameterException- if the zone is null or empty
-
setPopulatorTopLevelZone
public void setPopulatorTopLevelZone(java.lang.String populatorTopLevelZone) throws NumInvalidParameterExceptionOverride the populatortop-level zone from 'num.uk' to 'myzone.com' for example.- Specified by:
setPopulatorTopLevelZonein interfaceNumAPI- Parameters:
populatorTopLevelZone- The populator top level zone to use for DNS lookups. Replaces the default of 'num.uk'- Throws:
NumInvalidParameterException- if the zone is null or empty
-
begin
public NumAPIContext begin(java.lang.String moduleId, java.lang.String numId, int timeoutMillis) throws NumBadModuleIdException, NumBadModuleConfigDataException, NumBadURLException, NumInvalidParameterException, NumBadRecordException, NumDNSQueryException, NumInvalidDNSQueryException, RrSetNoHeadersException, RrSetHeaderFormatException, RrSetIncompleteException
Initialise a new NumAPIContextBase object for a specific module/NUM ID combination. The returned context object can be used to obtain the list of required user variables that must be set before moving on to retrieveNumRecord().- Specified by:
beginin interfaceNumAPI- Parameters:
moduleId- E.g. "1" for the Contacts module.numId- a domain name, URL, or email address that identifies the location in DNS of a NUM record.timeoutMillis- the timeout in milliseconds to wait for responses from DNS.- Returns:
- a new NumAPIContextBase object.
- Throws:
NumBadModuleIdException- on errorNumBadModuleConfigDataException- on errorNumBadURLException- on errorNumInvalidParameterException- on errorNumBadRecordException- on errorNumDNSQueryException- on errorNumInvalidDNSQueryException- on errorRrSetIncompleteException- on errorRrSetHeaderFormatException- on errorRrSetNoHeadersException- on error
-
retrieveNumRecord
public java.util.concurrent.Future<java.lang.String> retrieveNumRecord(NumAPIContext ctx, NumAPICallbacks handler, int timeoutMillis)
This method uses the module context and the supplied Required User Variable values to obtain a fully expanded JSON object from DNS. The supplied handler will be notified when the results are available or an error occurs.- Specified by:
retrieveNumRecordin interfaceNumAPI- Parameters:
ctx- The context object returned by the begin() method.handler- a handler object to receive the JSON results or processing errors.timeoutMillis- the maximum duration of each DNS request, the total wait time could be up to 4 times this value.- Returns:
- A Future object
-
-