use enum for state in EmbeddedChannel
This commit is contained in:
parent
4bca1c3fe3
commit
f80109f423
@ -44,6 +44,8 @@ import java.util.Queue;
|
|||||||
*/
|
*/
|
||||||
public class EmbeddedChannel extends AbstractChannel {
|
public class EmbeddedChannel extends AbstractChannel {
|
||||||
|
|
||||||
|
private enum State { OPEN, ACTIVE, CLOSED };
|
||||||
|
|
||||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(EmbeddedChannel.class);
|
private static final InternalLogger logger = InternalLoggerFactory.getInstance(EmbeddedChannel.class);
|
||||||
|
|
||||||
private static final ChannelMetadata METADATA = new ChannelMetadata(false);
|
private static final ChannelMetadata METADATA = new ChannelMetadata(false);
|
||||||
@ -55,7 +57,7 @@ public class EmbeddedChannel extends AbstractChannel {
|
|||||||
private final Queue<Object> inboundMessages = new ArrayDeque<Object>();
|
private final Queue<Object> inboundMessages = new ArrayDeque<Object>();
|
||||||
private final Queue<Object> outboundMessages = new ArrayDeque<Object>();
|
private final Queue<Object> outboundMessages = new ArrayDeque<Object>();
|
||||||
private Throwable lastException;
|
private Throwable lastException;
|
||||||
private int state; // 0 = OPEN, 1 = ACTIVE, 2 = CLOSED
|
private State state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance
|
* Create a new instance
|
||||||
@ -99,12 +101,12 @@ public class EmbeddedChannel extends AbstractChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOpen() {
|
public boolean isOpen() {
|
||||||
return state < 2;
|
return state != State.CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return state == 1;
|
return state == State.ACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -289,7 +291,7 @@ public class EmbeddedChannel extends AbstractChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doRegister() throws Exception {
|
protected void doRegister() throws Exception {
|
||||||
state = 1;
|
state = State.ACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -304,7 +306,7 @@ public class EmbeddedChannel extends AbstractChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doClose() throws Exception {
|
protected void doClose() throws Exception {
|
||||||
state = 2;
|
state = State.CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user