Don't create an EmbeddedSocketAddress every time

This commit is contained in:
Trustin Lee 2013-11-08 18:01:29 +09:00
parent 9125977692
commit daf15fc167
2 changed files with 10 additions and 4 deletions

View File

@ -44,6 +44,9 @@ import java.util.Queue;
*/
public class EmbeddedChannel extends AbstractChannel {
private static final SocketAddress LOCAL_ADDRESS = new EmbeddedSocketAddress();
private static final SocketAddress REMOTE_ADDRESS = new EmbeddedSocketAddress();
private static final ChannelHandler[] EMPTY_HANDLERS = new ChannelHandler[0];
private enum State { OPEN, ACTIVE, CLOSED }
@ -53,8 +56,6 @@ public class EmbeddedChannel extends AbstractChannel {
private final EmbeddedEventLoop loop;
private final ChannelConfig config = new DefaultChannelConfig(this);
private final SocketAddress localAddress = new EmbeddedSocketAddress();
private final SocketAddress remoteAddress = new EmbeddedSocketAddress();
private final Queue<Object> inboundMessages = new ArrayDeque<Object>();
private final Queue<Object> outboundMessages = new ArrayDeque<Object>();
private Throwable lastException;
@ -285,12 +286,12 @@ public class EmbeddedChannel extends AbstractChannel {
@Override
protected SocketAddress localAddress0() {
return isActive()? localAddress : null;
return isActive()? LOCAL_ADDRESS : null;
}
@Override
protected SocketAddress remoteAddress0() {
return isActive()? remoteAddress : null;
return isActive()? REMOTE_ADDRESS : null;
}
@Override

View File

@ -19,4 +19,9 @@ import java.net.SocketAddress;
final class EmbeddedSocketAddress extends SocketAddress {
private static final long serialVersionUID = 1400788804624980619L;
@Override
public String toString() {
return "embeded";
}
}