directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r415511 - in /directory/trunks/mina/core/src: main/java/org/apache/mina/transport/socket/nio/support/ test/java/org/apache/mina/transport/ test/java/org/apache/mina/transport/socket/nio/
Date Tue, 20 Jun 2006 06:02:18 GMT
Author: trustin
Date: Mon Jun 19 23:02:18 2006
New Revision: 415511

URL: http://svn.apache.org/viewvc?rev=415511&view=rev
Log:
Fixed issue: DIRMINA-222 (DatagramAcceptor doesn't configure a user-defined FilterChain configuration
on bind.)
* Added buildFilterChain to DatagramAcceptor and DatagramConnector to reduce code duplication
which caused this issue.
* Eventually, we need to refactor the NIO transport implementation.


Added:
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramConfigTest.java
  (with props)
Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractTrafficControlTest.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java?rev=415511&r1=415510&r2=415511&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
Mon Jun 19 23:02:18 2006
@@ -225,9 +225,7 @@
         
         try
         {
-            this.getFilterChainBuilder().buildFilterChain( s.getFilterChain() );
-            req.config.getFilterChainBuilder().buildFilterChain( s.getFilterChain() );
-            req.config.getThreadModel().buildFilterChain( s.getFilterChain() );
+            buildFilterChain( req, s );
             ( ( DatagramFilterChain ) s.getFilterChain() ).sessionCreated( s );
         }
         catch( Throwable t )
@@ -237,6 +235,13 @@
         
         return s;
     }
+
+    private void buildFilterChain( RegistrationRequest req, IoSession session ) throws Exception
+    {
+        this.getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
+        req.config.getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
+        req.config.getThreadModel().buildFilterChain( session.getFilterChain() );
+    }
     
     public IoServiceConfig getDefaultConfig()
     {
@@ -362,6 +367,7 @@
             
             try
             {
+                buildFilterChain( req, session );
                 ( ( DatagramFilterChain ) session.getFilterChain() ).sessionCreated( session
);
 
                 if( key.isReadable() )

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java?rev=415511&r1=415510&r2=415511&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
Mon Jun 19 23:02:18 2006
@@ -33,6 +33,7 @@
 import org.apache.mina.common.IoConnector;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoServiceConfig;
+import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.common.support.BaseIoConnector;
 import org.apache.mina.common.support.DefaultConnectFuture;
@@ -550,9 +551,7 @@
             boolean success = false;
             try
             {
-                getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
-                req.config.getFilterChainBuilder().buildFilterChain( session.getFilterChain()
);
-                req.config.getThreadModel().buildFilterChain( session.getFilterChain() );
+                buildFilterChain( req, session );
                 ( ( DatagramFilterChain ) session.getFilterChain() ).sessionCreated( session
);
 
                 SelectionKey key = req.channel.register( selector,
@@ -583,6 +582,13 @@
                 }
             }
         }
+    }
+
+    private void buildFilterChain( RegistrationRequest req, IoSession session ) throws Exception
+    {
+        getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
+        req.config.getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
+        req.config.getThreadModel().buildFilterChain( session.getFilterChain() );
     }
 
     private void cancelKeys()

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java?rev=415511&r1=415510&r2=415511&view=diff
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
(original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
Mon Jun 19 23:02:18 2006
@@ -178,7 +178,7 @@
         bind( false );
     }
 
-    static class EchoProtocolHandler extends IoHandlerAdapter
+    private static class EchoProtocolHandler extends IoHandlerAdapter
     {
         private static final Logger log = LoggerFactory.getLogger( EchoProtocolHandler.class
);
 

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractTrafficControlTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractTrafficControlTest.java?rev=415511&r1=415510&r2=415511&view=diff
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractTrafficControlTest.java
(original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractTrafficControlTest.java
Mon Jun 19 23:02:18 2006
@@ -215,7 +215,7 @@
         
     }
     
-    public static class ServerIoHandler extends IoHandlerAdapter
+    private static class ServerIoHandler extends IoHandlerAdapter
     {
         public void messageReceived( IoSession session, Object message )
                 throws Exception

Added: directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramConfigTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramConfigTest.java?rev=415511&view=auto
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramConfigTest.java
(added)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramConfigTest.java
Mon Jun 19 23:02:18 2006
@@ -0,0 +1,110 @@
+/*
+ *   @(#) $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.transport.socket.nio;
+
+import java.net.InetSocketAddress;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.util.AvailablePortFinder;
+
+/**
+ * Tests if {@link DatagramAcceptor} session is configured properly.
+ * 
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$ 
+ */
+public class DatagramConfigTest extends TestCase
+{
+    private final IoAcceptor acceptor = new DatagramAcceptor();
+    private final IoConnector connector = new DatagramConnector();
+    private String result;
+
+    public DatagramConfigTest()
+    {
+    }
+    
+    protected void setUp() throws Exception
+    {
+        result = "";
+    }
+    
+    public void testAcceptorFilterChain() throws Exception
+    {
+        int port = AvailablePortFinder.getNextAvailable( 1024 );
+        DatagramAcceptorConfig expectedConfig = new DatagramAcceptorConfig();
+        IoFilter mockFilter = new MockFilter();
+        IoHandler mockHandler = new MockHandler();
+        
+        expectedConfig.getFilterChain().addLast( "mock", mockFilter );
+        acceptor.bind( new InetSocketAddress( port ), mockHandler, expectedConfig );
+        
+        try
+        {
+            ConnectFuture future = connector.connect( new InetSocketAddress( "localhost",
port ), new IoHandlerAdapter() );
+            future.join();
+            future.getSession().write( ByteBuffer.allocate( 16 ).putInt( 0 ).flip() ).join();
+            future.getSession().close();
+    
+            for( int i = 0; i < 30; i ++ )
+            {
+                if ( result.length() == 2 )
+                {
+                    break;
+                }
+                Thread.sleep( 100 );
+            }
+            
+            Assert.assertEquals( "FH", result );
+        }
+        finally
+        {
+            acceptor.unbind( new InetSocketAddress( port ) );
+        }
+    }
+    
+    private class MockFilter extends IoFilterAdapter
+    {
+
+        public void messageReceived( NextFilter nextFilter, IoSession session, Object message
) throws Exception
+        {
+            result += "F";
+            nextFilter.messageReceived( session, message );
+        }
+        
+    }
+    
+    private class MockHandler extends IoHandlerAdapter
+    {
+        public void messageReceived( IoSession session, Object message ) throws Exception
+        {
+            result += "H";
+        }
+    }
+}

Propchange: directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramConfigTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision



Mime
View raw message