From a6ae7f150565140ce5db5da9bd07cc0e1992691b Mon Sep 17 00:00:00 2001 From: "Jeffrey(Xilang) Yan" Date: Tue, 14 Feb 2017 16:21:06 +0800 Subject: [PATCH] =?UTF-8?q?SelectorManager=E5=A2=9E=E5=8A=A0stopped?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gecko/core/nio/impl/SelectorManager.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/taobao/gecko/core/nio/impl/SelectorManager.java b/src/main/java/com/taobao/gecko/core/nio/impl/SelectorManager.java index 706ebf9..aa430c3 100644 --- a/src/main/java/com/taobao/gecko/core/nio/impl/SelectorManager.java +++ b/src/main/java/com/taobao/gecko/core/nio/impl/SelectorManager.java @@ -18,10 +18,10 @@ import java.io.IOException; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; - + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - + import com.taobao.gecko.core.config.Configuration; import com.taobao.gecko.core.core.EventType; import com.taobao.gecko.core.core.Session; @@ -63,8 +63,10 @@ public SelectorManager(final int selectorPoolSize, final NioController controlle } this.dividend = this.reactorSet.length - 1; } - - private volatile boolean started; + + //SelectorManager status: new -> started -> stopped + private volatile boolean started = false; + private volatile boolean stopped = false; public int getSelectorCount() { @@ -76,7 +78,8 @@ public synchronized void start() { if (this.started) { return; } - this.started = true; + this.started = true; + this.stopped = false; for (final Reactor reactor : this.reactorSet) { reactor.start(); } @@ -101,7 +104,8 @@ public synchronized void stop() { if (!this.started) { return; } - this.started = false; + this.started = false; + this.stopped = true; for (final Reactor reactor : this.reactorSet) { reactor.interrupt(); } @@ -148,7 +152,11 @@ void awaitReady() { } catch (final InterruptedException e) { Thread.currentThread().interrupt();// reset interrupt status - } + } + + if (this.stopped) { + throw new IllegalStateException("SelectorManager was stopped"); + } } } }