View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.dns;
21  
22  
23  import org.apache.directory.server.core.DefaultDirectoryService;
24  import org.apache.directory.server.core.api.DirectoryService;
25  import org.apache.directory.server.protocol.shared.transport.TcpTransport;
26  import org.apache.directory.server.protocol.shared.transport.UdpTransport;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  
31  /**
32   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
33   */
34  public class Main
35  {
36      /** Logger for this class */
37      private static final Logger LOG = LoggerFactory.getLogger( Main.class );
38  
39      private static DnsServer dnsConfiguration;
40  
41  
42      /**
43       * Entry point for the DNS server.
44       *
45       * @param args
46       * @throws Exception
47       */
48      public static void main( String[] args ) throws Exception
49      {
50          new Main().go();
51      }
52  
53  
54      /**
55       * Start an instance of the DNS server.
56       */
57      public void go() throws Exception
58      {
59          LOG.debug( "Starting the DNS server" );
60  
61          DirectoryService directoryService = new DefaultDirectoryService();
62          dnsConfiguration = new DnsServer();
63          dnsConfiguration.setDirectoryService( directoryService );
64          dnsConfiguration.setEnabled( true );
65          dnsConfiguration.setTransports( new TcpTransport( 10053 ), new UdpTransport( 10053 ) );
66          dnsConfiguration.start();
67      }
68  
69  
70      protected void shutdown()
71      {
72          LOG.debug( "Stopping the DNS server" );
73          dnsConfiguration.stop();
74      }
75  }