Exemplo n.º 1
0
  /**
   * Creates the service wrapper with the location of the configuration service and server settings.
   *
   * @param configLocation URL with the location of the configuration service.
   * @param settings Default settings for the server. Settings in the configuration service can over
   *     ride these settings.
   * @throws DNSException
   * @since 1.0
   */
  public DNSServerService(URL configLocation, DNSServerSettings settings) throws DNSException {
    LOGGER.info(
        "Creating the DNSServer using configuration location " + configLocation.toExternalForm());

    BasicDNSServerSettingsProvider settingsProv =
        new BasicDNSServerSettingsProvider(settings.getBindAddress(), settings.getPort());
    server = DNSServerFactory.createDNSServer(configLocation, null, settingsProv);

    LOGGER.info("DNS Server created.  Starting server.");
    server.start();

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              public void run() {
                try {
                  LOGGER.info("Shutdown hook detected.  Intiate server shutdown.");
                  stopService();
                } catch (DNSException e) {
                  /* no-op */
                }
              }
            });
  }
Exemplo n.º 2
0
 /**
  * Stops and shutdown the service.
  *
  * @throws DNSException
  * @since 1.0
  */
 public synchronized void stopService() throws DNSException {
   if (server != null) {
     LOGGER.info("Shutting down DNS server.");
     server.stop();
   }
 }