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"); + } } } }