directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r332564 - in /directory/network/trunk/src/java/org/apache/mina: common/support/ transport/socket/nio/support/
Date Fri, 11 Nov 2005 14:27:07 GMT
Author: trustin
Date: Fri Nov 11 06:27:01 2005
New Revision: 332564

URL: http://svn.apache.org/viewcvs?rev=332564&view=rev
Log:
Resolved issue: DIRMINA-113 SocketIoProcessor should use ExceptionMonitor to log exceptions.
* SocketIoProcessor is not a singleton anymore.  There's one SocketIoProcessor per SocketAcceptor(or
SocketConnector)
* Changed the selector of SocketIoProcessor is initialized when Worker thread starts (lazy
initialization)

Related issue: DIRMINA-119 Multiple selector loops

Modified:
    directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionManagerFilterChain.java

Modified: directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java?rev=332564&r1=332563&r2=332564&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
Fri Nov 11 06:27:01 2005
@@ -126,7 +126,7 @@
             }
             
             public void filterWrite( NextFilter nextFilter, IoSession session,
-                                     WriteRequest writeRequest )
+                                     WriteRequest writeRequest ) throws Exception
             {
                 if( session.getTransportType().getEnvelopeType().isAssignableFrom( writeRequest.getMessage().getClass()
) )
                 {
@@ -637,9 +637,9 @@
         }
     }
 
-    protected abstract void doWrite( IoSession session, WriteRequest writeRequest );
+    protected abstract void doWrite( IoSession session, WriteRequest writeRequest ) throws
Exception;
     
-    protected abstract void doClose( IoSession session, CloseFuture closeFuture );
+    protected abstract void doClose( IoSession session, CloseFuture closeFuture ) throws
Exception;
 
     private class Entry
     {

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java?rev=332564&r1=332563&r2=332564&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
Fri Nov 11 06:27:01 2005
@@ -65,6 +65,7 @@
     private final Queue cancelQueue = new Queue();
     
     private Worker worker;
+    private final SocketIoProcessor ioProcessor = new SocketIoProcessor( this );
 
 
     /**
@@ -293,9 +294,9 @@
                 try
                 {
                     RegistrationRequest req = ( RegistrationRequest ) key.attachment();
-                    SocketSessionImpl session = new SocketSessionImpl( filters, ch, req.handler
);
+                    SocketSessionImpl session = new SocketSessionImpl( ioProcessor, filters,
ch, req.handler );
                     session.getManagerFilterChain().sessionCreated( session );
-                    SocketIoProcessor.getInstance().addNew( session );
+                    session.getIoProcessor().addNew( session );
                     success = true;
                 }
                 catch( Throwable t )

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java?rev=332564&r1=332563&r2=332564&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
Fri Nov 11 06:27:01 2005
@@ -59,6 +59,8 @@
     private final Queue connectQueue = new Queue();
 
     private Worker worker;
+    
+    private final SocketIoProcessor ioProcessor = new SocketIoProcessor( this );
 
     /**
      * Creates a new instance.
@@ -241,7 +243,7 @@
 
     private SocketSessionImpl newSession( SocketChannel ch, IoHandler handler ) throws IOException
     {
-        SocketSessionImpl session = new SocketSessionImpl( filters, ch, handler );
+        SocketSessionImpl session = new SocketSessionImpl( ioProcessor, filters, ch, handler
);
         try
         {
             session.getManagerFilterChain().sessionCreated( session );
@@ -250,7 +252,7 @@
         {
             ExceptionUtil.throwException( e );
         }
-        SocketIoProcessor.getInstance().addNew( session );
+        session.getIoProcessor().addNew( session );
         return session;
     }
 

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java?rev=332564&r1=332563&r2=332564&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
Fri Nov 11 06:27:01 2005
@@ -27,11 +27,10 @@
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoSessionManager;
 import org.apache.mina.common.WriteTimeoutException;
 import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.util.Queue;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Performs all I/O operations for sockets which is connected or bound.
@@ -42,29 +41,8 @@
  */
 class SocketIoProcessor
 {
-    private static final Logger log = LoggerFactory.getLogger( SocketIoProcessor.class );

-    private static final SocketIoProcessor instance;
-
-    static
-    {
-        SocketIoProcessor tmp;
-
-        try
-        {
-            tmp = new SocketIoProcessor();
-        }
-        catch( IOException e )
-        {
-            InternalError error = new InternalError(
-                                                     "Failed to open selector." );
-            error.initCause( e );
-            throw error;
-        }
-
-        instance = tmp;
-    }
-
-    private final Selector selector;
+    private final IoSessionManager parent;
+    private Selector selector;
 
     private final Queue newSessions = new Queue();
     private final Queue removingSessions = new Queue();
@@ -75,17 +53,12 @@
 
     private long lastIdleCheckTime = System.currentTimeMillis();
 
-    private SocketIoProcessor() throws IOException
-    {
-        selector = Selector.open();
-    }
-
-    public static SocketIoProcessor getInstance()
+    SocketIoProcessor( IoSessionManager parent )
     {
-        return instance;
+        this.parent = parent;
     }
 
-    void addNew( SocketSessionImpl session )
+    void addNew( SocketSessionImpl session ) throws IOException
     {
         synchronized( this )
         {
@@ -99,17 +72,18 @@
         selector.wakeup();
     }
 
-    void remove( SocketSessionImpl session )
+    void remove( SocketSessionImpl session ) throws IOException
     {
         scheduleRemove( session );
         startupWorker();
         selector.wakeup();
     }
 
-    private synchronized void startupWorker()
+    private synchronized void startupWorker() throws IOException
     {
         if( worker == null )
         {
+            selector = Selector.open();
             worker = new Worker();
             worker.start();
         }
@@ -590,6 +564,18 @@
                                 newSessions.isEmpty() )
                             {
                                 worker = null;
+                                try
+                                {
+                                    selector.close();
+                                }
+                                catch( IOException e )
+                                {
+                                    parent.getExceptionMonitor().exceptionCaught( parent,
e );
+                                }
+                                finally
+                                {
+                                    selector = null;
+                                }
                                 break;
                             }
                         }
@@ -597,7 +583,7 @@
                 }
                 catch( Throwable t )
                 {
-                    log.warn( "Unexpected exception.", t );
+                    parent.getExceptionMonitor().exceptionCaught( parent, t );
 
                     try
                     {

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java?rev=332564&r1=332563&r2=332564&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java
Fri Nov 11 06:27:01 2005
@@ -46,6 +46,7 @@
 {
     private static final int DEFAULT_READ_BUFFER_SIZE = 1024;
 
+    private final SocketIoProcessor ioProcessor;
     private final IoSessionManagerFilterChain managerFilterChain;
     private final IoSessionFilterChain filterChain;
     private final SocketChannel ch;
@@ -60,9 +61,12 @@
     /**
      * Creates a new instance.
      */
-    public SocketSessionImpl( IoSessionManagerFilterChain managerFilterChain,
-                   SocketChannel ch, IoHandler defaultHandler )
+    public SocketSessionImpl(
+            SocketIoProcessor ioProcessor,
+            IoSessionManagerFilterChain managerFilterChain,
+            SocketChannel ch, IoHandler defaultHandler )
     {
+        this.ioProcessor = ioProcessor;
         this.managerFilterChain = managerFilterChain;
         this.filterChain = new IoSessionFilterChain( this, managerFilterChain );
         this.ch = ch;
@@ -72,6 +76,11 @@
         this.localAddress = ch.socket().getLocalSocketAddress();
     }
     
+    SocketIoProcessor getIoProcessor()
+    {
+        return ioProcessor;
+    }
+    
     IoSessionManagerFilterChain getManagerFilterChain()
     {
         return managerFilterChain;
@@ -254,6 +263,6 @@
 
     protected void updateTrafficMask()
     {
-        SocketIoProcessor.getInstance().updateTrafficMask( this );
+        this.ioProcessor.updateTrafficMask( this );
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionManagerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionManagerFilterChain.java?rev=332564&r1=332563&r2=332564&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionManagerFilterChain.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionManagerFilterChain.java
Fri Nov 11 06:27:01 2005
@@ -1,5 +1,7 @@
 package org.apache.mina.transport.socket.nio.support;
 
+import java.io.IOException;
+
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.IoFilterChain;
@@ -33,13 +35,14 @@
             if( writeRequestQueue.size() == 1 && session.getTrafficMask().isWritable()
)
             {
                 // Notify SocketIoProcessor only when writeRequestQueue was empty.
-                SocketIoProcessor.getInstance().flush( s );
+                s.getIoProcessor().flush( s );
             }
         }
     }
 
-    protected void doClose( IoSession session, CloseFuture closeFuture )
+    protected void doClose( IoSession session, CloseFuture closeFuture ) throws IOException
     {
-        SocketIoProcessor.getInstance().remove( ( SocketSessionImpl ) session );
+        SocketSessionImpl s = ( SocketSessionImpl ) session;
+        s.getIoProcessor().remove( s );
     }
 }



Mime
View raw message