directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r330831 - in /directory/protocol-providers/ntp/trunk: ./ src/main/java/org/apache/ntp/ src/main/java/org/apache/ntp/protocol/
Date Fri, 04 Nov 2005 16:09:27 GMT
Author: erodriguez
Date: Fri Nov  4 08:09:11 2005
New Revision: 330831

URL: http://svn.apache.org/viewcvs?rev=330831&view=rev
Log:
Migrated protocol-provider for NTP protocol to MINA 0.9.

Added:
    directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolCodecFactory.java
      - copied, changed from r330735, directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolProvider.java
Removed:
    directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolProvider.java
Modified:
    directory/protocol-providers/ntp/trunk/project.xml
    directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpConfiguration.java
    directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpException.java
    directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpServer.java
    directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpDecoder.java
    directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpEncoder.java
    directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolHandler.java

Modified: directory/protocol-providers/ntp/trunk/project.xml
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ntp/trunk/project.xml?rev=330831&r1=330830&r2=330831&view=diff
==============================================================================
--- directory/protocol-providers/ntp/trunk/project.xml (original)
+++ directory/protocol-providers/ntp/trunk/project.xml Fri Nov  4 08:09:11 2005
@@ -85,7 +85,7 @@
     <dependency>
       <groupId>directory-network</groupId>
       <artifactId>mina</artifactId>
-      <version>0.8.0</version>
+      <version>0.9.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>directory-shared</groupId>
@@ -114,7 +114,7 @@
   <build>
     <nagEmailAddress>dev@directory.apache.org</nagEmailAddress>
     <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
-    <unitTestSourceDirectory>${basedir}/src/test</unitTestSourceDirectory>
+    <unitTestSourceDirectory>${basedir}/src/test/java</unitTestSourceDirectory>
     <unitTest>
       <includes>
         <include>**/*Test*</include>
@@ -126,7 +126,7 @@
       </excludes>
       <resources>
         <resource>
-          <directory>${basedir}/src/test</directory>
+          <directory>${basedir}/src/test/java</directory>
           <includes>
             <include>**/*.ldif</include>
             <include>**/*.properties</include>

Modified: directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpConfiguration.java?rev=330831&r1=330830&r2=330831&view=diff
==============================================================================
--- directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpConfiguration.java
(original)
+++ directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpConfiguration.java
Fri Nov  4 08:09:11 2005
@@ -28,6 +28,8 @@
 
 public class NtpConfiguration extends ServiceConfiguration
 {
+    private static final long serialVersionUID = 2961795205765175775L;
+
     /** the default port */
     private static final String DEFAULT_IP_PORT = "123";
 

Modified: directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpException.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpException.java?rev=330831&r1=330830&r2=330831&view=diff
==============================================================================
--- directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpException.java
(original)
+++ directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpException.java
Fri Nov  4 08:09:11 2005
@@ -25,6 +25,8 @@
  */
 public class NtpException extends Exception
 {
+    private static final long serialVersionUID = -225862469671550203L;
+
     /**
      * Creates an NtpException.
      */

Modified: directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpServer.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpServer.java?rev=330831&r1=330830&r2=330831&view=diff
==============================================================================
--- directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpServer.java (original)
+++ directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/NtpServer.java Fri
Nov  4 08:09:11 2005
@@ -20,11 +20,11 @@
 import java.io.IOException;
 import java.util.Dictionary;
 
+import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.TransportType;
-import org.apache.mina.protocol.ProtocolProvider;
 import org.apache.mina.registry.Service;
 import org.apache.mina.registry.ServiceRegistry;
-import org.apache.ntp.protocol.NtpProtocolProvider;
+import org.apache.ntp.protocol.NtpProtocolHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,7 +36,7 @@
     private NtpConfiguration config;
     private ServiceRegistry registry;
 
-    private ProtocolProvider provider;
+    private IoHandler handler;
     private Service tcpService;
     private Service udpService;
 
@@ -50,13 +50,13 @@
 
         try
         {
-            provider = new NtpProtocolProvider();
+            handler = new NtpProtocolHandler();
 
             udpService = new Service( name, TransportType.DATAGRAM, port );
             tcpService = new Service( name, TransportType.SOCKET, port );
 
-            registry.bind( udpService, provider );
-            registry.bind( tcpService, provider );
+            registry.bind( udpService, handler );
+            registry.bind( tcpService, handler );
 
             log.debug( name + " listening on port " + port );
         }
@@ -77,7 +77,7 @@
         registry.unbind( tcpService );
 
         registry = null;
-        provider = null;
+        handler = null;
         udpService = null;
         tcpService = null;
 

Modified: directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpDecoder.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpDecoder.java?rev=330831&r1=330830&r2=330831&view=diff
==============================================================================
--- directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpDecoder.java
(original)
+++ directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpDecoder.java
Fri Nov  4 08:09:11 2005
@@ -18,18 +18,20 @@
 package org.apache.ntp.protocol;
 
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.protocol.ProtocolDecoder;
-import org.apache.mina.protocol.ProtocolDecoderOutput;
-import org.apache.mina.protocol.ProtocolSession;
-import org.apache.mina.protocol.ProtocolViolationException;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.apache.ntp.io.NtpMessageDecoder;
 
 public class NtpDecoder implements ProtocolDecoder
 {
-    public void decode( ProtocolSession session, ByteBuffer in, ProtocolDecoderOutput out
)
-            throws ProtocolViolationException
+    public void decode( IoSession session, ByteBuffer in, ProtocolDecoderOutput out )
     {
         NtpMessageDecoder decoder = new NtpMessageDecoder();
         out.write( decoder.decode( in.buf() ) );
+    }
+
+    public void dispose( IoSession arg0 ) throws Exception
+    {
     }
 }

Modified: directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpEncoder.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpEncoder.java?rev=330831&r1=330830&r2=330831&view=diff
==============================================================================
--- directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpEncoder.java
(original)
+++ directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpEncoder.java
Fri Nov  4 08:09:11 2005
@@ -18,17 +18,15 @@
 package org.apache.ntp.protocol;
 
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.protocol.ProtocolEncoder;
-import org.apache.mina.protocol.ProtocolEncoderOutput;
-import org.apache.mina.protocol.ProtocolSession;
-import org.apache.mina.protocol.ProtocolViolationException;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
 import org.apache.ntp.io.NtpMessageEncoder;
 import org.apache.ntp.messages.NtpMessage;
 
 public class NtpEncoder implements ProtocolEncoder
 {
-    public void encode( ProtocolSession session, Object message, ProtocolEncoderOutput out
)
-            throws ProtocolViolationException
+    public void encode( IoSession session, Object message, ProtocolEncoderOutput out )
     {
         NtpMessageEncoder encoder = new NtpMessageEncoder();
 
@@ -38,5 +36,9 @@
         buf.flip();
 
         out.write( buf );
+    }
+
+    public void dispose( IoSession arg0 ) throws Exception
+    {
     }
 }

Copied: directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolCodecFactory.java
(from r330735, directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolProvider.java)
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolCodecFactory.java?p2=directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolCodecFactory.java&p1=directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolProvider.java&r1=330735&r2=330831&rev=330831&view=diff
==============================================================================
--- directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolProvider.java
(original)
+++ directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolCodecFactory.java
Fri Nov  4 08:09:11 2005
@@ -17,40 +17,32 @@
 
 package org.apache.ntp.protocol;
 
-import org.apache.mina.protocol.ProtocolCodecFactory;
-import org.apache.mina.protocol.ProtocolDecoder;
-import org.apache.mina.protocol.ProtocolEncoder;
-import org.apache.mina.protocol.ProtocolHandler;
-import org.apache.mina.protocol.ProtocolProvider;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolEncoder;
 
-public class NtpProtocolProvider implements ProtocolProvider
+public class NtpProtocolCodecFactory implements ProtocolCodecFactory
 {
-    // Protocol handler is usually a singleton.
-    private static ProtocolHandler HANDLER = new NtpProtocolHandler();
+    private static final NtpProtocolCodecFactory INSTANCE = new NtpProtocolCodecFactory();
 
-    // Codec factory is also usually a singleton.
-    private static ProtocolCodecFactory CODEC_FACTORY = new ProtocolCodecFactory()
+    public static NtpProtocolCodecFactory getInstance()
     {
-        public ProtocolEncoder newEncoder()
-        {
-            // Create a new encoder.
-            return new NtpEncoder();
-        }
+        return INSTANCE;
+    }
 
-        public ProtocolDecoder newDecoder()
-        {
-            // Create a new decoder.
-            return new NtpDecoder();
-        }
-    };
+    private NtpProtocolCodecFactory()
+    {
+    }
 
-    public ProtocolCodecFactory getCodecFactory()
+    public ProtocolEncoder getEncoder()
     {
-        return CODEC_FACTORY;
+        // Create a new encoder.
+        return new NtpEncoder();
     }
 
-    public ProtocolHandler getHandler()
+    public ProtocolDecoder getDecoder()
     {
-        return HANDLER;
+        // Create a new decoder.
+        return new NtpDecoder();
     }
 }

Modified: directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolHandler.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolHandler.java?rev=330831&r1=330830&r2=330831&view=diff
==============================================================================
--- directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolHandler.java
(original)
+++ directory/protocol-providers/ntp/trunk/src/main/java/org/apache/ntp/protocol/NtpProtocolHandler.java
Fri Nov  4 08:09:11 2005
@@ -18,30 +18,33 @@
 package org.apache.ntp.protocol;
 
 import org.apache.mina.common.IdleStatus;
-import org.apache.mina.protocol.ProtocolHandler;
-import org.apache.mina.protocol.ProtocolSession;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
 import org.apache.ntp.NtpService;
 import org.apache.ntp.messages.NtpMessage;
 import org.apache.ntp.service.NtpServiceImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class NtpProtocolHandler implements ProtocolHandler
+public class NtpProtocolHandler implements IoHandler
 {
     /** the log for this class */
     private static final Logger log = LoggerFactory.getLogger( NtpProtocolHandler.class );
 
     private NtpService ntpService = new NtpServiceImpl();
 
-    public void sessionCreated( ProtocolSession session )
+    public void sessionCreated( IoSession session ) throws Exception
     {
         if ( log.isDebugEnabled() )
         {
             log.debug( session.getRemoteAddress() + " CREATED" );
         }
+
+        session.getFilterChain().addFirst( "codec", new ProtocolCodecFilter( NtpProtocolCodecFactory.getInstance()
) );
     }
 
-    public void sessionOpened( ProtocolSession session )
+    public void sessionOpened( IoSession session )
     {
         if ( log.isDebugEnabled() )
         {
@@ -49,7 +52,7 @@
         }
     }
 
-    public void sessionClosed( ProtocolSession session )
+    public void sessionClosed( IoSession session )
     {
         if ( log.isDebugEnabled() )
         {
@@ -57,7 +60,7 @@
         }
     }
 
-    public void sessionIdle( ProtocolSession session, IdleStatus status )
+    public void sessionIdle( IoSession session, IdleStatus status )
     {
         if ( log.isDebugEnabled() )
         {
@@ -65,13 +68,13 @@
         }
     }
 
-    public void exceptionCaught( ProtocolSession session, Throwable cause )
+    public void exceptionCaught( IoSession session, Throwable cause )
     {
         log.error( session.getRemoteAddress() + " EXCEPTION", cause );
         session.close();
     }
 
-    public void messageReceived( ProtocolSession session, Object message )
+    public void messageReceived( IoSession session, Object message )
     {
         if ( log.isDebugEnabled() )
         {
@@ -83,7 +86,7 @@
         session.write( reply );
     }
 
-    public void messageSent( ProtocolSession session, Object message )
+    public void messageSent( IoSession session, Object message )
     {
         if ( log.isDebugEnabled() )
         {



Mime
View raw message