Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneeded Throwable handling in nio #27412

Merged
merged 2 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,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