Remove code duplication in OIO transport / Make concrete unsafe final

This commit is contained in:
Trustin Lee 2012-08-29 12:58:00 +09:00
parent a3f25da228
commit dca860e0d5
8 changed files with 22 additions and 67 deletions

View File

@ -35,7 +35,7 @@ abstract class AbstractNioByteChannel extends AbstractNioChannel {
return new NioByteUnsafe();
}
final class NioByteUnsafe extends AbstractNioUnsafe {
private final class NioByteUnsafe extends AbstractNioUnsafe {
@Override
public void read() {
assert eventLoop().inEventLoop();

View File

@ -34,7 +34,7 @@ abstract class AbstractNioMessageChannel extends AbstractNioChannel {
return new NioMessageUnsafe();
}
final class NioMessageUnsafe extends AbstractNioUnsafe {
private final class NioMessageUnsafe extends AbstractNioUnsafe {
@Override
public void read() {
assert eventLoop().inEventLoop();

View File

@ -28,9 +28,11 @@ abstract class AbstractOioByteChannel extends AbstractOioChannel {
}
@Override
protected abstract AbstractOioByteUnsafe newUnsafe();
protected OioByteUnsafe newUnsafe() {
return new OioByteUnsafe();
}
abstract class AbstractOioByteUnsafe extends AbstractOioUnsafe {
private final class OioByteUnsafe extends AbstractOioUnsafe {
@Override
public void read() {
assert eventLoop().inEventLoop();

View File

@ -27,6 +27,8 @@ abstract class AbstractOioChannel extends AbstractChannel {
static final int SO_TIMEOUT = 1000;
protected volatile boolean readSuspended;
protected AbstractOioChannel(Channel parent, Integer id) {
super(parent, id);
}
@ -51,7 +53,6 @@ abstract class AbstractOioChannel extends AbstractChannel {
}
abstract class AbstractOioUnsafe extends AbstractUnsafe implements OioUnsafe {
@Override
public void connect(
final SocketAddress remoteAddress,
@ -82,6 +83,16 @@ abstract class AbstractOioChannel extends AbstractChannel {
});
}
}
@Override
public void suspendRead() {
readSuspended = true;
}
@Override
public void resumeRead() {
readSuspended = false;
}
}
@Override

View File

@ -28,9 +28,11 @@ abstract class AbstractOioMessageChannel extends AbstractOioChannel {
}
@Override
protected abstract AbstractOioMessageUnsafe newUnsafe();
protected OioMessageUnsafe newUnsafe() {
return new OioMessageUnsafe();
}
abstract class AbstractOioMessageUnsafe extends AbstractOioUnsafe {
private final class OioMessageUnsafe extends AbstractOioUnsafe {
@Override
public void read() {
assert eventLoop().inEventLoop();

View File

@ -52,8 +52,6 @@ public class OioDatagramChannel extends AbstractOioMessageChannel
private final DatagramChannelConfig config;
private final java.net.DatagramPacket tmpPacket = new java.net.DatagramPacket(EMPTY_DATA, 0);
private volatile boolean readSuspended;
private static MulticastSocket newSocket() {
try {
return new MulticastSocket(null);
@ -352,22 +350,4 @@ public class OioDatagramChannel extends AbstractOioMessageChannel
future.setFailure(new UnsupportedOperationException());
return future;
}
@Override
protected AbstractOioMessageUnsafe newUnsafe() {
return new OioDatagramChannelUnsafe();
}
private final class OioDatagramChannelUnsafe extends AbstractOioMessageUnsafe {
@Override
public void suspendRead() {
readSuspended = true;
}
@Override
public void resumeRead() {
readSuspended = false;
}
}
}

View File

@ -54,8 +54,6 @@ public class OioServerSocketChannel extends AbstractOioMessageChannel
final Lock shutdownLock = new ReentrantLock();
private final ServerSocketChannelConfig config;
private volatile boolean readSuspended;
public OioServerSocketChannel() {
this(newServerSocket());
}
@ -192,22 +190,4 @@ public class OioServerSocketChannel extends AbstractOioMessageChannel
protected void doWriteMessages(MessageBuf<Object> buf) throws Exception {
throw new UnsupportedOperationException();
}
@Override
protected AbstractOioMessageUnsafe newUnsafe() {
return new OioServerSocketUnsafe();
}
private final class OioServerSocketUnsafe extends AbstractOioMessageUnsafe {
@Override
public void suspendRead() {
readSuspended = true;
}
@Override
public void resumeRead() {
readSuspended = false;
}
}
}

View File

@ -46,7 +46,6 @@ public class OioSocketChannel extends AbstractOioByteChannel
private final SocketChannelConfig config;
private InputStream is;
private OutputStream os;
private volatile boolean readSuspended;
public OioSocketChannel() {
this(new Socket());
@ -186,23 +185,4 @@ public class OioSocketChannel extends AbstractOioByteChannel
}
buf.readBytes(os, buf.readableBytes());
}
@Override
protected AbstractOioByteUnsafe newUnsafe() {
return new OioSocketChannelUnsafe();
}
private final class OioSocketChannelUnsafe extends AbstractOioByteUnsafe {
@Override
public void suspendRead() {
readSuspended = true;
}
@Override
public void resumeRead() {
readSuspended = false;
}
}
}