You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2016/08/11 15:28:11 UTC

[01/10] mina git commit: Added some missing javadoc

Repository: mina
Updated Branches:
  refs/heads/2.0 35c0aac3d -> 5be12d6b6


Added some missing javadoc


Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/f119ff13
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/f119ff13
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/f119ff13

Branch: refs/heads/2.0
Commit: f119ff13d03877322887e5aef7481b140885bf27
Parents: 35c0aac
Author: Emmanuel L�charny <el...@symas.com>
Authored: Thu Mar 3 14:05:46 2016 +0100
Committer: Emmanuel L�charny <el...@symas.com>
Committed: Thu Mar 3 14:05:46 2016 +0100

----------------------------------------------------------------------
 .../core/service/DefaultTransportMetadata.java  | 22 ++++++++++++++++++++
 1 file changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/f119ff13/mina-core/src/main/java/org/apache/mina/core/service/DefaultTransportMetadata.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/service/DefaultTransportMetadata.java b/mina-core/src/main/java/org/apache/mina/core/service/DefaultTransportMetadata.java
index 1e05542..2c07e8c 100644
--- a/mina-core/src/main/java/org/apache/mina/core/service/DefaultTransportMetadata.java
+++ b/mina-core/src/main/java/org/apache/mina/core/service/DefaultTransportMetadata.java
@@ -39,6 +39,7 @@ public class DefaultTransportMetadata implements TransportMetadata {
 
     private final boolean connectionless;
 
+    /** The flag indicating that the transport support fragmentation or not */
     private final boolean fragmentation;
 
     private final Class<? extends SocketAddress> addressType;
@@ -97,30 +98,51 @@ public class DefaultTransportMetadata implements TransportMetadata {
         this.envelopeTypes = Collections.unmodifiableSet(newEnvelopeTypes);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public Class<? extends SocketAddress> getAddressType() {
         return addressType;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public Set<Class<? extends Object>> getEnvelopeTypes() {
         return envelopeTypes;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public Class<? extends IoSessionConfig> getSessionConfigType() {
         return sessionConfigType;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public String getProviderName() {
         return providerName;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public String getName() {
         return name;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public boolean isConnectionless() {
         return connectionless;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public boolean hasFragmentation() {
         return fragmentation;
     }


[05/10] mina git commit: o Destroy the session when it's closed immediately, instead of waiting for the NioProcessor to do it. o Made the CLOSE_REQUEST constant visible. o Exposed the destroy() method o Don't wrap the writeRequestQueue into a CloseAwareW

Posted by el...@apache.org.
o Destroy the session when it's closed immediately, instead of waiting
for the NioProcessor to do it.
o Made the CLOSE_REQUEST constant visible.
o Exposed the destroy() method
o Don't wrap the writeRequestQueue into a CloseAwareWriteQueue, this is
useless
o Removed the CloseAwareWriteQueue private class
o A bit of cleanup

Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/8c0ad040
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/8c0ad040
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/8c0ad040

Branch: refs/heads/2.0
Commit: 8c0ad040e7522ea0ed3a8210434b51b8435aa7e7
Parents: 0478d38
Author: Emmanuel L�charny <el...@symas.com>
Authored: Thu Aug 11 16:43:51 2016 +0200
Committer: Emmanuel L�charny <el...@symas.com>
Committed: Thu Aug 11 16:43:51 2016 +0200

----------------------------------------------------------------------
 .../mina/core/session/AbstractIoSession.java    | 97 ++++----------------
 1 file changed, 19 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/8c0ad040/mina-core/src/main/java/org/apache/mina/core/session/AbstractIoSession.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/session/AbstractIoSession.java b/mina-core/src/main/java/org/apache/mina/core/session/AbstractIoSession.java
index 7186fba..2addbac 100644
--- a/mina-core/src/main/java/org/apache/mina/core/session/AbstractIoSession.java
+++ b/mina-core/src/main/java/org/apache/mina/core/session/AbstractIoSession.java
@@ -95,7 +95,7 @@ public abstract class AbstractIoSession implements IoSession {
      * 
      * @see #writeRequestQueue
      */
-    private static final WriteRequest CLOSE_REQUEST = new DefaultWriteRequest(new Object());
+    public static final WriteRequest CLOSE_REQUEST = new DefaultWriteRequest(new Object());
 
     private final Object lock = new Object();
 
@@ -313,11 +313,7 @@ public abstract class AbstractIoSession implements IoSession {
      * {@inheritDoc}
      */
     public final CloseFuture close() {
-        try {
-            closeNow();
-        } finally {
-            return closeFuture;
-        }
+        return closeNow();
     }
 
     /**
@@ -327,10 +323,9 @@ public abstract class AbstractIoSession implements IoSession {
         if (!isClosing()) {
             getWriteRequestQueue().offer(this, CLOSE_REQUEST);
             getProcessor().flush(this);
-            return closeFuture;
-        } else {
-            return closeFuture;
         }
+        
+        return closeFuture;
     }
 
     /**
@@ -343,12 +338,26 @@ public abstract class AbstractIoSession implements IoSession {
             }
 
             closing = true;
+            
+            try {
+                destroy();
+            } catch (Exception e) {
+                IoFilterChain filterChain = getFilterChain();
+                filterChain.fireExceptionCaught(e);
+            }
         }
 
         getFilterChain().fireFilterClose();
 
         return closeFuture;
     }
+    
+    /**
+     * Destroy the session
+     *
+     */
+    protected void destroy() throws Exception {
+    }
 
     /**
      * {@inheritDoc}
@@ -676,7 +685,7 @@ public abstract class AbstractIoSession implements IoSession {
      * @param writeRequestQueue The write request queue
      */
     public final void setWriteRequestQueue(WriteRequestQueue writeRequestQueue) {
-        this.writeRequestQueue = new CloseAwareWriteQueue(writeRequestQueue);
+        this.writeRequestQueue = writeRequestQueue;
     }
 
     /**
@@ -1396,72 +1405,4 @@ public abstract class AbstractIoSession implements IoSession {
             }
         }
     }
-
-    /**
-     * A queue which handles the CLOSE request.
-     * 
-     * TODO : Check that when closing a session, all the pending requests are
-     * correctly sent.
-     */
-    private class CloseAwareWriteQueue implements WriteRequestQueue {
-
-        private final WriteRequestQueue queue;
-
-        /**
-         * {@inheritDoc}
-         */
-        public CloseAwareWriteQueue(WriteRequestQueue queue) {
-            this.queue = queue;
-        }
-
-        /**
-         * {@inheritDoc}
-         */
-        public synchronized WriteRequest poll(IoSession session) {
-            WriteRequest answer = queue.poll(session);
-
-            if (answer == CLOSE_REQUEST) {
-                AbstractIoSession.this.close( true );
-                dispose(session);
-                answer = null;
-            }
-
-            return answer;
-        }
-
-        /**
-         * {@inheritDoc}
-         */
-        public void offer(IoSession session, WriteRequest e) {
-            queue.offer(session, e);
-        }
-
-        /**
-         * {@inheritDoc}
-         */
-        public boolean isEmpty(IoSession session) {
-            return queue.isEmpty(session);
-        }
-
-        /**
-         * {@inheritDoc}
-         */
-        public void clear(IoSession session) {
-            queue.clear(session);
-        }
-
-        /**
-         * {@inheritDoc}
-         */
-        public void dispose(IoSession session) {
-            queue.dispose(session);
-        }
-
-        /**
-         * {@inheritDoc}
-         */
-        public int size() {
-            return queue.size();
-        }
-    }
 }


[07/10] mina git commit: o Process the new handle before doing a select() o Removed the ThreadSleep() at startup : we process the handle first, so we don't need to wait with a random value.

Posted by el...@apache.org.
o Process the new handle before doing a select()
o Removed the ThreadSleep() at startup : we process the handle first, so
we don't need to wait with a random value.

Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/d2aeee7b
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/d2aeee7b
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/d2aeee7b

Branch: refs/heads/2.0
Commit: d2aeee7bbe8a342bfe196bcebdda74ba69e62e7a
Parents: ebd9a5a
Author: Emmanuel L�charny <el...@symas.com>
Authored: Thu Aug 11 16:47:22 2016 +0200
Committer: Emmanuel L�charny <el...@symas.com>
Committed: Thu Aug 11 16:47:22 2016 +0200

----------------------------------------------------------------------
 .../core/polling/AbstractPollingIoAcceptor.java     | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/d2aeee7b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoAcceptor.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoAcceptor.java b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoAcceptor.java
index 5c862fb..f9fad07 100644
--- a/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoAcceptor.java
+++ b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoAcceptor.java
@@ -356,8 +356,6 @@ public abstract class AbstractPollingIoAcceptor<S extends AbstractIoSession, H>
         try {
             lock.acquire();
 
-            // Wait a bit to give a chance to the Acceptor thread to do the select()
-            Thread.sleep(10);
             wakeup();
         } finally {
             lock.release();
@@ -447,17 +445,20 @@ public abstract class AbstractPollingIoAcceptor<S extends AbstractIoSession, H>
 
             while (selectable) {
                 try {
+                    // Process the bound sockets to this acceptor.
+                    // this actually sets the selector to OP_ACCEPT,
+                    // and binds to the port on which this class will
+                    // listen on. We do that before the select because 
+                    // the registerQueue containing the new handler is
+                    // already updated at this point.
+                    nHandles += registerHandles();
+
                     // Detect if we have some keys ready to be processed
                     // The select() will be woke up if some new connection
                     // have occurred, or if the selector has been explicitly
                     // woke up
                     int selected = select();
 
-                    // this actually sets the selector to OP_ACCEPT,
-                    // and binds to the port on which this class will
-                    // listen on
-                    nHandles += registerHandles();
-
                     // Now, if the number of registred handles is 0, we can
                     // quit the loop: we don't have any socket listening
                     // for incoming connection.
@@ -592,6 +593,7 @@ public abstract class AbstractPollingIoAcceptor<S extends AbstractIoSession, H>
 
                 // and notify.
                 future.setDone();
+                
                 return newHandles.size();
             } catch (Exception e) {
                 // We store the exception in the future


[02/10] mina git commit: No need to call session.closeNow() if the session is currently being closed

Posted by el...@apache.org.
No need to call session.closeNow() if the session is currently being closed


Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/3b6c4464
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/3b6c4464
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/3b6c4464

Branch: refs/heads/2.0
Commit: 3b6c44642bdd07b2fb6b40015b62d7c6b5450dea
Parents: f119ff1
Author: Emmanuel L�charny <el...@symas.com>
Authored: Sun Jul 24 21:30:18 2016 +0200
Committer: Emmanuel L�charny <el...@symas.com>
Committed: Sun Jul 24 21:30:18 2016 +0200

----------------------------------------------------------------------
 .../org/apache/mina/core/filterchain/DefaultIoFilterChain.java | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/3b6c4464/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java b/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java
index 2d301c5..a843a74 100644
--- a/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java
+++ b/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java
@@ -594,7 +594,11 @@ public class DefaultIoFilterChain implements IoFilterChain {
         } else {
             // Please note that this place is not the only place that
             // calls ConnectFuture.setException().
-            session.close(true);
+            if (!session.isClosing()) {
+                // Call the closeNow method only if needed
+                session.closeNow();
+            }
+            
             future.setException(cause);
         }
     }


[03/10] mina git commit: CLose the channel only when it's not already closed

Posted by el...@apache.org.
CLose the channel only when it's not already closed


Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/0a28b4ea
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/0a28b4ea
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/0a28b4ea

Branch: refs/heads/2.0
Commit: 0a28b4eae07e9d348ec6ecd0b004888b698d9818
Parents: 3b6c446
Author: Emmanuel L�charny <el...@symas.com>
Authored: Thu Aug 11 16:26:46 2016 +0200
Committer: Emmanuel L�charny <el...@symas.com>
Committed: Thu Aug 11 16:26:46 2016 +0200

----------------------------------------------------------------------
 .../org/apache/mina/transport/socket/nio/NioProcessor.java  | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/0a28b4ea/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java
index f621bcf..8202e18 100644
--- a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java
+++ b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java
@@ -135,11 +135,16 @@ public final class NioProcessor extends AbstractPollingIoProcessor<NioSession> {
     @Override
     protected void destroy(NioSession session) throws Exception {
         ByteChannel ch = session.getChannel();
+        
         SelectionKey key = session.getSelectionKey();
+        
         if (key != null) {
             key.cancel();
         }
-        ch.close();
+        
+        if ( ch.isOpen() ) {
+            ch.close();
+        }
     }
 
     /**
@@ -313,7 +318,7 @@ public final class NioProcessor extends AbstractPollingIoProcessor<NioSession> {
     }
 
     @Override
-    protected int write(NioSession session, IoBuffer buf, int length) throws Exception {
+    protected int write(NioSession session, IoBuffer buf, int length) throws IOException {
         if (buf.remaining() <= length) {
             return session.getChannel().write(buf.buf());
         }


[04/10] mina git commit: Added the destroy() method in the NioSession class. It closes the channel and cancels the selectionKey

Posted by el...@apache.org.
Added the destroy() method in the NioSession class. It closes the
channel and cancels the selectionKey

Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/0478d386
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/0478d386
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/0478d386

Branch: refs/heads/2.0
Commit: 0478d386b283fb7eced6fbb3b2bf576531a934e2
Parents: 0a28b4e
Author: Emmanuel L�charny <el...@symas.com>
Authored: Thu Aug 11 16:39:23 2016 +0200
Committer: Emmanuel L�charny <el...@symas.com>
Committed: Thu Aug 11 16:39:23 2016 +0200

----------------------------------------------------------------------
 .../mina/transport/socket/nio/NioSocketSession.java      | 11 +++++++++++
 1 file changed, 11 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/0478d386/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java
index 5b1b0c9..4a3e93c 100644
--- a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java
+++ b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketSession.java
@@ -22,6 +22,8 @@ package org.apache.mina.transport.socket.nio;
 import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.SocketException;
+import java.nio.channels.ByteChannel;
+import java.nio.channels.SelectionKey;
 import java.nio.channels.SocketChannel;
 
 import org.apache.mina.core.RuntimeIoException;
@@ -115,6 +117,15 @@ class NioSocketSession extends NioSession {
         return (InetSocketAddress) socket.getLocalSocketAddress();
     }
 
+    protected void destroy(NioSession session) throws Exception {
+        ByteChannel ch = session.getChannel();
+        SelectionKey key = session.getSelectionKey();
+        if (key != null) {
+            key.cancel();
+        }
+        ch.close();
+    }
+
     @Override
     public InetSocketAddress getServiceAddress() {
         return (InetSocketAddress) super.getServiceAddress();


[08/10] mina git commit: Added a method to let the user set the fragmentation option

Posted by el...@apache.org.
Added a method to let the user set the fragmentation option

Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/e5d3a647
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/e5d3a647
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/e5d3a647

Branch: refs/heads/2.0
Commit: e5d3a6477a01bb1b3c8ac18b7eeede8c5921cd03
Parents: d2aeee7
Author: Emmanuel L�charny <el...@symas.com>
Authored: Thu Aug 11 16:49:41 2016 +0200
Committer: Emmanuel L�charny <el...@symas.com>
Committed: Thu Aug 11 16:49:41 2016 +0200

----------------------------------------------------------------------
 .../filter/codec/CumulativeProtocolDecoder.java  | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/e5d3a647/mina-core/src/main/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java b/mina-core/src/main/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
index 227fbfd..ebeae0d 100644
--- a/mina-core/src/main/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
+++ b/mina-core/src/main/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
@@ -99,8 +99,13 @@ import org.apache.mina.core.session.IoSession;
  * @author <a href="http://mina.apache.org">Apache MINA Project</a>
  */
 public abstract class CumulativeProtocolDecoder extends ProtocolDecoderAdapter {
-
+    /** The buffer used to store the data in the session */
     private final AttributeKey BUFFER = new AttributeKey(getClass(), "buffer");
+    
+    /** A flag set to true if we handle fragmentation accordingly to the TransportMetadata setting. 
+     * It can be set to false if needed (UDP with fragments, for instance). the default value is 'true'
+     */
+    private boolean transportMetadataFragmentation = true;
 
     /**
      * Creates a new instance.
@@ -121,7 +126,7 @@ public abstract class CumulativeProtocolDecoder extends ProtocolDecoderAdapter {
      *             consuming the cumulative buffer.
      */
     public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
-        if (!session.getTransportMetadata().hasFragmentation()) {
+        if (transportMetadataFragmentation && !session.getTransportMetadata().hasFragmentation()) {
             while (in.hasRemaining()) {
                 if (!doDecode(session, in, out)) {
                     break;
@@ -241,4 +246,14 @@ public abstract class CumulativeProtocolDecoder extends ProtocolDecoderAdapter {
 
         session.setAttribute(BUFFER, remainingBuf);
     }
+    
+    /**
+     * Let the user change the way we handle fragmentation. If set to <tt>false</tt>, the 
+     * decode() method will not check the TransportMetadata fragmentation capability
+     *  
+     * @param handleFragment The flag to set.
+     */
+    public void setTransportMetadataFragmentation(boolean transportMetadataFragmentation) {
+        this.transportMetadataFragmentation = transportMetadataFragmentation;
+    }
 }


[10/10] mina git commit: Call closeNow() instead of close(true)

Posted by el...@apache.org.
Call closeNow() instead of close(true)

Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/5be12d6b
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/5be12d6b
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/5be12d6b

Branch: refs/heads/2.0
Commit: 5be12d6b67bd53bfc08b876edff48b9a9092da6d
Parents: 0aefa80
Author: Emmanuel L�charny <el...@symas.com>
Authored: Thu Aug 11 17:27:52 2016 +0200
Committer: Emmanuel L�charny <el...@symas.com>
Committed: Thu Aug 11 17:27:52 2016 +0200

----------------------------------------------------------------------
 .../org/apache/mina/core/polling/AbstractPollingIoProcessor.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/5be12d6b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
index 48604c8..c0f7ba8 100644
--- a/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
+++ b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
@@ -767,7 +767,7 @@ public abstract class AbstractPollingIoProcessor<S extends AbstractIoSession> im
                         }
                     } catch (Exception e) {
                         scheduleRemove(session);
-                        session.close(true);
+                        session.closeNow();
                         IoFilterChain filterChain = session.getFilterChain();
                         filterChain.fireExceptionCaught(e);
                     }


[06/10] mina git commit: o The poll() method close and dispose the session if the CLOSE_REQUEST message is read from the WriteRequestQueue o Don't call super() when not needed

Posted by el...@apache.org.
o The poll() method close and dispose the session if the CLOSE_REQUEST
message is read from the WriteRequestQueue
o Don't call super() when not needed

Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/ebd9a5aa
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/ebd9a5aa
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/ebd9a5aa

Branch: refs/heads/2.0
Commit: ebd9a5aa3cc7e134261976f914eaf7771f79f8a0
Parents: 8c0ad04
Author: Emmanuel L�charny <el...@symas.com>
Authored: Thu Aug 11 16:45:38 2016 +0200
Committer: Emmanuel L�charny <el...@symas.com>
Committed: Thu Aug 11 16:45:38 2016 +0200

----------------------------------------------------------------------
 .../session/DefaultIoSessionDataStructureFactory.java    | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/ebd9a5aa/mina-core/src/main/java/org/apache/mina/core/session/DefaultIoSessionDataStructureFactory.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/session/DefaultIoSessionDataStructureFactory.java b/mina-core/src/main/java/org/apache/mina/core/session/DefaultIoSessionDataStructureFactory.java
index 53ad09d..3fd0ca1 100644
--- a/mina-core/src/main/java/org/apache/mina/core/session/DefaultIoSessionDataStructureFactory.java
+++ b/mina-core/src/main/java/org/apache/mina/core/session/DefaultIoSessionDataStructureFactory.java
@@ -182,7 +182,6 @@ public class DefaultIoSessionDataStructureFactory implements IoSessionDataStruct
          * Default constructor
          */
         public DefaultWriteRequestQueue() {
-            super();
         }
 
         /**
@@ -217,7 +216,15 @@ public class DefaultIoSessionDataStructureFactory implements IoSessionDataStruct
          * {@inheritDoc}
          */
         public synchronized WriteRequest poll(IoSession session) {
-            return q.poll();
+            WriteRequest answer = q.poll();
+
+            if (answer == AbstractIoSession.CLOSE_REQUEST) {
+                session.closeNow();
+                dispose(session);
+                answer = null;
+            }
+
+            return answer;
         }
 
         @Override


[09/10] mina git commit: o The write() method now throws an IoException o Called the closeNow() method instead of close(true) o Called the removeNow() method instead of destroy() when we get an exception while writing a buffer

Posted by el...@apache.org.
o The write() method now throws an IoException
o Called the closeNow() method instead of close(true)
o Called the removeNow() method instead of destroy() when we get an
exception while writing a buffer

Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/0aefa807
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/0aefa807
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/0aefa807

Branch: refs/heads/2.0
Commit: 0aefa80711be8d078eb57d10f446e256120c31fd
Parents: e5d3a64
Author: Emmanuel L�charny <el...@symas.com>
Authored: Thu Aug 11 17:13:58 2016 +0200
Committer: Emmanuel L�charny <el...@symas.com>
Committed: Thu Aug 11 17:13:58 2016 +0200

----------------------------------------------------------------------
 .../polling/AbstractPollingIoProcessor.java     | 65 ++++++++++----------
 .../socket/nio/PollingIoProcessorTest.java      |  2 +-
 .../transport/socket/apr/AprIoProcessor.java    |  2 +-
 3 files changed, 34 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/0aefa807/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
index 310a7ae..48604c8 100644
--- a/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
+++ b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
@@ -341,7 +341,7 @@ public abstract class AbstractPollingIoProcessor<S extends AbstractIoSession> im
      * @return the number of byte written
      * @throws Exception any exception thrown by the underlying system calls
      */
-    protected abstract int write(S session, IoBuffer buf, int length) throws Exception;
+    protected abstract int write(S session, IoBuffer buf, int length) throws IOException;
 
     /**
      * Write a part of a file to a {@link IoSession}, if the underlying API
@@ -757,36 +757,36 @@ public abstract class AbstractPollingIoProcessor<S extends AbstractIoSession> im
             SessionState state = getState(session);
 
             switch (state) {
-            case OPENED:
-                try {
-                    boolean flushedAll = flushNow(session, currentTime);
-
-                    if (flushedAll && !session.getWriteRequestQueue().isEmpty(session)
-                            && !session.isScheduledForFlush()) {
-                        scheduleFlush(session);
+                case OPENED:
+                    try {
+                        boolean flushedAll = flushNow(session, currentTime);
+    
+                        if (flushedAll && !session.getWriteRequestQueue().isEmpty(session)
+                                && !session.isScheduledForFlush()) {
+                            scheduleFlush(session);
+                        }
+                    } catch (Exception e) {
+                        scheduleRemove(session);
+                        session.close(true);
+                        IoFilterChain filterChain = session.getFilterChain();
+                        filterChain.fireExceptionCaught(e);
                     }
-                } catch (Exception e) {
-                    scheduleRemove(session);
-                    session.close(true);
-                    IoFilterChain filterChain = session.getFilterChain();
-                    filterChain.fireExceptionCaught(e);
-                }
-
-                break;
-
-            case CLOSING:
-                // Skip if the channel is already closed.
-                break;
-
-            case OPENING:
-                // Retry later if session is not yet fully initialized.
-                // (In case that Session.write() is called before addSession()
-                // is processed)
-                scheduleFlush(session);
-                return;
-
-            default:
-                throw new IllegalStateException(String.valueOf(state));
+    
+                    break;
+    
+                case CLOSING:
+                    // Skip if the channel is already closed.
+                    break;
+    
+                case OPENING:
+                    // Retry later if session is not yet fully initialized.
+                    // (In case that Session.write() is called before addSession()
+                    // is processed)
+                    scheduleFlush(session);
+                    return;
+    
+                default:
+                    throw new IllegalStateException(String.valueOf(state));
             }
 
         } while (!flushingSessions.isEmpty());
@@ -911,12 +911,11 @@ public abstract class AbstractPollingIoProcessor<S extends AbstractIoSession> im
                 // We have had an issue while trying to send data to the
                 // peer : let's close the session.
                 buf.free();
-                session.close(true);
-                destroy(session);
+                session.closeNow();
+                removeNow(session);
 
                 return 0;
             }
-
         }
 
         session.increaseWrittenBytes(localWrittenBytes, currentTime);

http://git-wip-us.apache.org/repos/asf/mina/blob/0aefa807/mina-core/src/test/java/org/apache/mina/transport/socket/nio/PollingIoProcessorTest.java
----------------------------------------------------------------------
diff --git a/mina-core/src/test/java/org/apache/mina/transport/socket/nio/PollingIoProcessorTest.java b/mina-core/src/test/java/org/apache/mina/transport/socket/nio/PollingIoProcessorTest.java
index f65e512..379f55b 100644
--- a/mina-core/src/test/java/org/apache/mina/transport/socket/nio/PollingIoProcessorTest.java
+++ b/mina-core/src/test/java/org/apache/mina/transport/socket/nio/PollingIoProcessorTest.java
@@ -148,7 +148,7 @@ public class PollingIoProcessorTest {
             }
 
             @Override
-            protected int write(NioSession session, IoBuffer buf, int length) throws Exception {
+            protected int write(NioSession session, IoBuffer buf, int length) throws IOException {
                 throw new NoRouteToHostException("No Route To Host Test");
             }
 

http://git-wip-us.apache.org/repos/asf/mina/blob/0aefa807/mina-transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprIoProcessor.java
----------------------------------------------------------------------
diff --git a/mina-transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprIoProcessor.java b/mina-transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprIoProcessor.java
index 6a85d02..79fe741 100644
--- a/mina-transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprIoProcessor.java
+++ b/mina-transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprIoProcessor.java
@@ -420,7 +420,7 @@ public final class AprIoProcessor extends AbstractPollingIoProcessor<AprSession>
      * {@inheritDoc}
      */
     @Override
-    protected int write(AprSession session, IoBuffer buf, int length) throws Exception {
+    protected int write(AprSession session, IoBuffer buf, int length) throws IOException {
         int writtenBytes;
         if (buf.isDirect()) {
             writtenBytes = Socket.sendb(session.getDescriptor(), buf.buf(), buf.position(), length);