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();
|
return new NioByteUnsafe();
|
||||||
}
|
}
|
||||||
|
|
||||||
final class NioByteUnsafe extends AbstractNioUnsafe {
|
private final class NioByteUnsafe extends AbstractNioUnsafe {
|
||||||
@Override
|
@Override
|
||||||
public void read() {
|
public void read() {
|
||||||
assert eventLoop().inEventLoop();
|
assert eventLoop().inEventLoop();
|
||||||
|
@ -34,7 +34,7 @@ abstract class AbstractNioMessageChannel extends AbstractNioChannel {
|
|||||||
return new NioMessageUnsafe();
|
return new NioMessageUnsafe();
|
||||||
}
|
}
|
||||||
|
|
||||||
final class NioMessageUnsafe extends AbstractNioUnsafe {
|
private final class NioMessageUnsafe extends AbstractNioUnsafe {
|
||||||
@Override
|
@Override
|
||||||
public void read() {
|
public void read() {
|
||||||
assert eventLoop().inEventLoop();
|
assert eventLoop().inEventLoop();
|
||||||
|
@ -28,9 +28,11 @@ abstract class AbstractOioByteChannel extends AbstractOioChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected abstract AbstractOioByteUnsafe newUnsafe();
|
protected OioByteUnsafe newUnsafe() {
|
||||||
|
return new OioByteUnsafe();
|
||||||
|
}
|
||||||
|
|
||||||
abstract class AbstractOioByteUnsafe extends AbstractOioUnsafe {
|
private final class OioByteUnsafe extends AbstractOioUnsafe {
|
||||||
@Override
|
@Override
|
||||||
public void read() {
|
public void read() {
|
||||||
assert eventLoop().inEventLoop();
|
assert eventLoop().inEventLoop();
|
||||||
|
@ -27,6 +27,8 @@ abstract class AbstractOioChannel extends AbstractChannel {
|
|||||||
|
|
||||||
static final int SO_TIMEOUT = 1000;
|
static final int SO_TIMEOUT = 1000;
|
||||||
|
|
||||||
|
protected volatile boolean readSuspended;
|
||||||
|
|
||||||
protected AbstractOioChannel(Channel parent, Integer id) {
|
protected AbstractOioChannel(Channel parent, Integer id) {
|
||||||
super(parent, id);
|
super(parent, id);
|
||||||
}
|
}
|
||||||
@ -51,7 +53,6 @@ abstract class AbstractOioChannel extends AbstractChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class AbstractOioUnsafe extends AbstractUnsafe implements OioUnsafe {
|
abstract class AbstractOioUnsafe extends AbstractUnsafe implements OioUnsafe {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(
|
public void connect(
|
||||||
final SocketAddress remoteAddress,
|
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
|
@Override
|
||||||
|
@ -28,9 +28,11 @@ abstract class AbstractOioMessageChannel extends AbstractOioChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected abstract AbstractOioMessageUnsafe newUnsafe();
|
protected OioMessageUnsafe newUnsafe() {
|
||||||
|
return new OioMessageUnsafe();
|
||||||
|
}
|
||||||
|
|
||||||
abstract class AbstractOioMessageUnsafe extends AbstractOioUnsafe {
|
private final class OioMessageUnsafe extends AbstractOioUnsafe {
|
||||||
@Override
|
@Override
|
||||||
public void read() {
|
public void read() {
|
||||||
assert eventLoop().inEventLoop();
|
assert eventLoop().inEventLoop();
|
||||||
|
@ -52,8 +52,6 @@ public class OioDatagramChannel extends AbstractOioMessageChannel
|
|||||||
private final DatagramChannelConfig config;
|
private final DatagramChannelConfig config;
|
||||||
private final java.net.DatagramPacket tmpPacket = new java.net.DatagramPacket(EMPTY_DATA, 0);
|
private final java.net.DatagramPacket tmpPacket = new java.net.DatagramPacket(EMPTY_DATA, 0);
|
||||||
|
|
||||||
private volatile boolean readSuspended;
|
|
||||||
|
|
||||||
private static MulticastSocket newSocket() {
|
private static MulticastSocket newSocket() {
|
||||||
try {
|
try {
|
||||||
return new MulticastSocket(null);
|
return new MulticastSocket(null);
|
||||||
@ -352,22 +350,4 @@ public class OioDatagramChannel extends AbstractOioMessageChannel
|
|||||||
future.setFailure(new UnsupportedOperationException());
|
future.setFailure(new UnsupportedOperationException());
|
||||||
return future;
|
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();
|
final Lock shutdownLock = new ReentrantLock();
|
||||||
private final ServerSocketChannelConfig config;
|
private final ServerSocketChannelConfig config;
|
||||||
|
|
||||||
private volatile boolean readSuspended;
|
|
||||||
|
|
||||||
public OioServerSocketChannel() {
|
public OioServerSocketChannel() {
|
||||||
this(newServerSocket());
|
this(newServerSocket());
|
||||||
}
|
}
|
||||||
@ -192,22 +190,4 @@ public class OioServerSocketChannel extends AbstractOioMessageChannel
|
|||||||
protected void doWriteMessages(MessageBuf<Object> buf) throws Exception {
|
protected void doWriteMessages(MessageBuf<Object> buf) throws Exception {
|
||||||
throw new UnsupportedOperationException();
|
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 final SocketChannelConfig config;
|
||||||
private InputStream is;
|
private InputStream is;
|
||||||
private OutputStream os;
|
private OutputStream os;
|
||||||
private volatile boolean readSuspended;
|
|
||||||
|
|
||||||
public OioSocketChannel() {
|
public OioSocketChannel() {
|
||||||
this(new Socket());
|
this(new Socket());
|
||||||
@ -186,23 +185,4 @@ public class OioSocketChannel extends AbstractOioByteChannel
|
|||||||
}
|
}
|
||||||
buf.readBytes(os, buf.readableBytes());
|
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