Avoid overspecifying ScheduledFuture when Future will do (#11636)
Motivation: Overspecifying interfaces can increase coupling and make refactoring harder down the line. Modification: Places that were specifying fields, variables, and return types as ScheduledFuture, but did not use any features specific to ScheduledFuture, have been changed to specify Future instead. Result: Cleaner code.
This commit is contained in:
parent
d027ba7320
commit
b3d3269b8c
|
@ -23,8 +23,8 @@ import io.netty.channel.ChannelOutboundHandler;
|
||||||
import io.netty.channel.ChannelPromise;
|
import io.netty.channel.ChannelPromise;
|
||||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
|
import io.netty.util.concurrent.Future;
|
||||||
import io.netty.util.concurrent.PromiseNotifier;
|
import io.netty.util.concurrent.PromiseNotifier;
|
||||||
import io.netty.util.concurrent.ScheduledFuture;
|
|
||||||
|
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
|
@ -128,7 +128,7 @@ abstract class WebSocketProtocolHandler extends MessageToMessageDecoder<WebSocke
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ScheduledFuture<?> timeoutTask = ctx.executor().schedule(new Runnable() {
|
final Future<?> timeoutTask = ctx.executor().schedule(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!closeSent.isDone()) {
|
if (!closeSent.isDone()) {
|
||||||
|
|
|
@ -27,7 +27,7 @@ import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
import io.netty.handler.codec.http2.Http2Exception.CompositeStreamException;
|
import io.netty.handler.codec.http2.Http2Exception.CompositeStreamException;
|
||||||
import io.netty.handler.codec.http2.Http2Exception.StreamException;
|
import io.netty.handler.codec.http2.Http2Exception.StreamException;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import io.netty.util.concurrent.ScheduledFuture;
|
import io.netty.util.concurrent.Future;
|
||||||
import io.netty.util.internal.UnstableApi;
|
import io.netty.util.internal.UnstableApi;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
|
@ -943,7 +943,7 @@ public class Http2ConnectionHandler extends ByteToMessageDecoder implements Http
|
||||||
private static final class ClosingChannelFutureListener implements ChannelFutureListener {
|
private static final class ClosingChannelFutureListener implements ChannelFutureListener {
|
||||||
private final ChannelHandlerContext ctx;
|
private final ChannelHandlerContext ctx;
|
||||||
private final ChannelPromise promise;
|
private final ChannelPromise promise;
|
||||||
private final ScheduledFuture<?> timeoutTask;
|
private final Future<?> timeoutTask;
|
||||||
private boolean closed;
|
private boolean closed;
|
||||||
|
|
||||||
ClosingChannelFutureListener(ChannelHandlerContext ctx, ChannelPromise promise) {
|
ClosingChannelFutureListener(ChannelHandlerContext ctx, ChannelPromise promise) {
|
||||||
|
|
|
@ -27,7 +27,6 @@ import io.netty.util.ReferenceCountUtil;
|
||||||
import io.netty.util.concurrent.DefaultPromise;
|
import io.netty.util.concurrent.DefaultPromise;
|
||||||
import io.netty.util.concurrent.EventExecutor;
|
import io.netty.util.concurrent.EventExecutor;
|
||||||
import io.netty.util.concurrent.Future;
|
import io.netty.util.concurrent.Future;
|
||||||
import io.netty.util.concurrent.ScheduledFuture;
|
|
||||||
import io.netty.util.internal.ObjectUtil;
|
import io.netty.util.internal.ObjectUtil;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
|
@ -60,7 +59,7 @@ public abstract class ProxyHandler extends ChannelDuplexHandler {
|
||||||
private boolean suppressChannelReadComplete;
|
private boolean suppressChannelReadComplete;
|
||||||
private boolean flushedPrematurely;
|
private boolean flushedPrematurely;
|
||||||
private final LazyChannelPromise connectPromise = new LazyChannelPromise();
|
private final LazyChannelPromise connectPromise = new LazyChannelPromise();
|
||||||
private ScheduledFuture<?> connectTimeoutFuture;
|
private Future<?> connectTimeoutFuture;
|
||||||
private final ChannelFutureListener writeListener = new ChannelFutureListener() {
|
private final ChannelFutureListener writeListener = new ChannelFutureListener() {
|
||||||
@Override
|
@Override
|
||||||
public void operationComplete(ChannelFuture future) throws Exception {
|
public void operationComplete(ChannelFuture future) throws Exception {
|
||||||
|
|
|
@ -2102,7 +2102,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ScheduledFuture<?> timeoutFuture = ctx.executor().schedule(new Runnable() {
|
final Future<?> timeoutFuture = ctx.executor().schedule(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (localHandshakePromise.isDone()) {
|
if (localHandshakePromise.isDone()) {
|
||||||
|
@ -2153,7 +2153,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ScheduledFuture<?> timeoutFuture;
|
final Future<?> timeoutFuture;
|
||||||
if (!flushFuture.isDone()) {
|
if (!flushFuture.isDone()) {
|
||||||
long closeNotifyTimeout = closeNotifyFlushTimeoutMillis;
|
long closeNotifyTimeout = closeNotifyFlushTimeoutMillis;
|
||||||
if (closeNotifyTimeout > 0) {
|
if (closeNotifyTimeout > 0) {
|
||||||
|
@ -2189,7 +2189,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
||||||
// See https://github.com/netty/netty/issues/2358
|
// See https://github.com/netty/netty/issues/2358
|
||||||
addCloseListener(ctx.close(ctx.newPromise()), promise);
|
addCloseListener(ctx.close(ctx.newPromise()), promise);
|
||||||
} else {
|
} else {
|
||||||
final ScheduledFuture<?> closeNotifyReadTimeoutFuture;
|
final Future<?> closeNotifyReadTimeoutFuture;
|
||||||
|
|
||||||
if (!sslClosePromise.isDone()) {
|
if (!sslClosePromise.isDone()) {
|
||||||
closeNotifyReadTimeoutFuture = ctx.executor().schedule(new Runnable() {
|
closeNotifyReadTimeoutFuture = ctx.executor().schedule(new Runnable() {
|
||||||
|
|
|
@ -25,9 +25,9 @@ import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOutboundBuffer;
|
import io.netty.channel.ChannelOutboundBuffer;
|
||||||
import io.netty.channel.ChannelPromise;
|
import io.netty.channel.ChannelPromise;
|
||||||
|
import io.netty.util.concurrent.Future;
|
||||||
import io.netty.util.internal.ObjectUtil;
|
import io.netty.util.internal.ObjectUtil;
|
||||||
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,15 +113,15 @@ public class IdleStateHandler extends ChannelDuplexHandler {
|
||||||
private final long writerIdleTimeNanos;
|
private final long writerIdleTimeNanos;
|
||||||
private final long allIdleTimeNanos;
|
private final long allIdleTimeNanos;
|
||||||
|
|
||||||
private ScheduledFuture<?> readerIdleTimeout;
|
private Future<?> readerIdleTimeout;
|
||||||
private long lastReadTime;
|
private long lastReadTime;
|
||||||
private boolean firstReaderIdleEvent = true;
|
private boolean firstReaderIdleEvent = true;
|
||||||
|
|
||||||
private ScheduledFuture<?> writerIdleTimeout;
|
private Future<?> writerIdleTimeout;
|
||||||
private long lastWriteTime;
|
private long lastWriteTime;
|
||||||
private boolean firstWriterIdleEvent = true;
|
private boolean firstWriterIdleEvent = true;
|
||||||
|
|
||||||
private ScheduledFuture<?> allIdleTimeout;
|
private Future<?> allIdleTimeout;
|
||||||
private boolean firstAllIdleEvent = true;
|
private boolean firstAllIdleEvent = true;
|
||||||
|
|
||||||
private byte state; // 0 - none, 1 - initialized, 2 - destroyed
|
private byte state; // 0 - none, 1 - initialized, 2 - destroyed
|
||||||
|
@ -344,7 +344,7 @@ public class IdleStateHandler extends ChannelDuplexHandler {
|
||||||
/**
|
/**
|
||||||
* This method is visible for testing!
|
* This method is visible for testing!
|
||||||
*/
|
*/
|
||||||
ScheduledFuture<?> schedule(ChannelHandlerContext ctx, Runnable task, long delay, TimeUnit unit) {
|
Future<?> schedule(ChannelHandlerContext ctx, Runnable task, long delay, TimeUnit unit) {
|
||||||
return ctx.executor().schedule(task, delay, unit);
|
return ctx.executor().schedule(task, delay, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,9 @@ import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOutboundHandlerAdapter;
|
import io.netty.channel.ChannelOutboundHandlerAdapter;
|
||||||
import io.netty.channel.ChannelPromise;
|
import io.netty.channel.ChannelPromise;
|
||||||
|
import io.netty.util.concurrent.Future;
|
||||||
import io.netty.util.internal.ObjectUtil;
|
import io.netty.util.internal.ObjectUtil;
|
||||||
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -192,7 +192,7 @@ public class WriteTimeoutHandler extends ChannelOutboundHandlerAdapter {
|
||||||
WriteTimeoutTask prev;
|
WriteTimeoutTask prev;
|
||||||
WriteTimeoutTask next;
|
WriteTimeoutTask next;
|
||||||
|
|
||||||
ScheduledFuture<?> scheduledFuture;
|
Future<?> scheduledFuture;
|
||||||
|
|
||||||
WriteTimeoutTask(ChannelHandlerContext ctx, ChannelPromise promise) {
|
WriteTimeoutTask(ChannelHandlerContext ctx, ChannelPromise promise) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
|
|
|
@ -22,11 +22,11 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
import io.netty.channel.ChannelOutboundBuffer;
|
import io.netty.channel.ChannelOutboundBuffer;
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
|
import io.netty.util.concurrent.Future;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
@ -384,7 +384,7 @@ public class IdleStateHandlerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
ScheduledFuture<?> schedule(ChannelHandlerContext ctx, Runnable task, long delay, TimeUnit unit) {
|
Future<?> schedule(ChannelHandlerContext ctx, Runnable task, long delay, TimeUnit unit) {
|
||||||
this.task = task;
|
this.task = task;
|
||||||
this.delayInNanos = unit.toNanos(delay);
|
this.delayInNanos = unit.toNanos(delay);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -27,13 +27,14 @@ import io.netty.channel.epoll.EpollEventLoopGroup;
|
||||||
import io.netty.channel.epoll.EpollServerSocketChannel;
|
import io.netty.channel.epoll.EpollServerSocketChannel;
|
||||||
import io.netty.channel.epoll.EpollSocketChannel;
|
import io.netty.channel.epoll.EpollSocketChannel;
|
||||||
import io.netty.microbench.util.AbstractMicrobenchmark;
|
import io.netty.microbench.util.AbstractMicrobenchmark;
|
||||||
import io.netty.util.concurrent.ScheduledFuture;
|
import io.netty.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import org.openjdk.jmh.annotations.Benchmark;
|
import org.openjdk.jmh.annotations.Benchmark;
|
||||||
import org.openjdk.jmh.annotations.GroupThreads;
|
import org.openjdk.jmh.annotations.GroupThreads;
|
||||||
import org.openjdk.jmh.annotations.Setup;
|
import org.openjdk.jmh.annotations.Setup;
|
||||||
import org.openjdk.jmh.annotations.TearDown;
|
import org.openjdk.jmh.annotations.TearDown;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class EpollSocketChannelBenchmark extends AbstractMicrobenchmark {
|
public class EpollSocketChannelBenchmark extends AbstractMicrobenchmark {
|
||||||
private static final Runnable runnable = new Runnable() {
|
private static final Runnable runnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,7 +45,7 @@ public class EpollSocketChannelBenchmark extends AbstractMicrobenchmark {
|
||||||
private Channel serverChan;
|
private Channel serverChan;
|
||||||
private Channel chan;
|
private Channel chan;
|
||||||
private ByteBuf abyte;
|
private ByteBuf abyte;
|
||||||
private ScheduledFuture<?> future;
|
private Future<?> future;
|
||||||
|
|
||||||
@Setup
|
@Setup
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
|
|
|
@ -30,7 +30,6 @@ import io.netty.util.concurrent.Future;
|
||||||
import io.netty.util.concurrent.FutureListener;
|
import io.netty.util.concurrent.FutureListener;
|
||||||
import io.netty.util.concurrent.GenericFutureListener;
|
import io.netty.util.concurrent.GenericFutureListener;
|
||||||
import io.netty.util.concurrent.Promise;
|
import io.netty.util.concurrent.Promise;
|
||||||
import io.netty.util.concurrent.ScheduledFuture;
|
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
|
@ -52,7 +51,7 @@ abstract class DnsQueryContext implements FutureListener<AddressedEnvelope<DnsRe
|
||||||
private final InetSocketAddress nameServerAddr;
|
private final InetSocketAddress nameServerAddr;
|
||||||
|
|
||||||
private final boolean recursionDesired;
|
private final boolean recursionDesired;
|
||||||
private volatile ScheduledFuture<?> timeoutFuture;
|
private volatile Future<?> timeoutFuture;
|
||||||
|
|
||||||
DnsQueryContext(DnsNameResolver parent,
|
DnsQueryContext(DnsNameResolver parent,
|
||||||
InetSocketAddress nameServerAddr,
|
InetSocketAddress nameServerAddr,
|
||||||
|
@ -228,7 +227,7 @@ abstract class DnsQueryContext implements FutureListener<AddressedEnvelope<DnsRe
|
||||||
@Override
|
@Override
|
||||||
public void operationComplete(Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> future) {
|
public void operationComplete(Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> future) {
|
||||||
// Cancel the timeout task.
|
// Cancel the timeout task.
|
||||||
final ScheduledFuture<?> timeoutFuture = this.timeoutFuture;
|
Future<?> timeoutFuture = this.timeoutFuture;
|
||||||
if (timeoutFuture != null) {
|
if (timeoutFuture != null) {
|
||||||
this.timeoutFuture = null;
|
this.timeoutFuture = null;
|
||||||
timeoutFuture.cancel(false);
|
timeoutFuture.cancel(false);
|
||||||
|
|
|
@ -39,6 +39,7 @@ import io.netty.channel.unix.IovArray;
|
||||||
import io.netty.channel.unix.Socket;
|
import io.netty.channel.unix.Socket;
|
||||||
import io.netty.channel.unix.UnixChannel;
|
import io.netty.channel.unix.UnixChannel;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
|
import io.netty.util.concurrent.Future;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
@ -49,7 +50,6 @@ import java.nio.channels.ClosedChannelException;
|
||||||
import java.nio.channels.ConnectionPendingException;
|
import java.nio.channels.ConnectionPendingException;
|
||||||
import java.nio.channels.NotYetConnectedException;
|
import java.nio.channels.NotYetConnectedException;
|
||||||
import java.nio.channels.UnresolvedAddressException;
|
import java.nio.channels.UnresolvedAddressException;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static io.netty.channel.internal.ChannelUtils.WRITE_STATUS_SNDBUF_FULL;
|
import static io.netty.channel.internal.ChannelUtils.WRITE_STATUS_SNDBUF_FULL;
|
||||||
|
@ -64,7 +64,7 @@ abstract class AbstractEpollChannel extends AbstractChannel implements UnixChann
|
||||||
* connection attempts will fail.
|
* connection attempts will fail.
|
||||||
*/
|
*/
|
||||||
private ChannelPromise connectPromise;
|
private ChannelPromise connectPromise;
|
||||||
private ScheduledFuture<?> connectTimeoutFuture;
|
private Future<?> connectTimeoutFuture;
|
||||||
private SocketAddress requestedRemoteAddress;
|
private SocketAddress requestedRemoteAddress;
|
||||||
|
|
||||||
private volatile SocketAddress local;
|
private volatile SocketAddress local;
|
||||||
|
@ -160,7 +160,7 @@ abstract class AbstractEpollChannel extends AbstractChannel implements UnixChann
|
||||||
connectPromise = null;
|
connectPromise = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScheduledFuture<?> future = connectTimeoutFuture;
|
Future<?> future = connectTimeoutFuture;
|
||||||
if (future != null) {
|
if (future != null) {
|
||||||
future.cancel(false);
|
future.cancel(false);
|
||||||
connectTimeoutFuture = null;
|
connectTimeoutFuture = null;
|
||||||
|
|
|
@ -37,6 +37,7 @@ import io.netty.channel.socket.SocketChannelConfig;
|
||||||
import io.netty.channel.unix.FileDescriptor;
|
import io.netty.channel.unix.FileDescriptor;
|
||||||
import io.netty.channel.unix.UnixChannel;
|
import io.netty.channel.unix.UnixChannel;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
|
import io.netty.util.concurrent.Future;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
|
@ -47,7 +48,6 @@ import java.nio.channels.AlreadyConnectedException;
|
||||||
import java.nio.channels.ConnectionPendingException;
|
import java.nio.channels.ConnectionPendingException;
|
||||||
import java.nio.channels.NotYetConnectedException;
|
import java.nio.channels.NotYetConnectedException;
|
||||||
import java.nio.channels.UnresolvedAddressException;
|
import java.nio.channels.UnresolvedAddressException;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static io.netty.channel.internal.ChannelUtils.WRITE_STATUS_SNDBUF_FULL;
|
import static io.netty.channel.internal.ChannelUtils.WRITE_STATUS_SNDBUF_FULL;
|
||||||
|
@ -61,7 +61,7 @@ abstract class AbstractKQueueChannel extends AbstractChannel implements UnixChan
|
||||||
* connection attempts will fail.
|
* connection attempts will fail.
|
||||||
*/
|
*/
|
||||||
private ChannelPromise connectPromise;
|
private ChannelPromise connectPromise;
|
||||||
private ScheduledFuture<?> connectTimeoutFuture;
|
private Future<?> connectTimeoutFuture;
|
||||||
private SocketAddress requestedRemoteAddress;
|
private SocketAddress requestedRemoteAddress;
|
||||||
|
|
||||||
final BsdSocket socket;
|
final BsdSocket socket;
|
||||||
|
|
|
@ -29,6 +29,7 @@ import io.netty.channel.ConnectTimeoutException;
|
||||||
import io.netty.channel.EventLoop;
|
import io.netty.channel.EventLoop;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import io.netty.util.ReferenceCounted;
|
import io.netty.util.ReferenceCounted;
|
||||||
|
import io.netty.util.concurrent.Future;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
|
@ -39,7 +40,6 @@ import java.nio.channels.ClosedChannelException;
|
||||||
import java.nio.channels.ConnectionPendingException;
|
import java.nio.channels.ConnectionPendingException;
|
||||||
import java.nio.channels.SelectableChannel;
|
import java.nio.channels.SelectableChannel;
|
||||||
import java.nio.channels.SelectionKey;
|
import java.nio.channels.SelectionKey;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,7 +66,7 @@ public abstract class AbstractNioChannel extends AbstractChannel {
|
||||||
* connection attempts will fail.
|
* connection attempts will fail.
|
||||||
*/
|
*/
|
||||||
private ChannelPromise connectPromise;
|
private ChannelPromise connectPromise;
|
||||||
private ScheduledFuture<?> connectTimeoutFuture;
|
private Future<?> connectTimeoutFuture;
|
||||||
private SocketAddress requestedRemoteAddress;
|
private SocketAddress requestedRemoteAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -503,7 +503,7 @@ public abstract class AbstractNioChannel extends AbstractChannel {
|
||||||
connectPromise = null;
|
connectPromise = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScheduledFuture<?> future = connectTimeoutFuture;
|
Future<?> future = connectTimeoutFuture;
|
||||||
if (future != null) {
|
if (future != null) {
|
||||||
future.cancel(false);
|
future.cancel(false);
|
||||||
connectTimeoutFuture = null;
|
connectTimeoutFuture = null;
|
||||||
|
|
|
@ -15,25 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.channel.embedded;
|
package io.netty.channel.embedded;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.nio.channels.ClosedChannelException;
|
|
||||||
import java.util.ArrayDeque;
|
|
||||||
import java.util.Queue;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.Timeout;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
|
@ -51,7 +32,24 @@ import io.netty.channel.ChannelPromise;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import io.netty.util.concurrent.Future;
|
import io.netty.util.concurrent.Future;
|
||||||
import io.netty.util.concurrent.FutureListener;
|
import io.netty.util.concurrent.FutureListener;
|
||||||
import io.netty.util.concurrent.ScheduledFuture;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.Timeout;
|
||||||
|
|
||||||
|
import java.nio.channels.ClosedChannelException;
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class EmbeddedChannelTest {
|
public class EmbeddedChannelTest {
|
||||||
|
|
||||||
|
@ -134,7 +132,7 @@ public class EmbeddedChannelTest {
|
||||||
public void testScheduling() throws Exception {
|
public void testScheduling() throws Exception {
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter());
|
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter());
|
||||||
final CountDownLatch latch = new CountDownLatch(2);
|
final CountDownLatch latch = new CountDownLatch(2);
|
||||||
ScheduledFuture future = ch.eventLoop().schedule(new Runnable() {
|
Future future = ch.eventLoop().schedule(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
|
@ -158,7 +156,7 @@ public class EmbeddedChannelTest {
|
||||||
@Test
|
@Test
|
||||||
public void testScheduledCancelled() throws Exception {
|
public void testScheduledCancelled() throws Exception {
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter());
|
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter());
|
||||||
ScheduledFuture<?> future = ch.eventLoop().schedule(new Runnable() {
|
Future<?> future = ch.eventLoop().schedule(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() { }
|
public void run() { }
|
||||||
}, 1, TimeUnit.DAYS);
|
}, 1, TimeUnit.DAYS);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user