org.apache.james.dnsserver
Class DNSServer

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.james.dnsserver.DNSServer
All Implemented Interfaces:
org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.logger.LogEnabled, DNSService, DNSServerMBean

public class DNSServer
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable, DNSService, DNSServerMBean

Provides DNS client functionality to services running inside James


Field Summary
protected  org.xbill.DNS.Cache cache
          A TTL cache of results received from the DNS server.
protected  org.xbill.DNS.Resolver resolver
          A resolver instance used to retrieve DNS records.
 
Fields inherited from interface org.apache.james.api.dnsservice.DNSService
ROLE
 
Constructor Summary
DNSServer()
           
 
Method Summary
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
           
 java.util.Collection findMXRecords(java.lang.String hostname)
          Return a prioritized unmodifiable list of host handling mail for the domain.
 java.util.Collection findTXTRecords(java.lang.String hostname)
          Get a collection of DNS TXT Records
 java.net.InetAddress[] getAllByName(java.lang.String host)
           
 java.net.InetAddress getByName(java.lang.String host)
           
 java.lang.String[] getDNSServers()
          Return the list of DNS servers in use by this service
 java.lang.String getHostName(java.net.InetAddress addr)
           
 java.net.InetAddress getLocalHost()
           
 org.xbill.DNS.Name[] getSearchPaths()
          Return the list of DNS servers in use by this service
 java.util.Iterator getSMTPHostAddresses(java.lang.String domainName)
          Returns an Iterator over org.apache.mailet.HostAddress, a specialized subclass of javax.mail.URLName, which provides location information for servers that are specified as mail handlers for the given hostname.
 void initialize()
           
protected  org.xbill.DNS.Record[] lookup(java.lang.String namestr, int type, java.lang.String typeDesc)
          Looks up DNS records of the specified type for the specified name.
protected  org.xbill.DNS.Record[] lookupNoException(java.lang.String namestr, int type, java.lang.String typeDesc)
           
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resolver

protected org.xbill.DNS.Resolver resolver
A resolver instance used to retrieve DNS records. This is a reference to a third party library object.


cache

protected org.xbill.DNS.Cache cache
A TTL cache of results received from the DNS server. This is a reference to a third party library object.

Constructor Detail

DNSServer

public DNSServer()
Method Detail

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Throws:
org.apache.avalon.framework.configuration.ConfigurationException
See Also:
Configurable.configure(Configuration)

initialize

public void initialize()
                throws java.lang.Exception
Specified by:
initialize in interface org.apache.avalon.framework.activity.Initializable
Throws:
java.lang.Exception
See Also:
Initializable.initialize()

getDNSServers

public java.lang.String[] getDNSServers()

Return the list of DNS servers in use by this service

Specified by:
getDNSServers in interface DNSServerMBean
Returns:
an array of DNS server names

getSearchPaths

public org.xbill.DNS.Name[] getSearchPaths()

Return the list of DNS servers in use by this service

Returns:
an array of DNS server names

findMXRecords

public java.util.Collection findMXRecords(java.lang.String hostname)
                                   throws TemporaryResolutionException
Description copied from interface: DNSService

Return a prioritized unmodifiable list of host handling mail for the domain.

First lookup MX hosts, then MX hosts of the CNAME adress, and if no server is found return the IP of the hostname

Specified by:
findMXRecords in interface DNSService
Parameters:
hostname - domain name to look up
Returns:
a unmodifiable list of handling servers corresponding to this mail domain name
Throws:
TemporaryResolutionException - get thrown on temporary problems
See Also:
DNSService.findMXRecords(String)

lookup

protected org.xbill.DNS.Record[] lookup(java.lang.String namestr,
                                        int type,
                                        java.lang.String typeDesc)
                                 throws TemporaryResolutionException
Looks up DNS records of the specified type for the specified name. This method is a public wrapper for the private implementation method

Parameters:
namestr - the name of the host to be looked up
type - the type of record desired
typeDesc - the description of the record type, for debugging purpose
Throws:
TemporaryResolutionException

lookupNoException

protected org.xbill.DNS.Record[] lookupNoException(java.lang.String namestr,
                                                   int type,
                                                   java.lang.String typeDesc)

getSMTPHostAddresses

public java.util.Iterator getSMTPHostAddresses(java.lang.String domainName)
                                        throws TemporaryResolutionException
Description copied from interface: DNSService
Returns an Iterator over org.apache.mailet.HostAddress, a specialized subclass of javax.mail.URLName, which provides location information for servers that are specified as mail handlers for the given hostname. This is done using MX records, and the HostAddress instances are returned sorted by MX priority. If no host is found for domainName, the Iterator returned will be empty and the first call to hasNext() will return false. The Iterator is a nested iterator: the outer iteration is over the results of the MX record lookup, and the inner iteration is over potentially multiple A records for each MX record. DNS lookups are deferred until actually needed.

Specified by:
getSMTPHostAddresses in interface DNSService
Parameters:
domainName - - the domain for which to find mail servers
Returns:
an Iterator over HostAddress instances, sorted by priority
Throws:
TemporaryResolutionException - get thrown on temporary problems
See Also:
DNSService.getSMTPHostAddresses(String)

getByName

public java.net.InetAddress getByName(java.lang.String host)
                               throws java.net.UnknownHostException
Specified by:
getByName in interface DNSService
Throws:
java.net.UnknownHostException
See Also:
DNSService.getByName(String)

getAllByName

public java.net.InetAddress[] getAllByName(java.lang.String host)
                                    throws java.net.UnknownHostException
Specified by:
getAllByName in interface DNSService
Throws:
java.net.UnknownHostException
See Also:
DNSService.getAllByName(String)

findTXTRecords

public java.util.Collection findTXTRecords(java.lang.String hostname)
Description copied from interface: DNSService
Get a collection of DNS TXT Records

Specified by:
findTXTRecords in interface DNSService
Parameters:
hostname - The hostname to check
Returns:
collection of strings representing TXT record values
See Also:
DNSService.findTXTRecords(String)

getHostName

public java.lang.String getHostName(java.net.InetAddress addr)
Specified by:
getHostName in interface DNSService
See Also:
DNSService.getHostName(java.net.InetAddress)

getLocalHost

public java.net.InetAddress getLocalHost()
                                  throws java.net.UnknownHostException
Specified by:
getLocalHost in interface DNSService
Throws:
java.net.UnknownHostException
See Also:
DNSService.getLocalHost()


Copyright ? 2002-2009 The Apache Software Foundation. All Rights Reserved.