directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r151659 - in incubator/directory/network/mina/trunk/src/java/org/apache/mina: io/datagram/DatagramAcceptor.java io/datagram/DatagramConnector.java io/socket/SocketIoProcessor.java io/socket/SocketSession.java protocol/io/IoAdapter.java util/IoHandlerFilterManager.java
Date Mon, 07 Feb 2005 01:57:17 GMT
Author: trustin
Date: Sun Feb  6 17:57:15 2005
New Revision: 151659

URL: http://svn.apache.org/viewcvs?view=rev&rev=151659
Log:
Fixed: ByteBuffer leakage detection code causes I/O threads to die.
Fixed: SocketSession.readBuf is sometimes released more than once.

Modified:
    incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
    incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/datagram/DatagramConnector.java
    incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
    incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
    incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
    incubator/directory/network/mina/trunk/src/java/org/apache/mina/util/IoHandlerFilterManager.java

Modified: incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
URL: http://svn.apache.org/viewcvs/incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java?view=diff&r1=151658&r2=151659
==============================================================================
--- incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
(original)
+++ incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
Sun Feb  6 17:57:15 2005
@@ -338,7 +338,16 @@
                     writeMarkerQueue.pop();
                 }
 
-                ByteBuffer.release( buf );
+                try
+                {
+                    ByteBuffer.release( buf );
+                }
+                catch( IllegalStateException e )
+                {
+                    session.getFilterManager().fireExceptionCaught( session,
+                            e );
+                }
+
                 session.getFilterManager().fireDataWritten( session, marker );
                 continue;
             }

Modified: incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/datagram/DatagramConnector.java
URL: http://svn.apache.org/viewcvs/incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/datagram/DatagramConnector.java?view=diff&r1=151658&r2=151659
==============================================================================
--- incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/datagram/DatagramConnector.java
(original)
+++ incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/datagram/DatagramConnector.java
Sun Feb  6 17:57:15 2005
@@ -46,13 +46,13 @@
  * @version $Rev$, $Date$
  */
 public class DatagramConnector extends DatagramProcessor implements
-                                                        IoConnector
+        IoConnector
 {
     private static volatile int nextId = 0;
 
     private final IoHandlerFilterManager filterManager = new IoHandlerFilterManager();
 
-    private final int id = nextId++;
+    private final int id = nextId ++ ;
 
     private final Selector selector;
 
@@ -84,7 +84,7 @@
         if( handler == null )
             throw new NullPointerException( "handler" );
 
-        if( ! ( address instanceof InetSocketAddress ) )
+        if( !( address instanceof InetSocketAddress ) )
             throw new IllegalArgumentException( "Unexpected address type: "
                                                 + address.getClass() );
 
@@ -200,7 +200,7 @@
                 catch( IOException e )
                 {
                     exceptionMonitor.exceptionCaught( DatagramConnector.this,
-                                                      e );
+                            e );
 
                     try
                     {
@@ -319,7 +319,17 @@
                     writeBufferQueue.pop();
                     writeMarkerQueue.pop();
                 }
-                ByteBuffer.release( buf );
+
+                try
+                {
+                    ByteBuffer.release( buf );
+                }
+                catch( IllegalStateException e )
+                {
+                    session.getFilterManager().fireExceptionCaught( session,
+                            e );
+                }
+
                 session.getFilterManager().fireDataWritten( session, marker );
                 continue;
             }
@@ -334,9 +344,8 @@
             }
             else
             {
-                key
-                        .interestOps( key.interestOps()
-                                      & ( ~SelectionKey.OP_WRITE ) );
+                key.interestOps( key.interestOps()
+                                 & ( ~SelectionKey.OP_WRITE ) );
 
                 // pop and fire event
                 synchronized( writeBufferQueue )
@@ -366,13 +375,10 @@
                 break;
 
             DatagramSession session = new DatagramSession( this,
-                                                           filterManager,
-                                                           req.channel,
-                                                           req.handler );
+                    filterManager, req.channel, req.handler );
 
             SelectionKey key = req.channel.register( selector,
-                                                     SelectionKey.OP_READ,
-                                                     session );
+                    SelectionKey.OP_READ, session );
 
             session.setSelectionKey( key );
 
@@ -427,12 +433,12 @@
 
     public void removeAllFilters()
     {
-    	filterManager.removeAllFilters();
+        filterManager.removeAllFilters();
     }
 
     public List getAllFilters()
     {
-    	return filterManager.filters();
+        return filterManager.filters();
     }
 
     private static class RegistrationRequest
@@ -443,7 +449,8 @@
 
         private DatagramSession session;
 
-        private RegistrationRequest( DatagramChannel channel, IoHandler handler )
+        private RegistrationRequest( DatagramChannel channel,
+                                    IoHandler handler )
         {
             this.channel = channel;
             this.handler = handler;
@@ -464,4 +471,4 @@
 
         this.exceptionMonitor = monitor;
     }
-}
\ No newline at end of file
+}

Modified: incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java?view=diff&r1=151658&r2=151659
==============================================================================
--- incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
(original)
+++ incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
Sun Feb  6 17:57:15 2005
@@ -418,7 +418,16 @@
                     writeBufferQueue.pop();
                     writeMarkerQueue.pop();
                 }
-                ByteBuffer.release( buf );
+                try
+                {
+                    ByteBuffer.release( buf );
+                }
+                catch( IllegalStateException e )
+                {
+                    session.getFilterManager().fireExceptionCaught( session,
+                            e );
+                }
+
                 session.getFilterManager().fireDataWritten( session, marker );
                 continue;
             }

Modified: incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
URL: http://svn.apache.org/viewcvs/incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/socket/SocketSession.java?view=diff&r1=151658&r2=151659
==============================================================================
--- incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
(original)
+++ incubator/directory/network/mina/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
Sun Feb  6 17:57:15 2005
@@ -79,6 +79,8 @@
     private boolean idleForRead;
 
     private boolean idleForWrite;
+    
+    private boolean disposed;
 
     /**
      * Creates a new instance.
@@ -119,6 +121,11 @@
 
     void dispose()
     {
+        if (disposed)
+        {
+            return;
+        }
+        disposed = true;
         ByteBuffer.release( readBuf );
     }
 

Modified: incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java?view=diff&r1=151658&r2=151659
==============================================================================
--- incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
(original)
+++ incubator/directory/network/mina/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
Sun Feb  6 17:57:15 2005
@@ -196,7 +196,14 @@
             }
             finally
             {
-                ByteBuffer.release( in );
+                try
+                {
+                    ByteBuffer.release( in );
+                }
+                catch( IllegalStateException e )
+                {
+                    filterManager.fireExceptionCaught( psession, e );
+                }
             }
         }
 

Modified: incubator/directory/network/mina/trunk/src/java/org/apache/mina/util/IoHandlerFilterManager.java
URL: http://svn.apache.org/viewcvs/incubator/directory/network/mina/trunk/src/java/org/apache/mina/util/IoHandlerFilterManager.java?view=diff&r1=151658&r2=151659
==============================================================================
--- incubator/directory/network/mina/trunk/src/java/org/apache/mina/util/IoHandlerFilterManager.java
(original)
+++ incubator/directory/network/mina/trunk/src/java/org/apache/mina/util/IoHandlerFilterManager.java
Sun Feb  6 17:57:15 2005
@@ -55,8 +55,8 @@
             session.getHandler().sessionIdle( session, status );
         }
 
-        public void exceptionCaught( IoHandler nextHandler, IoSession session,
-                                    Throwable cause )
+        public void exceptionCaught( IoHandler nextHandler,
+                                    IoSession session, Throwable cause )
         {
             session.getHandler().exceptionCaught( session, cause );
         }
@@ -86,7 +86,7 @@
     };
 
     private Entry head = new Entry( null, null, Integer.MIN_VALUE,
-                                    FINAL_FILTER );
+            FINAL_FILTER );
 
     private final Entry tail = head;
 
@@ -117,9 +117,9 @@
             else if( e.priority == priority )
             {
                 throw new IllegalArgumentException(
-                                                    "Other filter is registered with priority
"
-                                                                                        
                                                                                         
                             + priority
-                                                                                        
                                                                                         
                             + " already." );
+                        "Other filter is registered with priority "
+                                                                                        
       + priority
+                                                                                        
       + " already." );
             }
             prevEntry = e;
             e = e.nextEntry;
@@ -128,11 +128,11 @@
 
     public synchronized void removeFilter( IoHandlerFilter filter )
     {
-    	if( filter == tail )
-    	{
-    		throw new IllegalArgumentException(
-    				"Cannot remove the internal filter.");
-    	}
+        if( filter == tail )
+        {
+            throw new IllegalArgumentException(
+                    "Cannot remove the internal filter." );
+        }
 
         Entry e = head;
         Entry prevEntry = null;
@@ -161,11 +161,12 @@
             e = e.nextEntry;
         }
     }
-    
-    public synchronized void removeAllFilters() {
-    	tail.prevEntry = null;
-    	tail.nextEntry = null;
-    	head = tail;
+
+    public synchronized void removeAllFilters()
+    {
+        tail.prevEntry = null;
+        tail.nextEntry = null;
+        head = tail;
     }
 
     public void fireSessionOpened( IoSession session )
@@ -256,9 +257,18 @@
             newBuf = e.filter.filterWrite( session, buf );
             if( buf != newBuf )
             {
-            	// Original buffer is replaced with new filtered buffer;
-            	// let's release the old one.
-            	ByteBuffer.release(buf);
+                // Original buffer is replaced with new filtered buffer;
+                // let's release the old one.
+                try
+                {
+                    ByteBuffer.release( buf );
+                }
+                catch( IllegalStateException ex )
+                {
+                    fireExceptionCaught( session, ex );
+                    // abort the write operation.
+                    return;
+                }
             }
             buf = newBuf;
             e = e.prevEntry;
@@ -324,14 +334,13 @@
                 {
                     try
                     {
-                        Entry.this.nextEntry.filter
-                                .sessionOpened(
-                                                Entry.this.nextEntry.nextHandler,
-                                                session );
+                        Entry.this.nextEntry.filter.sessionOpened(
+                                Entry.this.nextEntry.nextHandler, session );
                     }
                     catch( Throwable e )
                     {
-                        IoHandlerFilterManager.this.fireExceptionCaught( session, e );
+                        IoHandlerFilterManager.this.fireExceptionCaught(
+                                session, e );
                     }
                 }
 
@@ -339,14 +348,13 @@
                 {
                     try
                     {
-                        Entry.this.nextEntry.filter
-                                .sessionClosed(
-                                                Entry.this.nextEntry.nextHandler,
-                                                session );
+                        Entry.this.nextEntry.filter.sessionClosed(
+                                Entry.this.nextEntry.nextHandler, session );
                     }
                     catch( Throwable e )
                     {
-                        IoHandlerFilterManager.this.fireExceptionCaught( session, e );
+                        IoHandlerFilterManager.this.fireExceptionCaught(
+                                session, e );
                     }
                 }
 
@@ -354,25 +362,25 @@
                 {
                     try
                     {
-                        Entry.this.nextEntry.filter
-                                .sessionIdle(
-                                              Entry.this.nextEntry.nextHandler,
-                                              session, status );
+                        Entry.this.nextEntry.filter.sessionIdle(
+                                Entry.this.nextEntry.nextHandler, session,
+                                status );
                     }
                     catch( Throwable e )
                     {
-                        IoHandlerFilterManager.this.fireExceptionCaught( session, e );
+                        IoHandlerFilterManager.this.fireExceptionCaught(
+                                session, e );
                     }
                 }
 
-                public void exceptionCaught( IoSession session, Throwable cause )
+                public void exceptionCaught( IoSession session,
+                                            Throwable cause )
                 {
                     try
                     {
-                        Entry.this.nextEntry.filter
-                                .exceptionCaught(
-                                                  Entry.this.nextEntry.nextHandler,
-                                                  session, cause );
+                        Entry.this.nextEntry.filter.exceptionCaught(
+                                Entry.this.nextEntry.nextHandler, session,
+                                cause );
                     }
                     catch( Throwable e )
                     {
@@ -384,13 +392,14 @@
                 {
                     try
                     {
-                        Entry.this.nextEntry.filter
-                                .dataRead( Entry.this.nextEntry.nextHandler,
-                                           session, buf );
+                        Entry.this.nextEntry.filter.dataRead(
+                                Entry.this.nextEntry.nextHandler, session,
+                                buf );
                     }
                     catch( Throwable e )
                     {
-                        IoHandlerFilterManager.this.fireExceptionCaught( session, e );
+                        IoHandlerFilterManager.this.fireExceptionCaught(
+                                session, e );
                     }
                 }
 
@@ -398,14 +407,14 @@
                 {
                     try
                     {
-                        Entry.this.nextEntry.filter
-                                .dataWritten(
-                                              Entry.this.nextEntry.nextHandler,
-                                              session, marker );
+                        Entry.this.nextEntry.filter.dataWritten(
+                                Entry.this.nextEntry.nextHandler, session,
+                                marker );
                     }
                     catch( Throwable e )
                     {
-                        IoHandlerFilterManager.this.fireExceptionCaught( session, e );
+                        IoHandlerFilterManager.this.fireExceptionCaught(
+                                session, e );
                     }
                 }
             };
@@ -416,4 +425,4 @@
     {
         void execute( ByteBuffer buf, Object marker );
     }
-}
\ No newline at end of file
+}



Mime
View raw message