Skip to content

Commit

Permalink
Remove unneeded Throwable handling in nio (#27412)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tim-Brooks committed Nov 17, 2017
1 parent 4cc35c2 commit 60ff1ba
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ protected SocketEventHandler getSocketEventHandler() {
return new SocketEventHandler(logger, this::exceptionCaught, openChannels);
}

final void exceptionCaught(NioSocketChannel channel, Throwable cause) {
final Throwable unwrapped = ExceptionsHelper.unwrap(cause, ElasticsearchException.class);
final Throwable t = unwrapped != null ? unwrapped : cause;
onException(channel, t instanceof Exception ? (Exception) t : new ElasticsearchException(t));
final void exceptionCaught(NioSocketChannel channel, Exception exception) {
onException(channel, exception);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
*/
public class SocketEventHandler extends EventHandler {

private final BiConsumer<NioSocketChannel, Throwable> exceptionHandler;
private final BiConsumer<NioSocketChannel, Exception> exceptionHandler;
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);
this.exceptionHandler = exceptionHandler;
this.logger = logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ public TcpReadHandler(NioTransport transport) {
this.transport = transport;
}

public void handleMessage(BytesReference reference, NioSocketChannel channel, String profileName,
int messageBytesLength) {
public void handleMessage(BytesReference reference, NioSocketChannel channel, int messageBytesLength) {
try {
transport.messageReceived(reference, channel, profileName, channel.getRemoteAddress(), messageBytesLength);
transport.messageReceived(reference, channel, channel.getProfile(), channel.getRemoteAddress(), messageBytesLength);
} catch (IOException e) {
handleException(channel, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public int read() throws IOException {

// A message length of 6 bytes it is just a ping. Ignore for now.
if (messageLengthWithHeader != 6) {
handler.handleMessage(messageWithoutHeader, channel, channel.getProfile(), messageWithoutHeader.length());
handler.handleMessage(messageWithoutHeader, channel, messageWithoutHeader.length());
}
} catch (Exception e) {
handler.handleException(channel, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

public class SocketEventHandlerTests extends ESTestCase {

private BiConsumer<NioSocketChannel, Throwable> exceptionHandler;
private BiConsumer<NioSocketChannel, Exception> exceptionHandler;

private SocketEventHandler handler;
private NioSocketChannel channel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@

public class TestingSocketEventHandler extends SocketEventHandler {

private final Logger logger;

public TestingSocketEventHandler(Logger logger, BiConsumer<NioSocketChannel, Throwable> exceptionHandler, OpenChannels openChannels) {
public TestingSocketEventHandler(Logger logger, BiConsumer<NioSocketChannel, Exception> exceptionHandler, OpenChannels openChannels) {
super(logger, exceptionHandler, openChannels);
this.logger = logger;
}

private Set<NioSocketChannel> hasConnectedMap = Collections.newSetFromMap(new WeakHashMap<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void testSuccessfulRead() throws IOException {

readContext.read();

verify(handler).handleMessage(new BytesArray(bytes), channel, PROFILE, messageLength);
verify(handler).handleMessage(new BytesArray(bytes), channel, messageLength);
assertEquals(1024 * 16, bufferCapacity.get());

BytesArray bytesArray = new BytesArray(new byte[10]);
Expand Down Expand Up @@ -110,7 +110,7 @@ public void testPartialRead() throws IOException {
assertEquals(1024 * 16 - fullPart1.length, bufferCapacity.get());

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 {
Expand Down

0 comments on commit 60ff1ba

Please sign in to comment.