directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r123314 - in incubator/directory/network/trunk/mina/src: examples/org/apache/mina/examples/echoserver java/org/apache/mina/io java/org/apache/mina/io/datagram java/org/apache/mina/io/socket java/org/apache/mina/protocol java/org/apache/mina/util
Date Sat, 25 Dec 2004 05:25:55 GMT
Author: trustin
Date: Fri Dec 24 21:25:52 2004
New Revision: 123314

URL: http://svn.apache.org/viewcvs?view=rev&rev=123314
Log:
 * Added Session.stateless property to distinguish TCP and UDP
 * Read buffers allocated from DatagramAcceptor/Connector are returned to ByteBufferPool.
 It is little tricky because The point of return is up to which package (I/O or Protocol)
user is using.  You'll have to look at IoHandlerFilterManager.
 * Write buffers are returned to ByteBufferPool when dataWritten or messageSent event is fired.
 All byte buffers written must be allocated from ByteBufferPool now.
   TODO: do we need to constraint this?
Modified:
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramSession.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.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/ProtocolSession.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java

Modified: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java?view=diff&rev=123314&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java&r1=123313&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java&r2=123314
==============================================================================
--- incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java
(original)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java
Fri Dec 24 21:25:52 2004
@@ -66,14 +66,12 @@
         System.out.println( Thread.currentThread().getName() + ' '
                             + session.getRemoteAddress() + ": READ ("
                             + wb.remaining() + "B)" );
-        session.write( wb, wb );
+        session.write( wb, null );
     }
 
     public void dataWritten( IoSession IoSession, Object marker )
     {
         System.out.println( Thread.currentThread().getName() + ' '
                             + IoSession.getRemoteAddress() + ": WRITTEN" );
-        
-        ByteBufferPool.release( ( ByteBuffer ) marker );
     }
 }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java?view=diff&rev=123314&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java&r1=123313&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java&r2=123314
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java	Fri
Dec 24 21:25:52 2004
@@ -45,10 +45,10 @@
     Object getAttachment();
 
     void setAttachment( Object attachment );
+    
+    boolean isStateless();
 
     boolean isConnected();
-
-    boolean isClosed();
 
     SessionConfig getConfig();
 

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java?view=diff&rev=123314&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java&r1=123313&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java&r2=123314
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
Fri Dec 24 21:25:52 2004
@@ -319,6 +319,8 @@
                     writeBufferQueue.pop();
                     writeMarkerQueue.pop();
                 }
+                
+                ByteBufferPool.release( buf );
                 session.getFilterManager().fireDataWritten( session, marker );
                 continue;
             }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java?view=diff&rev=123314&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java&r1=123313&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java&r2=123314
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java
Fri Dec 24 21:25:52 2004
@@ -311,6 +311,7 @@
                     writeBufferQueue.pop();
                     writeMarkerQueue.pop();
                 }
+                ByteBufferPool.release( buf );
                 session.getFilterManager().fireDataWritten( session, marker );
                 continue;
             }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramSession.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramSession.java?view=diff&rev=123314&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramSession.java&r1=123313&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramSession.java&r2=123314
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramSession.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramSession.java
Fri Dec 24 21:25:52 2004
@@ -161,15 +161,15 @@
 
         parent.flushSession( this );
     }
-
-    public boolean isConnected()
+    
+    public boolean isStateless()
     {
-        return ch.isConnected();
+    	return true;
     }
 
-    public boolean isClosed()
+    public boolean isConnected()
     {
-        return !isConnected();
+        return ch.isConnected();
     }
 
     public SessionConfig getConfig()

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java?view=diff&rev=123314&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java&r1=123313&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java&r2=123314
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
Fri Dec 24 21:25:52 2004
@@ -29,6 +29,7 @@
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.io.WriteTimeoutException;
+import org.apache.mina.util.ByteBufferPool;
 import org.apache.mina.util.Queue;
 
 /**
@@ -375,7 +376,7 @@
             if( session == null )
                 break;
 
-            if( session.isClosed() )
+            if( !session.isConnected() )
                 continue;
 
             try
@@ -416,7 +417,7 @@
                     writeBufferQueue.pop();
                     writeMarkerQueue.pop();
                 }
-
+                ByteBufferPool.release( buf );
                 session.getFilterManager().fireDataWritten( session, marker );
                 continue;
             }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java?view=diff&rev=123314&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java&r1=123313&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java&r2=123314
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java
Fri Dec 24 21:25:52 2004
@@ -172,15 +172,15 @@
 
         SocketIoProcessor.getInstance().flushSession( this );
     }
-
-    public boolean isConnected()
+    
+    public boolean isStateless()
     {
-        return ch.isConnected();
+    	return false;
     }
 
-    public boolean isClosed()
+    public boolean isConnected()
     {
-        return !isConnected();
+        return ch.isConnected();
     }
 
     public SessionConfig getConfig()

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=123314&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java&r1=123313&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java&r2=123314
==============================================================================
--- 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 21:25:52 2004
@@ -25,6 +25,7 @@
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoSession;
+import org.apache.mina.util.ByteBufferPool;
 import org.apache.mina.util.ProtocolHandlerFilterManager;
 import org.apache.mina.util.Queue;
 
@@ -36,6 +37,8 @@
  */
 public class IoAdapter
 {
+	public static final Class IO_HANDLER_TYPE = SessionHandlerAdapter.class;
+	
     private final ProtocolHandlerFilterManager filterManager = new ProtocolHandlerFilterManager();
 
     public IoAdapter()
@@ -132,6 +135,11 @@
             {
                 filterManager.fireExceptionCaught( psession, t );
             }
+            
+            if (session.isStateless())
+            {
+            	ByteBufferPool.release( in );
+            }
         }
 
         public void dataWritten( IoSession session, Object marker )
@@ -256,15 +264,15 @@
             adapter.write( session );
             return true;
         }
-
-        public boolean isConnected()
+        
+        public boolean isStateless()
         {
-            return session.isConnected();
+        	return session.isStateless();
         }
 
-        public boolean isClosed()
+        public boolean isConnected()
         {
-            return session.isClosed();
+            return session.isConnected();
         }
 
         public SessionConfig getConfig()

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java?view=diff&rev=123314&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java&r1=123313&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java&r2=123314
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java
Fri Dec 24 21:25:52 2004
@@ -45,9 +45,9 @@
 
     boolean write( Object message );
 
-    boolean isConnected();
+    boolean isStateless();
 
-    boolean isClosed();
+    boolean isConnected();
 
     SessionConfig getConfig();
 

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java?view=diff&rev=123314&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java&r1=123313&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java&r2=123314
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ByteBufferPool.java
Fri Dec 24 21:25:52 2004
@@ -69,7 +69,7 @@
 			buf = (ByteBuffer) stack.pop();
     		if (buf == null)
     		{
-    			buf = ByteBuffer.allocate( bufferStackSizes[ idx ] );
+    			buf = ByteBuffer.allocateDirect( bufferStackSizes[ idx ] );
     		}
 		}
 		

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java?view=diff&rev=123314&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java&r1=123313&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java&r2=123314
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java
Fri Dec 24 21:25:52 2004
@@ -24,6 +24,7 @@
 import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoHandlerFilter;
 import org.apache.mina.io.IoSession;
+import org.apache.mina.protocol.IoAdapter;
 
 /**
  * TODO Document me.
@@ -61,7 +62,11 @@
         public void dataRead( IoHandler nextHandler, IoSession session,
                              ByteBuffer buf )
         {
-            session.getHandler().dataRead( session, buf );
+        	IoHandler handler = session.getHandler();
+            handler.dataRead( session, buf );
+            if (session.isStateless() && !IoAdapter.IO_HANDLER_TYPE.isAssignableFrom(
handler.getClass() )) {
+            	ByteBufferPool.release( buf );
+            }
         }
 
         public void dataWritten( IoHandler nextHandler, IoSession session,

Mime
View raw message