org.nhindirect.dns
Class DNSSocketServer

java.lang.Object
  extended by org.nhindirect.dns.DNSSocketServer
All Implemented Interfaces:
DNSSocketServerMBean
Direct Known Subclasses:
TCPServer, UDPServer

public abstract class DNSSocketServer
extends Object
implements DNSSocketServerMBean

The socket server is an IP protocol agnostic server that manages threading/concurrency and message dispatching to the concrete socket implementation. It utilizes a "smart" thread pool for efficiently managing processing threads.

Since:
1.0
Author:
Greg Meyer

Constructor Summary
DNSSocketServer(DNSServerSettings settings, DNSResponder responsder)
          Creates a socket server.
 
Method Summary
abstract  void createServerSocket()
          Creates and initializes the socket implementation that will accept incoming requests.
abstract  Runnable getDNSRequestTask(Object s)
          Gets the Runnable task that will process a DNS request.
 Long getRejectedRequestCount()
          Gets the number of requests that were rejected by the server due to being to busy.
 Long getResourceRequestCount()
          Gets the number of DNS requests received by the server.
 String getResourceRequestLoad()
          Gets the request load of the server.
abstract  Runnable getSocketAcceptTask()
          Gets the Runnable task that will be responsible for accepting connections.
 Long getUptime()
          Gets the time in milliseconds that the server has been running since its last start.
 void start()
          Starts the socket server and initializes the dispatch threads.
 void stop()
          Shuts down the socket server and terminates the server from accepting additional requests.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.nhindirect.dns.DNSSocketServerMBean
getErrorRequestCount, getMissedRequestCount, getSuccessfulRequestCount
 

Constructor Detail

DNSSocketServer

public DNSSocketServer(DNSServerSettings settings,
                       DNSResponder responsder)
                throws DNSException
Creates a socket server. The server will not start accepting messages until the start() method is called.

Parameters:
settings - The server settings. The settings contain specific IP and socket configuration parameters.
responsder - The DNS responder that will handle lookups.
Throws:
DNSException
Method Detail

start

public void start()
           throws DNSException
Starts the socket server and initializes the dispatch threads. After this method has been called, the server will start accepting DNS requests.

Throws:
DNSException

stop

public void stop()
          throws DNSException
Shuts down the socket server and terminates the server from accepting additional requests. The server attempts to gracefully shutdown the processing threads and gives currently running processing threads a chance to finish.

Throws:
DNSException

createServerSocket

public abstract void createServerSocket()
                                 throws DNSException
Creates and initializes the socket implementation that will accept incoming requests.

Throws:
DNSException

getSocketAcceptTask

public abstract Runnable getSocketAcceptTask()
Gets the Runnable task that will be responsible for accepting connections. This task is placed in a single thread, so it should loop until the running flag is set to false.

Returns:
The Runnable task that will be responsible for accepting connections

getDNSRequestTask

public abstract Runnable getDNSRequestTask(Object s)
Gets the Runnable task that will process a DNS request. Each accepted request will create a new instance of the Runnable task and run it in its own thread.

Parameters:
s - An arbitrary parameter passed to the Runnable task. This parameter generally contain the DNS request information. This may be the TCP socket from the accept() server socket call or a UDP datagram packet.
Returns:
The Runnable task that will process a DNS request

getUptime

public Long getUptime()
Gets the time in milliseconds that the server has been running since its last start.

Specified by:
getUptime in interface DNSSocketServerMBean
Returns:
The time in milliseconds that the server has been running since its last start.

getRejectedRequestCount

public Long getRejectedRequestCount()
Gets the number of requests that were rejected by the server due to being to busy. A high number of rejected requests indicates that the server should be reconfigured to accept a higher load.

Specified by:
getRejectedRequestCount in interface DNSSocketServerMBean
Returns:
The number of requests that were rejected by the server due to being to busy.

getResourceRequestCount

public Long getResourceRequestCount()
Gets the number of DNS requests received by the server.

Specified by:
getResourceRequestCount in interface DNSSocketServerMBean
Returns:
The number of DNS requests received by the server.

getResourceRequestLoad

public String getResourceRequestLoad()
Gets the request load of the server. Load is returned in number of requests per second averaged over the last 5 seconds.

Specified by:
getResourceRequestLoad in interface DNSSocketServerMBean
Returns:
The request load of the server.


Copyright © 2010-2015 The Direct Project. All Rights Reserved.