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:15 UTC
[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
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();
- }
- }
}