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 java.io.IOException;
24  
25  import javax.naming.NamingException;
26  
27  import org.apache.directory.server.core.DefaultDirectoryService;
28  import org.apache.directory.server.core.DirectoryService;
29  import org.apache.directory.server.protocol.shared.DatagramAcceptor;
30  import org.apache.directory.server.protocol.shared.SocketAcceptor;
31  import org.slf4j.Logger;
32  import org.slf4j.LoggerFactory;
33  
34  
35  /**
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   * @version $Rev$, $Date$
38   */
39  public class Main
40  {
41      /** Logger for this class */
42      private static final Logger LOG = LoggerFactory.getLogger( Main.class );
43  
44      private static DnsServer dnsConfiguration;
45  
46      /**
47       * Entry point for the DNS server.
48       *
49       * @param args
50       * @throws Exception
51       */
52      public static void main( String[] args ) throws Exception
53      {
54          new Main().go();
55      }
56  
57  
58      /**
59       * Start an instance of the DNS server.
60       */
61      public void go() throws IOException, NamingException
62      {
63          LOG.debug( "Starting the DNS server" );
64          
65          DatagramAcceptor datagramAcceptor = new DatagramAcceptor( null );
66          SocketAcceptor socketAcceptor = new SocketAcceptor( null );
67          DirectoryService directoryService = new DefaultDirectoryService();
68          dnsConfiguration = new DnsServer();
69          dnsConfiguration.setDatagramAcceptor( datagramAcceptor );
70          dnsConfiguration.setSocketAcceptor( socketAcceptor );
71          dnsConfiguration.setDirectoryService( directoryService );
72          dnsConfiguration.setEnabled( true );
73          dnsConfiguration.setIpPort( 10053 );
74          dnsConfiguration.start();
75      }
76  
77  
78      protected void shutdown()
79      {
80          LOG.debug( "Stopping the DNS server" );
81          dnsConfiguration.stop();
82      }
83  }