directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r165586 [2/2] - in /directory/network/trunk/src: examples/org/apache/mina/examples/echoserver/ examples/org/apache/mina/examples/reverser/ java/org/apache/mina/common/ java/org/apache/mina/io/ java/org/apache/mina/io/datagram/ java/org/apache/mina/io/filter/ java/org/apache/mina/io/socket/ java/org/apache/mina/protocol/ java/org/apache/mina/protocol/filter/ java/org/apache/mina/protocol/io/ java/org/apache/mina/protocol/vmpipe/ java/org/apache/mina/registry/ java/org/apache/mina/util/ test/org/apache/mina/examples/echoserver/ test/org/apache/mina/io/ test/org/apache/mina/protocol/
Date Mon, 02 May 2005 06:27:28 GMT
Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java?rev=165586&r1=165585&r2=165586&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java Sun
May  1 23:27:27 2005
@@ -8,15 +8,15 @@
 
 import org.apache.mina.common.BaseSession;
 import org.apache.mina.common.SessionConfig;
-import org.apache.mina.common.SessionInitializer;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.protocol.ProtocolDecoder;
 import org.apache.mina.protocol.ProtocolEncoder;
-import org.apache.mina.protocol.ProtocolHandler;
 import org.apache.mina.protocol.ProtocolFilterChain;
+import org.apache.mina.protocol.ProtocolHandler;
 import org.apache.mina.protocol.ProtocolSession;
 import org.apache.mina.protocol.ProtocolSessionFilterChain;
 import org.apache.mina.protocol.vmpipe.VmPipeAcceptor.Entry;
+import org.apache.mina.util.ExceptionUtil;
 
 /**
  * A {@link ProtocolSession} for in-VM transport (VM_PIPE).
@@ -50,7 +50,6 @@
     VmPipeSession( Object lock, SocketAddress localAddress,
                    VmPipeSessionManagerFilterChain managerFilterChain,
                    ProtocolHandler handler,
-                   SessionInitializer initializer,
                    Entry remoteEntry ) throws IOException
     {
         this.lock = lock;
@@ -65,7 +64,7 @@
         // initialize remote session
         try
         {
-            remoteEntry.initializer.initializeSession( remoteSession );
+            remoteEntry.handler.sessionCreated( remoteSession );
         }
         catch( Throwable t )
         {
@@ -76,7 +75,14 @@
         }
         
         // initialize client session
-        initializer.initializeSession( this );
+        try
+        {
+            handler.sessionCreated( this );
+        }
+        catch( Throwable t )
+        {
+            ExceptionUtil.throwException( t );
+        }
 
         remoteEntry.managerFilterChain.sessionOpened( remoteSession );
         managerFilterChain.sessionOpened( this );

Modified: directory/network/trunk/src/java/org/apache/mina/registry/ServiceRegistry.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/registry/ServiceRegistry.java?rev=165586&r1=165585&r2=165586&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/registry/ServiceRegistry.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/registry/ServiceRegistry.java Sun May
 1 23:27:27 2005
@@ -21,7 +21,6 @@
 import java.io.IOException;
 import java.util.Set;
 
-import org.apache.mina.common.SessionInitializer;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.io.IoAcceptor;
 import org.apache.mina.io.IoHandler;
@@ -48,18 +47,6 @@
      */
     void bind( Service service, ProtocolProvider protocolProvider )
             throws IOException;
-
-    /**
-     * Binds the specified I/O handler to the specified service.
-     */
-    void bind( Service service,
-               IoHandler ioHandler, SessionInitializer initializer ) throws IOException;
-
-    /**
-     * Binds the specified protocol provider to the specified service.
-     */
-    void bind( Service service, ProtocolProvider protocolProvider,
-               SessionInitializer initializer ) throws IOException;
 
     /**
      * Unbinds the specified service (and its aggregated I/O handler or

Modified: directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java?rev=165586&r1=165585&r2=165586&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java Sun
May  1 23:27:27 2005
@@ -10,7 +10,6 @@
 import java.util.Iterator;
 import java.util.Set;
 
-import org.apache.mina.common.SessionInitializer;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.io.IoAcceptor;
 import org.apache.mina.io.IoHandler;
@@ -64,31 +63,17 @@
 
     public void bind( Service service, IoHandler ioHandler ) throws IOException
     {
-        bind( service, ioHandler, null );
-    }
-
-    public synchronized void bind( Service service,
-                                   ProtocolProvider protocolProvider ) throws IOException
-    {
-        bind( service, protocolProvider, null );
-    }
-    
-    public synchronized void bind( Service service,
-                                   IoHandler ioHandler,
-                                   SessionInitializer initializer ) throws IOException
-    {
         IoAcceptor acceptor = findIoAcceptor( service.getTransportType() );
-        acceptor.bind( service.getAddress(), ioHandler, initializer );
+        acceptor.bind( service.getAddress(), ioHandler );
         startThreadPools();
         services.add( service );
     }
 
     public synchronized void bind( Service service,
-                                   ProtocolProvider protocolProvider,
-                                   SessionInitializer initializer ) throws IOException
+                                   ProtocolProvider protocolProvider ) throws IOException
     {
         ProtocolAcceptor acceptor = findProtocolAcceptor( service.getTransportType() );
-        acceptor.bind( service.getAddress(), protocolProvider, initializer );
+        acceptor.bind( service.getAddress(), protocolProvider );
         startThreadPools();
         services.add( service );
     }

Added: directory/network/trunk/src/java/org/apache/mina/util/SessionUtil.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/util/SessionUtil.java?rev=165586&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/util/SessionUtil.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/util/SessionUtil.java Sun May  1 23:27:27
2005
@@ -0,0 +1,56 @@
+/*
+ *   @(#) $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.util;
+
+import java.net.SocketException;
+
+import org.apache.mina.common.Session;
+import org.apache.mina.common.SessionConfig;
+import org.apache.mina.io.datagram.DatagramSessionConfig;
+import org.apache.mina.io.socket.SocketSessionConfig;
+
+/**
+ * Exception utility.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class SessionUtil
+{
+    public static void initialize( Session session ) throws SocketException
+    {
+        SessionConfig config = session.getConfig();
+        if( config instanceof SocketSessionConfig )
+        {
+            SocketSessionConfig ssc = ( SocketSessionConfig ) config;
+            ssc.setReuseAddress( true );
+            ssc.setKeepAlive( true );
+        }
+        else if( config instanceof DatagramSessionConfig )
+        {
+            DatagramSessionConfig dsc = ( DatagramSessionConfig ) config;
+            dsc.setReuseAddress( true );
+        }
+    }
+
+    private SessionUtil()
+    {
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/util/SessionUtil.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AbstractTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AbstractTest.java?rev=165586&r1=165585&r2=165586&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AbstractTest.java
(original)
+++ directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AbstractTest.java
Sun May  1 23:27:27 2005
@@ -20,12 +20,9 @@
 
 import java.io.IOException;
 
-import junit.framework.Assert;
 import junit.framework.TestCase;
 
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.Session;
-import org.apache.mina.common.SessionInitializer;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.registry.Service;
 import org.apache.mina.registry.ServiceRegistry;
@@ -39,17 +36,12 @@
  */
 public class AbstractTest extends TestCase
 {
-    private final boolean testInitializer;
-    
-    private MarkingInitializer initializer;
-
     protected int port;
 
     protected ServiceRegistry registry;
     
-    protected AbstractTest( boolean testInitializer )
+    protected AbstractTest()
     {
-        this.testInitializer = testInitializer;
     }
 
     protected static void assertEquals( byte[] expected, byte[] actual )
@@ -82,11 +74,6 @@
     {
         registry = new SimpleServiceRegistry();
         
-        if( testInitializer )
-        {
-            initializer = new MarkingInitializer();
-        }
-
         // Find an availble test port and bind to it.
         boolean socketBound = false;
         boolean datagramBound = false;
@@ -104,13 +91,10 @@
             
             try
             {
-                registry.bind( socketService,
-                               new EchoProtocolHandler(), initializer );
+                registry.bind( socketService, new EchoProtocolHandler() );
                 socketBound = true;
 
-                registry.bind( datagramService,
-                               new EchoProtocolHandler(),
-                               initializer );
+                registry.bind( datagramService, new EchoProtocolHandler() );
                 datagramBound = true;
 
                 break;
@@ -139,19 +123,5 @@
     protected void tearDown() throws Exception
     {
         registry.unbindAll();
-        if( initializer != null  )
-        {
-            Assert.assertTrue( initializer.executed );
-        }
-    }
-
-    private static class MarkingInitializer implements SessionInitializer
-    {
-        private boolean executed;
-
-        public void initializeSession(Session session) throws IOException
-        {
-            executed = true;
-        }
     }
 }

Modified: directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java?rev=165586&r1=165585&r2=165586&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
(original)
+++ directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
Sun May  1 23:27:27 2005
@@ -47,7 +47,6 @@
 {
     public AcceptorTest()
     {
-        super( true );
     }
 
     public void testTCP() throws Exception

Modified: directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java?rev=165586&r1=165585&r2=165586&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
(original)
+++ directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
Sun May  1 23:27:27 2005
@@ -18,7 +18,6 @@
  */
 package org.apache.mina.examples.echoserver;
 
-import java.io.IOException;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
@@ -26,8 +25,6 @@
 import junit.framework.Assert;
 
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.Session;
-import org.apache.mina.common.SessionInitializer;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
 import org.apache.mina.io.IoAcceptor;
@@ -51,7 +48,6 @@
     
     public ConnectorTest()
     {
-        super( false );
     }
 
     public void setUp() throws Exception
@@ -99,16 +95,13 @@
     
     private void testConnector( IoConnector connector ) throws Exception
     {
-        MarkingInitializer marker;
         InetSocketAddress localAddress = new InetSocketAddress( clientPort );
 
         System.out.println("* Without localAddress and initializer");
-        testConnector( connector, null, null );
+        testConnector( connector, null );
         
         System.out.println("* Without localAddress and with initializer");
-        marker = new MarkingInitializer();
-        testConnector( connector, null, marker );
-        Assert.assertTrue( marker.executed );
+        testConnector( connector, null );
 
         // Tests below fail in Windows platform.
         if( System.getProperty("os.name").toLowerCase().indexOf( "windows" ) >= 0 )
@@ -119,7 +112,7 @@
         }
         
         System.out.println("* With localAddress and without initializer");
-        testConnector( connector, localAddress, null );
+        testConnector( connector, localAddress );
         
         // It takes some time for local address to be cleared by OS,
         // so let's just get a new one rather than waiting for it.
@@ -127,21 +120,17 @@
         localAddress = new InetSocketAddress( clientPort );
 
         System.out.println("* With localAddress and initializer");
-        marker = new MarkingInitializer();
-        testConnector( connector, localAddress, marker );
-        Assert.assertTrue( marker.executed );
+        testConnector( connector, localAddress );
     }
     
-    private void testConnector( IoConnector connector, SocketAddress localAddress,
-                                SessionInitializer initializer ) throws Exception
+    private void testConnector( IoConnector connector, SocketAddress localAddress ) throws
Exception
     {
         EchoConnectorHandler handler = new EchoConnectorHandler();
         ByteBuffer readBuf = handler.readBuf;
         IoSession session = connector.connect(
                 new InetSocketAddress( InetAddress.getLocalHost(), port ),
                 localAddress,
-                handler,
-                initializer );
+                handler );
         
         for( int i = 0; i < 10; i ++ )
         {
@@ -241,16 +230,6 @@
         public void exceptionCaught( IoSession session, Throwable cause )
         {
             cause.printStackTrace();
-        }
-    }
-    
-    private static class MarkingInitializer implements SessionInitializer
-    {
-        private boolean executed;
-
-        public void initializeSession(Session session) throws IOException
-        {
-            executed = true;
         }
     }
 }

Modified: directory/network/trunk/src/test/org/apache/mina/io/IoFilterChainTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/io/IoFilterChainTest.java?rev=165586&r1=165585&r2=165586&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/io/IoFilterChainTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/io/IoFilterChainTest.java Sun May  1
23:27:27 2005
@@ -104,7 +104,7 @@
 
     private class TestSession extends BaseSession implements IoSession
     {
-        private IoHandler handler = new IoHandler()
+        private IoHandler handler = new IoHandlerAdapter()
         {
             public void sessionOpened(IoSession session) {
                 result += "HSO ";

Modified: directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolFilterChainTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolFilterChainTest.java?rev=165586&r1=165585&r2=165586&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolFilterChainTest.java
(original)
+++ directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolFilterChainTest.java
Sun May  1 23:27:27 2005
@@ -103,7 +103,7 @@
 
     private class TestSession extends BaseSession implements ProtocolSession
     {
-        private ProtocolHandler handler = new ProtocolHandler()
+        private ProtocolHandler handler = new ProtocolHandlerAdapter()
         {
             public void sessionOpened(ProtocolSession session) {
                 result += "HSO";



Mime
View raw message