Author: erodriguez
Date: Wed Jan 12 17:42:52 2005
New Revision: 125014

URL: http://svn.apache.org/viewcvs?view=rev&rev=125014
Log:
DNS test harness, basic main method frontend.
Added:
   incubator/directory/dns/trunk/main/src/
   incubator/directory/dns/trunk/main/src/java/
   incubator/directory/dns/trunk/main/src/java/org/
   incubator/directory/dns/trunk/main/src/java/org/apache/
   incubator/directory/dns/trunk/main/src/java/org/apache/dns/
   incubator/directory/dns/trunk/main/src/java/org/apache/dns/Main.java

Added: incubator/directory/dns/trunk/main/src/java/org/apache/dns/Main.java
Url: 
http://svn.apache.org/viewcvs/incubator/directory/dns/trunk/main/src/java/org/apache/dns/Main.java?view=auto&rev=125014
==============================================================================
--- (empty file)
+++ incubator/directory/dns/trunk/main/src/java/org/apache/dns/Main.java        
Wed Jan 12 17:42:52 2005
@@ -0,0 +1,69 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.dns;
+
+import java.net.InetSocketAddress;
+
+import org.apache.dns.protocol.DnsProtocolProvider;
+import org.apache.mina.io.datagram.DatagramAcceptor;
+import org.apache.mina.io.filter.IoThreadPoolFilter;
+import org.apache.mina.io.socket.SocketAcceptor;
+import org.apache.mina.protocol.filter.ProtocolThreadPoolFilter;
+import org.apache.mina.protocol.io.IoProtocolAcceptor;
+
+
+public class Main
+{
+    private static final int PORT = 53;
+
+    public static void main( String[] args ) throws Exception
+    {
+        // Create I/O and Protocol thread pool filter.
+        // I/O thread pool performs encoding and decoding of messages.
+        // Protocol thread pool performs actual protocol flow.
+        IoThreadPoolFilter ioThreadPoolFilter = new IoThreadPoolFilter();
+        ProtocolThreadPoolFilter protocolThreadPoolFilter = new 
ProtocolThreadPoolFilter();
+
+        // and start both.
+        ioThreadPoolFilter.start();
+        protocolThreadPoolFilter.start();
+
+        // Create a TCP/IP acceptor.
+        IoProtocolAcceptor acceptor = new IoProtocolAcceptor( new 
SocketAcceptor() );
+
+        // Add both thread pool filters.
+        acceptor.getIoAcceptor().addFilter( Integer.MAX_VALUE, 
ioThreadPoolFilter );
+        acceptor.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
+
+        // Bind
+        acceptor.bind( new InetSocketAddress( PORT ), new 
DnsProtocolProvider() );
+        
+        // Create a UDP/IP acceptor
+        IoProtocolAcceptor datagramAcceptor = new IoProtocolAcceptor( new 
DatagramAcceptor() );
+        
+        // Add both thread pool filters.
+        datagramAcceptor.getIoAcceptor().addFilter( Integer.MAX_VALUE, 
ioThreadPoolFilter );
+        datagramAcceptor.addFilter( Integer.MAX_VALUE, 
protocolThreadPoolFilter );
+        
+        // Bind
+        datagramAcceptor.bind( new InetSocketAddress( PORT ), new 
DnsProtocolProvider() );
+
+        System.out.println( "Apache DNS listening on port " + PORT );
+    }
+}
+

Reply via email to