directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r123286 - in incubator/directory/network/trunk/mina/src: examples/org/apache/mina/examples/reverser java/org/apache/mina/protocol
Date Fri, 24 Dec 2004 09:23:07 GMT
Author: trustin
Date: Fri Dec 24 01:23:04 2004
New Revision: 123286

URL: http://svn.apache.org/viewcvs?view=rev&rev=123286
Log:
 * Fixed: Reverser example didn't run because thread pool filters were not started
 * Added ProtocolDecoderOutput interface and modified ProtocolDecoder.decode() method signature
to resolve the case when decoder decodes more than one message from the specified bytebuffer
Added:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoderOutput.java
  (contents, props changed)
Modified:
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoder.java

Modified: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java?view=diff&rev=123286&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java&r1=123285&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java&r2=123286
==============================================================================
--- incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java
(original)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java
Fri Dec 24 01:23:04 2004
@@ -38,12 +38,16 @@
 
     public static void main( String[] args ) throws Exception
     {
+        IoThreadPoolFilter ioThreadPoolFilter = new IoThreadPoolFilter();
+        ProtocolThreadPoolFilter protocolThreadPoolFilter = new ProtocolThreadPoolFilter();
+        ioThreadPoolFilter.start();
+        protocolThreadPoolFilter.start();
+
         Acceptor acceptor = new SocketAcceptor();
         IoAdapter ioAdapter = new IoAdapter();
 
-        acceptor.addFilter( Integer.MAX_VALUE, new IoThreadPoolFilter() );
-        ioAdapter
-                .addFilter( Integer.MAX_VALUE, new ProtocolThreadPoolFilter() );
+        acceptor.addFilter( Integer.MAX_VALUE, ioThreadPoolFilter );
+        ioAdapter.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
 
         acceptor.bind( new InetSocketAddress( PORT ), ioAdapter
                 .adapt( new ReverseProtocolProvider() ) );

Modified: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java?view=diff&rev=123286&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java&r1=123285&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java&r2=123286
==============================================================================
--- incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java
(original)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java
Fri Dec 24 01:23:04 2004
@@ -21,6 +21,7 @@
 import java.nio.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;
 
@@ -35,7 +36,7 @@
 
     private StringBuffer decodeBuf = new StringBuffer();
 
-    public Object decode( ProtocolSession session, ByteBuffer in )
+    public void decode( ProtocolSession session, ByteBuffer in, ProtocolDecoderOutput out
)
             throws ProtocolViolationException
     {
         do
@@ -48,7 +49,8 @@
             case '\n':
                 String result = decodeBuf.toString();
                 decodeBuf.delete( 0, decodeBuf.length() );
-                return result;
+                out.write(result);
+                break;
             default:
                 decodeBuf.append( ( char ) b );
             }
@@ -60,7 +62,5 @@
             }
         }
         while( in.hasRemaining() );
-
-        return null;
     }
 }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java?view=diff&rev=123286&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java&r1=123285&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java&r2=123286
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
Fri Dec 24 01:23:04 2004
@@ -98,29 +98,36 @@
 
         public void dataRead( IoSession session, ByteBuffer in )
         {
-            ProtocolSession psession = getProtocolSession( session );
-            Object result;
+            ProtocolSessionImpl psession = getProtocolSession( session );
             try
             {
                 for( ;; )
                 {
-                    result = null;
                     synchronized( in )
                     {
                         if( in.hasRemaining() )
                         {
-                            result = decoder.decode( psession, in );
+                            decoder.decode( psession, in, psession.decOut );
                         }
                     }
 
-                    if( result == null )
+                    Queue queue = psession.decOut.messageQueue;
+                    synchronized( queue )
                     {
-                        // read up all data
-                        break;
-                    }
-                    else
-                    {
-                        filterManager.fireMessageReceived( psession, result );
+                        if( queue.isEmpty() )
+                        {
+                            break;
+                        }
+                        else
+                        {
+                            do
+                            {
+                                filterManager
+                                        .fireMessageReceived( psession, queue
+                                                .pop() );
+                            }
+                            while( !queue.isEmpty() );
+                        }
                     }
                 }
             }
@@ -168,15 +175,15 @@
             }
         }
 
-        private ProtocolSession getProtocolSession( IoSession session )
+        private ProtocolSessionImpl getProtocolSession( IoSession session )
         {
-            ProtocolSession psession = ( ProtocolSession ) session
+            ProtocolSessionImpl psession = ( ProtocolSessionImpl ) session
                     .getAttachment();
             if( psession == null )
             {
                 synchronized( session )
                 {
-                    psession = ( ProtocolSession ) session.getAttachment();
+                    psession = ( ProtocolSessionImpl ) session.getAttachment();
                     if( psession == null )
                     {
                         psession = new ProtocolSessionImpl( session, this );
@@ -199,6 +206,8 @@
 
         private final ProtocolEncoderOutputImpl encOut;
 
+        private final ProtocolDecoderOutputImpl decOut;
+
         private Object attachment;
 
         private ProtocolSessionImpl( IoSession session,
@@ -207,6 +216,7 @@
             this.session = session;
             this.adapter = adapter;
             this.encOut = new ProtocolEncoderOutputImpl( session );
+            this.decOut = new ProtocolDecoderOutputImpl();
         }
 
         public ProtocolHandler getHandler()
@@ -327,6 +337,22 @@
         public void write( byte[] buf, int offset, int length )
         {
             session.write( buf, offset, length, message );
+        }
+    }
+
+    private static class ProtocolDecoderOutputImpl implements
+                                                  ProtocolDecoderOutput
+    {
+
+        private final Queue messageQueue = new Queue();
+
+        private ProtocolDecoderOutputImpl()
+        {
+        }
+
+        public void write( Object message )
+        {
+            messageQueue.push( message );
         }
     }
 }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoder.java?view=diff&rev=123286&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoder.java&r1=123285&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoder.java&r2=123286
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoder.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoder.java
Fri Dec 24 01:23:04 2004
@@ -28,6 +28,6 @@
  */
 public interface ProtocolDecoder
 {
-    Object decode( ProtocolSession session, ByteBuffer in )
-            throws ProtocolViolationException;
+    void decode( ProtocolSession session, ByteBuffer in,
+                ProtocolDecoderOutput out ) throws ProtocolViolationException;
 }

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoderOutput.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoderOutput.java?view=auto&rev=123286
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoderOutput.java
Fri Dec 24 01:23:04 2004
@@ -0,0 +1,30 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 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.mina.protocol;
+
+/**
+ * TODO Document me.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface ProtocolDecoderOutput
+{
+    void write(Object message);
+}

Mime
View raw message