From 029a277eaa774ab8d291dab1a24aa994b6017cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9C=B0=E5=B9=B3=E7=BA=BF?= <22250530@qq.com> Date: Wed, 16 Sep 2015 19:54:20 +0800 Subject: [PATCH] --- .../wentch/redkale/net/AsyncConnection.java | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/com/wentch/redkale/net/AsyncConnection.java b/src/com/wentch/redkale/net/AsyncConnection.java index 9ecff75b5..560ecd791 100644 --- a/src/com/wentch/redkale/net/AsyncConnection.java +++ b/src/com/wentch/redkale/net/AsyncConnection.java @@ -38,7 +38,23 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl protected abstract void write(ByteBuffer[] srcs, int offset, int length, A attachment, CompletionHandler handler); - public abstract void dispose(); //同close, 只是去掉throws IOException + public void dispose() {//同close, 只是去掉throws IOException + try { + this.close(); + } catch (IOException io) { + } + } + + @Override + public void close() throws IOException { + if (attributes == null) return; + try { + for (Object obj : attributes.values()) { + if (obj instanceof AutoCloseable) ((AutoCloseable) obj).close(); + } + } catch (Exception io) { + } + } public void setAttribute(String name, Object value) { if (attributes == null) attributes = new HashMap<>(); @@ -173,19 +189,12 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl @Override public final void close() throws IOException { + super.close(); if (client) { channel.close(); } } - @Override - public void dispose() { - try { - this.close(); - } catch (IOException io) { - } - } - @Override public final boolean isOpen() { return channel.isOpen(); @@ -323,14 +332,6 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl } } - @Override - public void dispose() { - try { - this.close(); - } catch (IOException io) { - } - } - @Override public void read(ByteBuffer dst, A attachment, CompletionHandler handler) { try { @@ -373,6 +374,7 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl @Override public void close() throws IOException { + super.close(); this.socket.close(); } @@ -488,6 +490,7 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl @Override public final void close() throws IOException { + super.close(); channel.close(); } @@ -501,13 +504,6 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl return true; } - @Override - public void dispose() { - try { - this.close(); - } catch (IOException io) { - } - } } public static AsyncConnection create(final AsynchronousSocketChannel ch) {