directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r547515 - in /directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns: Main.java store/RecordStoreStub.java
Date Fri, 15 Jun 2007 03:51:40 GMT
Author: erodriguez
Date: Thu Jun 14 20:51:39 2007
New Revision: 547515

URL: http://svn.apache.org/viewvc?view=rev&rev=547515
Log:
Added main method class and store stub to demonstrate standalone use of DNS server.

Added:
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java
  (with props)
    directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStoreStub.java
  (with props)

Added: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java?view=auto&rev=547515
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java
(added)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java
Thu Jun 14 20:51:39 2007
@@ -0,0 +1,125 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.dns;
+
+
+import org.apache.directory.server.dns.store.RecordStore;
+import org.apache.directory.server.dns.store.RecordStoreStub;
+import org.apache.mina.common.ExecutorThreadModel;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.transport.socket.nio.DatagramAcceptor;
+import org.apache.mina.transport.socket.nio.DatagramAcceptorConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue;
+import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
+import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class Main
+{
+    /** Logger for this class */
+    private static final Logger log = LoggerFactory.getLogger( Main.class );
+
+    private static final int MAX_THREADS_DEFAULT = 4;
+
+    protected static IoAcceptor udpAcceptor;
+    protected static ThreadPoolExecutor threadPoolExecutor;
+    protected static ExecutorThreadModel threadModel = ExecutorThreadModel.getInstance( "ApacheDS"
);
+
+    private static DnsServer udpDnsServer;
+
+
+    /**
+     * Entry point for the DNS server.
+     *
+     * @param args
+     * @throws Exception
+     */
+    public static void main( String[] args ) throws Exception
+    {
+        int maxThreads = MAX_THREADS_DEFAULT;
+        threadPoolExecutor = new ThreadPoolExecutor( maxThreads, maxThreads, 60, TimeUnit.SECONDS,
+            new LinkedBlockingQueue() );
+        threadModel.setExecutor( threadPoolExecutor );
+
+        udpAcceptor = new DatagramAcceptor();
+
+        new Main().go();
+    }
+
+
+    /**
+     * Start an instance of the DNS server.
+     */
+    public void go()
+    {
+        DnsConfiguration dnsConfiguration = new DnsConfiguration();
+        dnsConfiguration.setEnabled( true );
+        dnsConfiguration.setIpPort( 10053 );
+
+        RecordStore store = new RecordStoreStub();
+
+        startup( dnsConfiguration, store );
+    }
+
+
+    private void startup( DnsConfiguration dnsConfig, RecordStore store )
+    {
+        // Skip if disabled
+        if ( !dnsConfig.isEnabled() )
+        {
+            return;
+        }
+
+        try
+        {
+            DatagramAcceptorConfig udpConfig = new DatagramAcceptorConfig();
+            udpConfig.setThreadModel( threadModel );
+
+            udpDnsServer = new DnsServer( dnsConfig, udpAcceptor, udpConfig, store );
+        }
+        catch ( Throwable t )
+        {
+            log.error( "Failed to start the DNS service", t );
+        }
+    }
+
+
+    protected void shutdown()
+    {
+        if ( udpDnsServer != null )
+        {
+            udpDnsServer.destroy();
+
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "Unbind of DNS Service complete: " + udpDnsServer );
+            }
+
+            udpDnsServer = null;
+        }
+    }
+}

Propchange: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStoreStub.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStoreStub.java?view=auto&rev=547515
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStoreStub.java
(added)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStoreStub.java
Thu Jun 14 20:51:39 2007
@@ -0,0 +1,63 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.dns.store;
+
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.server.dns.messages.QuestionRecord;
+import org.apache.directory.server.dns.messages.RecordClass;
+import org.apache.directory.server.dns.messages.RecordType;
+import org.apache.directory.server.dns.messages.ResourceRecord;
+import org.apache.directory.server.dns.messages.ResourceRecordModifier;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class RecordStoreStub implements RecordStore
+{
+    public Set<ResourceRecord> getRecords( QuestionRecord question ) throws Exception
+    {
+        Set<ResourceRecord> set = new HashSet<ResourceRecord>();
+
+        ResourceRecordModifier rm = new ResourceRecordModifier();
+        rm.setDnsClass( RecordClass.IN );
+        rm.setDnsName( "ldap.example.com" );
+        rm.setDnsTtl( 100 );
+        rm.setDnsType( RecordType.A );
+        rm.put( DnsAttribute.IP_ADDRESS, "10.0.0.2" );
+
+        set.add( rm.getEntry() );
+
+        ResourceRecordModifier rm2 = new ResourceRecordModifier();
+        rm2.setDnsClass( RecordClass.IN );
+        rm2.setDnsName( "www.example.com" );
+        rm2.setDnsTtl( 100 );
+        rm2.setDnsType( RecordType.A );
+        rm2.put( DnsAttribute.IP_ADDRESS, "10.0.0.3" );
+
+        set.add( rm2.getEntry() );
+
+        return set;
+    }
+}

Propchange: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/RecordStoreStub.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message