directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r359378 - /directory/trunk/mina-core/src/test/java/org/apache/mina/transport/socket/nio/AbstractBindTest.java
Date Wed, 28 Dec 2005 03:57:06 GMT
Author: akarasulu
Date: Tue Dec 27 19:57:04 2005
New Revision: 359378

URL: http://svn.apache.org/viewcvs?rev=359378&view=rev
Log:
fixing dep on echo server

Modified:
    directory/trunk/mina-core/src/test/java/org/apache/mina/transport/socket/nio/AbstractBindTest.java

Modified: directory/trunk/mina-core/src/test/java/org/apache/mina/transport/socket/nio/AbstractBindTest.java
URL: http://svn.apache.org/viewcvs/directory/trunk/mina-core/src/test/java/org/apache/mina/transport/socket/nio/AbstractBindTest.java?rev=359378&r1=359377&r2=359378&view=diff
==============================================================================
--- directory/trunk/mina-core/src/test/java/org/apache/mina/transport/socket/nio/AbstractBindTest.java
(original)
+++ directory/trunk/mina-core/src/test/java/org/apache/mina/transport/socket/nio/AbstractBindTest.java
Tue Dec 27 19:57:04 2005
@@ -25,8 +25,13 @@
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.examples.echoserver.EchoProtocolHandler;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Tests {@link IoAcceptor} resource leakage by repeating bind and unbind.
@@ -166,4 +171,44 @@
         bind( false );
     }
 
+    static class EchoProtocolHandler extends IoHandlerAdapter
+    {
+        private static final Logger log = LoggerFactory.getLogger( EchoProtocolHandler.class
);
+
+        public void sessionCreated( IoSession session )
+        {
+            if( session instanceof SocketSession )
+            {
+                ( ( SocketSession ) session ).setSessionReceiveBufferSize( 2048 );
+            }
+
+            session.setIdleTime( IdleStatus.BOTH_IDLE, 10 );
+        }
+
+        public void sessionIdle( IoSession session, IdleStatus status )
+        {
+            log.info( "*** IDLE #" + session.getIdleCount( IdleStatus.BOTH_IDLE ) + " ***"
);
+        }
+
+        public void exceptionCaught( IoSession session, Throwable cause )
+        {
+            cause.printStackTrace();
+            session.close();
+        }
+
+        public void messageReceived( IoSession session, Object message ) throws Exception
+        {
+            if( !( message instanceof ByteBuffer ) )
+            {
+                return;
+            }
+
+            ByteBuffer rb = ( ByteBuffer ) message;
+            // Write the received data back to remote peer
+            ByteBuffer wb = ByteBuffer.allocate( rb.remaining() );
+            wb.put( rb );
+            wb.flip();
+            session.write( wb );
+        }
+    }
 }



Mime
View raw message