directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r371822 - in /directory/trunks/mina: ./ filter-codec-asn1/src/main/java/org/apache/mina/filter/codec/asn1/ filter-codec-netty/ filter-codec-netty/src/ filter-codec-netty/src/main/ filter-codec-netty/src/main/java/ filter-codec-netty/src/mai...
Date Tue, 24 Jan 2006 05:31:54 GMT
Author: trustin
Date: Mon Jan 23 21:31:44 2006
New Revision: 371822

URL: http://svn.apache.org/viewcvs?rev=371822&view=rev
Log:
Resolved issue: DIRMINA-149 (Netty2 Codec)
* Added filter-codec-netty module


Added:
    directory/trunks/mina/filter-codec-asn1/src/main/java/org/apache/mina/filter/codec/asn1/package.html
    directory/trunks/mina/filter-codec-netty/
    directory/trunks/mina/filter-codec-netty/pom.xml   (with props)
    directory/trunks/mina/filter-codec-netty/src/
    directory/trunks/mina/filter-codec-netty/src/main/
    directory/trunks/mina/filter-codec-netty/src/main/java/
    directory/trunks/mina/filter-codec-netty/src/main/java/org/
    directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/
    directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/
    directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/
    directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/
    directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/
    directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyCodecFactory.java
  (with props)
    directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyDecoder.java
  (with props)
    directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyEncoder.java
  (with props)
    directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/package.html
  (with props)
    directory/trunks/mina/filter-codec-netty/src/test/
    directory/trunks/mina/filter-codec-netty/src/test/java/
Modified:
    directory/trunks/mina/pom.xml

Added: directory/trunks/mina/filter-codec-asn1/src/main/java/org/apache/mina/filter/codec/asn1/package.html
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/filter-codec-asn1/src/main/java/org/apache/mina/filter/codec/asn1/package.html?rev=371822&view=auto
==============================================================================
--- directory/trunks/mina/filter-codec-asn1/src/main/java/org/apache/mina/filter/codec/asn1/package.html
(added)
+++ directory/trunks/mina/filter-codec-asn1/src/main/java/org/apache/mina/filter/codec/asn1/package.html
Mon Jan 23 21:31:44 2006
@@ -0,0 +1,8 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+</head>
+<body>
+Protocol codec which provides the integration with <a href="http://directory.apache.org/subprojects/asn1/">Apache
ASN1</a>.
+</body>
+</html>

Added: directory/trunks/mina/filter-codec-netty/pom.xml
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/filter-codec-netty/pom.xml?rev=371822&view=auto
==============================================================================
--- directory/trunks/mina/filter-codec-netty/pom.xml (added)
+++ directory/trunks/mina/filter-codec-netty/pom.xml Mon Jan 23 21:31:44 2006
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.directory.mina</groupId>
+    <artifactId>build</artifactId>
+    <version>0.9.1-SNAPSHOT</version>
+  </parent>
+  <artifactId>org.apache.mina.filter.codec.netty</artifactId>
+  <name>mina-filter-codec-netty</name>
+  <packaging>jar</packaging>
+
+  <repositories>
+    <repository>
+      <snapshots>
+        <enabled>true</enabled>
+      </snapshots>
+      <id>gleamynode-m1-repository</id>
+      <name>gleamynode.net Maven 1.x Repository</name>
+      <url>http://gleamynode.net/dev</url>
+      <layout>legacy</layout>
+    </repository>
+  </repositories>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>tl-netty2</groupId>
+      <artifactId>tl-netty2</artifactId>
+      <version>1.9.2</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.directory.mina</groupId>
+      <artifactId>org.apache.mina</artifactId>
+      <version>0.9.1-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <version>1.0-rc5</version>
+      <scope>provided</scope>
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.4</source>
+          <target>1.4</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
+

Propchange: directory/trunks/mina/filter-codec-netty/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyCodecFactory.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyCodecFactory.java?rev=371822&view=auto
==============================================================================
--- directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyCodecFactory.java
(added)
+++ directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyCodecFactory.java
Mon Jan 23 21:31:44 2006
@@ -0,0 +1,39 @@
+/*
+ * @(#) $Id: NettyCodecFactory.java 4 2005-04-18 03:04:09Z trustin $
+ */
+package org.apache.mina.filter.codec.netty;
+
+import net.gleamynode.netty2.Message;
+import net.gleamynode.netty2.MessageRecognizer;
+
+/**
+ * A MINA <tt>ProtocolCodecFactory</tt> that provides encoder and decoder
+ * for Netty2 {@link Message}s and {@link MessageRecognizer}s.
+ * <p>
+ * Please note that this codec factory assumes one {@link MessageRecognizer}
+ * can be used for multiple sessions.  If not, you'll have to create your
+ * own factory after this factory.
+ *
+ * (Julien Vermillard) Migrated to 0.9
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev: 4 $, $Date: 2005-04-18 12:04:09 +0900 (월, 18  4월 2005) $,
+ */
+public class NettyCodecFactory implements org.apache.mina.filter.codec.ProtocolCodecFactory
{
+
+    private static final NettyEncoder ENCODER = new NettyEncoder();
+
+    private final MessageRecognizer recognizer;
+    
+    public NettyCodecFactory(MessageRecognizer recognizer) {
+        this.recognizer = recognizer;
+    }
+
+
+	public org.apache.mina.filter.codec.ProtocolEncoder getEncoder() {
+		return ENCODER;
+	}
+
+	public org.apache.mina.filter.codec.ProtocolDecoder getDecoder() {
+		return new NettyDecoder(recognizer);
+	}
+}

Propchange: directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyCodecFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyCodecFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyDecoder.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyDecoder.java?rev=371822&view=auto
==============================================================================
--- directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyDecoder.java
(added)
+++ directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyDecoder.java
Mon Jan 23 21:31:44 2006
@@ -0,0 +1,144 @@
+/*
+ * @(#) $Id: NettyDecoder.java 4 2005-04-18 03:04:09Z trustin $
+ */
+package org.apache.mina.filter.codec.netty;
+
+import net.gleamynode.netty2.Message;
+import net.gleamynode.netty2.MessageParseException;
+import net.gleamynode.netty2.MessageRecognizer;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderException;
+
+/**
+ * A MINA <tt>ProtocolDecoder</tt> that decodes byte buffers into
+ * Netty2 {@link Message}s using specified {@link MessageRecognizer}s. 
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev: 4 $, $Date: 2005-04-18 12:04:09 +0900 (월, 18  4월 2005) $,
+ */
+public class NettyDecoder implements org.apache.mina.filter.codec.ProtocolDecoder
+{
+    private final MessageRecognizer recognizer;
+
+    private java.nio.ByteBuffer readBuf = java.nio.ByteBuffer.allocate( 1024 );
+
+    private Message readingMessage;
+
+    /**
+     * Creates a new instance with the specified {@link MessageRecognizer}.
+     */
+    public NettyDecoder( MessageRecognizer recognizer )
+    {
+        if( recognizer == null )
+            throw new NullPointerException();
+
+        this.recognizer = recognizer;
+    }
+
+
+    private void put( ByteBuffer in )
+    {
+        // copy to read buffer
+        if( in.remaining() > readBuf.remaining() )
+            expand( ( readBuf.position() + in.remaining() ) * 3 / 2 );
+        readBuf.put( in.buf() );
+    }
+
+    private void expand( int newCapacity )
+    {
+        java.nio.ByteBuffer newBuf = java.nio.ByteBuffer
+                .allocate( newCapacity );
+        readBuf.flip();
+        newBuf.put( readBuf );
+        readBuf = newBuf;
+    }
+
+	public void decode(IoSession session, ByteBuffer in, org.apache.mina.filter.codec.ProtocolDecoderOutput
out) throws Exception {
+	       put( in );
+
+	        Message m = readingMessage;
+	        try
+	        {
+	            for( ;; )
+	            {
+	                readBuf.flip();
+	                if( m == null )
+	                {
+	                    int limit = readBuf.limit();
+	                    boolean failed = true;
+	                    try
+	                    {
+	                        m = recognizer.recognize( readBuf );
+	                        failed = false;
+	                    }
+	                    finally
+	                    {
+	                        if( failed )
+	                        {
+	                            // clear the read buffer if failed to recognize
+	                            readBuf.clear();
+	                            break;
+	                        }
+	                        else
+	                        {
+	                            if( m == null )
+	                            {
+	                                readBuf.limit( readBuf.capacity() );
+	                                readBuf.position( limit );
+	                                break; // finish decoding
+	                            }
+	                            else
+	                            {
+	                                // reset buffer for read
+	                                readBuf.limit( limit );
+	                                readBuf.position( 0 );
+	                            }
+	                        }
+	                    }
+	                }
+
+	                if( m != null )
+	                {
+	                    try
+	                    {
+	                    	//System.err.println("NETTY trying to decode : "+m);
+	                        if( m.read( readBuf ) )
+	                        {
+	                            out.write( m );
+	                            m = null;
+	                        } else {
+	                        	break;
+	                        }
+	                    }
+	                    finally
+	                    {
+	                        if( readBuf.hasRemaining() )
+	                        {
+	                            readBuf.compact();
+	                        }
+	                        else
+	                        {
+	                            readBuf.clear();
+				    break;
+	                        }
+	                    }
+	                }
+	            }
+	        }
+	        catch( MessageParseException e )
+	        {
+	            m = null; // discard reading message
+	            throw new ProtocolDecoderException( "Failed to decode.", e );
+	        }
+	        finally
+	        {
+	            readingMessage = m;
+	        }		
+	}
+
+	public void dispose(IoSession session) throws Exception {
+
+	}
+}

Propchange: directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyDecoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyDecoder.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyEncoder.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyEncoder.java?rev=371822&view=auto
==============================================================================
--- directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyEncoder.java
(added)
+++ directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyEncoder.java
Mon Jan 23 21:31:44 2006
@@ -0,0 +1,64 @@
+/*
+ * @(#) $Id: NettyEncoder.java 4 2005-04-18 03:04:09Z trustin $
+ */
+package org.apache.mina.filter.codec.netty;
+
+import net.gleamynode.netty2.Message;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoderException;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+
+/**
+ * A MINA <tt>ProtocolEncoder</tt> that encodes Netty2 {@link Message}s
+ * into byte buffers. 
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev: 4 $, $Date: 2005-04-18 12:04:09 +0900 (월, 18  4월 2005) $,
+ */
+public class NettyEncoder implements org.apache.mina.filter.codec.ProtocolEncoder
+{
+    /**
+     * Creates a new instance.
+     */
+    public NettyEncoder()
+    {
+    }
+
+	public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws
Exception {
+	       if( ! ( message instanceof Message ) )
+	        {
+	            throw new ProtocolEncoderException("This encoder can decode only Netty Messages."
);
+	        }
+
+	        for( ;; )
+	        {
+	            ByteBuffer buf = ByteBuffer.allocate( 8192 );
+	            Message m = ( Message ) message;
+	            try
+	            {
+	                if( m.write( buf.buf() ) )
+	                {
+	                    break;
+	                }
+	            }
+	            finally
+	            {
+	                buf.flip();
+	                if( buf.hasRemaining() )
+	                {
+	                    out.write( buf );
+	                }
+	                else
+	                {
+	                    buf.release();
+	                }
+	            }
+	        }		
+	}
+
+	public void dispose(IoSession session) throws Exception {
+		
+	}
+}
\ No newline at end of file

Propchange: directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyEncoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/NettyEncoder.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/package.html
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/package.html?rev=371822&view=auto
==============================================================================
--- directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/package.html
(added)
+++ directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/package.html
Mon Jan 23 21:31:44 2006
@@ -0,0 +1,8 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+</head>
+<body>
+Protocol codec which provides the integration with <a href="http://gleamynode.net/dev/tl-netty2/docs/">Netty2</a>
messages.
+</body>
+</html>

Propchange: directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/trunks/mina/filter-codec-netty/src/main/java/org/apache/mina/filter/codec/netty/package.html
------------------------------------------------------------------------------
    svn:executable = *

Modified: directory/trunks/mina/pom.xml
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/pom.xml?rev=371822&r1=371821&r2=371822&view=diff
==============================================================================
--- directory/trunks/mina/pom.xml (original)
+++ directory/trunks/mina/pom.xml Mon Jan 23 21:31:44 2006
@@ -49,6 +49,7 @@
         <module>core</module>
         <module>filter-ssl</module>
         <module>filter-codec-asn1</module>
+        <module>filter-codec-netty</module>
         <module>integration-spring</module>
         <module>examples</module>
       </modules>
@@ -62,6 +63,7 @@
       <modules>
         <module>core</module>
         <module>filter-codec-asn1</module>
+        <module>filter-codec-netty2</module>
       </modules>
       <build>
         <plugins>



Mime
View raw message