Remove code duplication in OIO transport / Make concrete unsafe final
This commit is contained in:
parent
a3f25da228
commit
dca860e0d5
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user