directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r330760 - in /directory/protocol-providers/dhcp/trunk: ./ src/java/org/apache/dhcp/ src/java/org/apache/dhcp/messages/ src/java/org/apache/dhcp/protocol/
Date Fri, 04 Nov 2005 08:47:41 GMT
Author: trustin
Date: Fri Nov  4 00:47:32 2005
New Revision: 330760

URL: http://svn.apache.org/viewcvs?rev=330760&view=rev
Log:
Related issue: DIR-114 Migrate all protocol providers to MINA 0.9.
* Migrated protocol-provider for DHCP to MINA 0.9.

Added:
    directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolCodecFactory.java
      - copied, changed from r330736, directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolProvider.java
Removed:
    directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolProvider.java
Modified:
    directory/protocol-providers/dhcp/trunk/project.xml
    directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/DhcpException.java
    directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/messages/DhcpMessageModifier.java
    directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpDecoder.java
    directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpEncoder.java
    directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolHandler.java

Modified: directory/protocol-providers/dhcp/trunk/project.xml
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dhcp/trunk/project.xml?rev=330760&r1=330759&r2=330760&view=diff
==============================================================================
--- directory/protocol-providers/dhcp/trunk/project.xml (original)
+++ directory/protocol-providers/dhcp/trunk/project.xml Fri Nov  4 00:47:32 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>junit</groupId>

Modified: directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/DhcpException.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/DhcpException.java?rev=330760&r1=330759&r2=330760&view=diff
==============================================================================
--- directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/DhcpException.java (original)
+++ directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/DhcpException.java Fri
Nov  4 00:47:32 2005
@@ -20,6 +20,8 @@
 
 public class DhcpException extends Exception
 {
+    private static final long serialVersionUID = 3985748516732135317L;
+
     /**
      * This empty constructor is used if no 
      * explanation of the DHCP exception is required.

Modified: directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/messages/DhcpMessageModifier.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/messages/DhcpMessageModifier.java?rev=330760&r1=330759&r2=330760&view=diff
==============================================================================
--- directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/messages/DhcpMessageModifier.java
(original)
+++ directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/messages/DhcpMessageModifier.java
Fri Nov  4 00:47:32 2005
@@ -85,7 +85,7 @@
 	/**
 	 * Set hops field.
 	 * 
-	 * @param inHops hops field
+	 * @param hardwareOptions hops field
 	 */
 	public void setHardwareOptions( byte hardwareOptions )
 	{

Modified: directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpDecoder.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpDecoder.java?rev=330760&r1=330759&r2=330760&view=diff
==============================================================================
--- directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpDecoder.java
(original)
+++ directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpDecoder.java
Fri Nov  4 00:47:32 2005
@@ -20,26 +20,20 @@
 import org.apache.dhcp.DhcpException;
 import org.apache.dhcp.io.DhcpMessageDecoder;
 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;
 
 public class DhcpDecoder implements ProtocolDecoder
 {
-    public void decode( ProtocolSession session, ByteBuffer in, ProtocolDecoderOutput out
)
-            throws ProtocolViolationException
+    public void decode( IoSession session, ByteBuffer in,
+            ProtocolDecoderOutput out ) throws DhcpException
     {
-    	 DhcpMessageDecoder decoder = new DhcpMessageDecoder();
-    	 try
-		 {
-    	 	out.write( decoder.decode( in.buf() ) );
-		 }
-    	 catch ( DhcpException de)
-		 {
-    	 	de.printStackTrace();
-		 }
+        DhcpMessageDecoder decoder = new DhcpMessageDecoder();
+        out.write( decoder.decode( in.buf() ) );
     }
-}
 
+    public void dispose( IoSession arg0 ) throws Exception
+    {
+    }
+}

Modified: directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpEncoder.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpEncoder.java?rev=330760&r1=330759&r2=330760&view=diff
==============================================================================
--- directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpEncoder.java
(original)
+++ directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpEncoder.java
Fri Nov  4 00:47:32 2005
@@ -20,16 +20,14 @@
 import org.apache.dhcp.io.DhcpMessageEncoder;
 import org.apache.dhcp.messages.DhcpMessage;
 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;
 
 
 public class DhcpEncoder implements ProtocolEncoder
 {
-    public void encode( ProtocolSession session, Object message, ProtocolEncoderOutput out
)
-            throws ProtocolViolationException
+    public void encode( IoSession session, Object message, ProtocolEncoderOutput out )
     {
         DhcpMessageEncoder encoder = new DhcpMessageEncoder();
         
@@ -39,6 +37,10 @@
         buf.flip();
         
         out.write( buf );
+    }
+
+    public void dispose( IoSession arg0 ) throws Exception
+    {
     }
 }
 

Copied: directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolCodecFactory.java
(from r330736, directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolProvider.java)
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolCodecFactory.java?p2=directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolCodecFactory.java&p1=directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolProvider.java&r1=330736&r2=330760&rev=330760&view=diff
==============================================================================
--- directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolProvider.java
(original)
+++ directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolCodecFactory.java
Fri Nov  4 00:47:32 2005
@@ -17,42 +17,32 @@
 
 package org.apache.dhcp.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 DhcpProtocolProvider implements ProtocolProvider
+public class DhcpProtocolCodecFactory implements ProtocolCodecFactory
 {
-    // Protocol handler is usually a singleton.
-    private static ProtocolHandler HANDLER = new DhcpProtocolHandler();
-
     // Codec factory is also usually a singleton.
-    private static ProtocolCodecFactory CODEC_FACTORY = new ProtocolCodecFactory()
+    private static DhcpProtocolCodecFactory INSTANCE =
+        new DhcpProtocolCodecFactory();
+    
+    public static DhcpProtocolCodecFactory getInstance()
     {
-        public ProtocolEncoder newEncoder()
-        {
-            // Create a new encoder.
-            return new DhcpEncoder();
-        }
-
-        public ProtocolDecoder newDecoder()
-        {
-            // Create a new decoder.
-            return new DhcpDecoder();
-        }
-    };
+        return INSTANCE;
+    }
 
-    public ProtocolCodecFactory getCodecFactory()
+    public ProtocolEncoder getEncoder()
     {
-        return CODEC_FACTORY;
+        // Create a new encoder.
+        return new DhcpEncoder();
     }
 
-    public ProtocolHandler getHandler()
+    public ProtocolDecoder getDecoder()
     {
-        return HANDLER;
+        // Create a new decoder.
+        return new DhcpDecoder();
     }
 }
 

Modified: directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolHandler.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolHandler.java?rev=330760&r1=330759&r2=330760&view=diff
==============================================================================
--- directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolHandler.java
(original)
+++ directory/protocol-providers/dhcp/trunk/src/java/org/apache/dhcp/protocol/DhcpProtocolHandler.java
Fri Nov  4 00:47:32 2005
@@ -17,43 +17,47 @@
 
 package org.apache.dhcp.protocol;
 
-import java.io.IOException;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 
 import org.apache.dhcp.DhcpService;
 import org.apache.dhcp.messages.DhcpMessage;
 import org.apache.dhcp.service.DhcpServiceImpl;
+import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.IdleStatus;
-import org.apache.mina.io.datagram.DatagramConnector;
-import org.apache.mina.protocol.ProtocolHandler;
-import org.apache.mina.protocol.ProtocolSession;
-import org.apache.mina.protocol.io.IoProtocolConnector;
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.transport.socket.nio.DatagramConnector;
 
 
-public class DhcpProtocolHandler implements ProtocolHandler
+public class DhcpProtocolHandler implements IoHandler
 {
-    public void sessionCreated( ProtocolSession session )
+    public void sessionCreated( IoSession session ) throws Exception
     {
         System.out.println( session.getRemoteAddress() + " CREATED" );
+        session.getFilterChain().addFirst(
+                "codec",
+                new ProtocolCodecFilter( new DhcpProtocolCodecFactory() ) );
     }
 
-    public void sessionOpened( ProtocolSession session )
+    public void sessionOpened( IoSession session )
     {
         System.out.println( session.getRemoteAddress() + " OPENED" );
     }
 
-    public void sessionClosed( ProtocolSession session )
+    public void sessionClosed( IoSession session )
     {
         System.out.println( session.getRemoteAddress() + " CLOSED" );
     }
 
-    public void sessionIdle( ProtocolSession session, IdleStatus status )
+    public void sessionIdle( IoSession session, IdleStatus status )
     {
         System.out.println( session.getRemoteAddress() + " IDLE(" + status + ")" );
     }
 
-    public void exceptionCaught( ProtocolSession session, Throwable cause )
+    public void exceptionCaught( IoSession session, Throwable cause )
     {
         System.out.println( session.getRemoteAddress() + " EXCEPTION" );
         cause.printStackTrace( System.out );
@@ -61,7 +65,7 @@
         session.close();
     }
 
-    public void messageReceived( ProtocolSession session, Object message )
+    public void messageReceived( IoSession session, Object message ) throws Exception
     {
         System.out.println( session.getRemoteAddress() + " RCVD: " + message );
         
@@ -72,22 +76,18 @@
             DhcpService dhcpService = new DhcpServiceImpl();
             DhcpMessage reply = dhcpService.getReplyFor( request );
             
-            try
-			{
-            	int PORT = 68;
-                IoProtocolConnector connector = new IoProtocolConnector( new DatagramConnector()
);
-                InetAddress broadcast = InetAddress.getByName( null );
-                ProtocolSession replySession = connector.connect( new InetSocketAddress(
broadcast, PORT ), new DhcpProtocolProvider() );
-                replySession.write( reply );
-			}
-            catch (IOException ioe)
-			{
-            	ioe.printStackTrace();
-			}
+        	int PORT = 68;
+            IoConnector connector = new DatagramConnector();
+            InetAddress broadcast = InetAddress.getByName( null );
+            ConnectFuture future = connector.connect( new InetSocketAddress( broadcast, PORT
), new DhcpProtocolHandler() );
+            future.join();
+            IoSession replySession = future.getSession();
+            replySession.write( reply ).join();
+            replySession.close();
         }
     }
 
-    public void messageSent( ProtocolSession session, Object message )
+    public void messageSent( IoSession session, Object message )
     {
         System.out.println( session.getRemoteAddress() + " SENT: " + message );
     }



Mime
View raw message