Remove unneeded Throwable handling in nio (#27412)
This is related to #27260. In the nio transport work we do not catch or handle `Throwable`. There are a few places where we have exception handlers that accept `Throwable`. This commit removes those cases.
This commit is contained in:
parent
492edb91b9
commit
f761a0e0e4
|
@ -184,9 +184,7 @@ public class NioTransport extends TcpTransport {
|
||||||
return new SocketEventHandler(logger, this::exceptionCaught, openChannels);
|
return new SocketEventHandler(logger, this::exceptionCaught, openChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
final void exceptionCaught(NioSocketChannel channel, Throwable cause) {
|
final void exceptionCaught(NioSocketChannel channel, Exception exception) {
|
||||||
final Throwable unwrapped = ExceptionsHelper.unwrap(cause, ElasticsearchException.class);
|
onException(channel, exception);
|
||||||
final Throwable t = unwrapped != null ? unwrapped : cause;
|
|
||||||
onException(channel, t instanceof Exception ? (Exception) t : new ElasticsearchException(t));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,10 @@ import java.util.function.BiConsumer;
|
||||||
*/
|
*/
|
||||||
public class SocketEventHandler extends EventHandler {
|
public class SocketEventHandler extends EventHandler {
|
||||||
|
|
||||||
private final BiConsumer<NioSocketChannel, Throwable> exceptionHandler;
|
private final BiConsumer<NioSocketChannel, Exception> exceptionHandler;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
public SocketEventHandler(Logger logger, BiConsumer<NioSocketChannel, Throwable> exceptionHandler, OpenChannels openChannels) {
|
public SocketEventHandler(Logger logger, BiConsumer<NioSocketChannel, Exception> exceptionHandler, OpenChannels openChannels) {
|
||||||
super(logger, openChannels);
|
super(logger, openChannels);
|
||||||
this.exceptionHandler = exceptionHandler;
|
this.exceptionHandler = exceptionHandler;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
|
@ -32,10 +32,9 @@ public class TcpReadHandler {
|
||||||
this.transport = transport;
|
this.transport = transport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleMessage(BytesReference reference, NioSocketChannel channel, String profileName,
|
public void handleMessage(BytesReference reference, NioSocketChannel channel, int messageBytesLength) {
|
||||||
int messageBytesLength) {
|
|
||||||
try {
|
try {
|
||||||
transport.messageReceived(reference, channel, profileName, channel.getRemoteAddress(), messageBytesLength);
|
transport.messageReceived(reference, channel, channel.getProfile(), channel.getRemoteAddress(), messageBytesLength);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
handleException(channel, e);
|
handleException(channel, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class TcpReadContext implements ReadContext {
|
||||||
|
|
||||||
// A message length of 6 bytes it is just a ping. Ignore for now.
|
// A message length of 6 bytes it is just a ping. Ignore for now.
|
||||||
if (messageLengthWithHeader != 6) {
|
if (messageLengthWithHeader != 6) {
|
||||||
handler.handleMessage(messageWithoutHeader, channel, channel.getProfile(), messageWithoutHeader.length());
|
handler.handleMessage(messageWithoutHeader, channel, messageWithoutHeader.length());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handler.handleException(channel, e);
|
handler.handleException(channel, e);
|
||||||
|
|
|
@ -43,7 +43,7 @@ import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class SocketEventHandlerTests extends ESTestCase {
|
public class SocketEventHandlerTests extends ESTestCase {
|
||||||
|
|
||||||
private BiConsumer<NioSocketChannel, Throwable> exceptionHandler;
|
private BiConsumer<NioSocketChannel, Exception> exceptionHandler;
|
||||||
|
|
||||||
private SocketEventHandler handler;
|
private SocketEventHandler handler;
|
||||||
private NioSocketChannel channel;
|
private NioSocketChannel channel;
|
||||||
|
|
|
@ -30,11 +30,8 @@ import java.util.function.BiConsumer;
|
||||||
|
|
||||||
public class TestingSocketEventHandler extends SocketEventHandler {
|
public class TestingSocketEventHandler extends SocketEventHandler {
|
||||||
|
|
||||||
private final Logger logger;
|
public TestingSocketEventHandler(Logger logger, BiConsumer<NioSocketChannel, Exception> exceptionHandler, OpenChannels openChannels) {
|
||||||
|
|
||||||
public TestingSocketEventHandler(Logger logger, BiConsumer<NioSocketChannel, Throwable> exceptionHandler, OpenChannels openChannels) {
|
|
||||||
super(logger, exceptionHandler, openChannels);
|
super(logger, exceptionHandler, openChannels);
|
||||||
this.logger = logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<NioSocketChannel> hasConnectedMap = Collections.newSetFromMap(new WeakHashMap<>());
|
private Set<NioSocketChannel> hasConnectedMap = Collections.newSetFromMap(new WeakHashMap<>());
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class TcpReadContextTests extends ESTestCase {
|
||||||
|
|
||||||
readContext.read();
|
readContext.read();
|
||||||
|
|
||||||
verify(handler).handleMessage(new BytesArray(bytes), channel, PROFILE, messageLength);
|
verify(handler).handleMessage(new BytesArray(bytes), channel, messageLength);
|
||||||
assertEquals(1024 * 16, bufferCapacity.get());
|
assertEquals(1024 * 16, bufferCapacity.get());
|
||||||
|
|
||||||
BytesArray bytesArray = new BytesArray(new byte[10]);
|
BytesArray bytesArray = new BytesArray(new byte[10]);
|
||||||
|
@ -110,7 +110,7 @@ public class TcpReadContextTests extends ESTestCase {
|
||||||
assertEquals(1024 * 16 - fullPart1.length, bufferCapacity.get());
|
assertEquals(1024 * 16 - fullPart1.length, bufferCapacity.get());
|
||||||
|
|
||||||
CompositeBytesReference reference = new CompositeBytesReference(new BytesArray(part1), new BytesArray(part2));
|
CompositeBytesReference reference = new CompositeBytesReference(new BytesArray(part1), new BytesArray(part2));
|
||||||
verify(handler).handleMessage(reference, channel, PROFILE, messageLength + messageLength);
|
verify(handler).handleMessage(reference, channel, messageLength + messageLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testReadThrowsIOException() throws IOException {
|
public void testReadThrowsIOException() throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue