Skip to content

Commit abf8c56

Browse files
authored
Remove logging from elasticsearch-nio jar (#30761)
This is related to #27260. The elasticsearch-nio jar is supposed to be a library opposed to a framework. Currently it internally logs certain exceptions. This commit modifies it to not rely on logging. Instead exception handlers are passed by the applications that use the jar.
1 parent c6be3b4 commit abf8c56

File tree

23 files changed

+139
-333
lines changed

23 files changed

+139
-333
lines changed

libs/elasticsearch-nio/build.gradle

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ publishing {
3333
}
3434

3535
dependencies {
36-
compile "org.apache.logging.log4j:log4j-api:${versions.log4j}"
37-
3836
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
3937
testCompile "junit:junit:${versions.junit}"
4038
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
@@ -64,18 +62,3 @@ forbiddenApisMain {
6462
// es-all is not checked as we connect and accept sockets
6563
signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
6664
}
67-
68-
//JarHell is part of es core, which we don't want to pull in
69-
jarHell.enabled=false
70-
71-
thirdPartyAudit.excludes = [
72-
'org/osgi/framework/AdaptPermission',
73-
'org/osgi/framework/AdminPermission',
74-
'org/osgi/framework/Bundle',
75-
'org/osgi/framework/BundleActivator',
76-
'org/osgi/framework/BundleContext',
77-
'org/osgi/framework/BundleEvent',
78-
'org/osgi/framework/SynchronousBundleListener',
79-
'org/osgi/framework/wiring/BundleWire',
80-
'org/osgi/framework/wiring/BundleWiring'
81-
]

libs/elasticsearch-nio/licenses/log4j-api-2.9.1.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.

libs/elasticsearch-nio/licenses/log4j-api-LICENSE.txt

Lines changed: 0 additions & 202 deletions
This file was deleted.

libs/elasticsearch-nio/licenses/log4j-api-NOTICE.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

libs/elasticsearch-nio/src/main/java/org/elasticsearch/nio/AcceptorEventHandler.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919

2020
package org.elasticsearch.nio;
2121

22-
import org.apache.logging.log4j.Logger;
23-
import org.apache.logging.log4j.message.ParameterizedMessage;
24-
2522
import java.io.IOException;
2623
import java.nio.channels.SelectionKey;
24+
import java.util.function.Consumer;
2725
import java.util.function.Supplier;
2826

2927
/**
@@ -33,8 +31,8 @@ public class AcceptorEventHandler extends EventHandler {
3331

3432
private final Supplier<SocketSelector> selectorSupplier;
3533

36-
public AcceptorEventHandler(Logger logger, Supplier<SocketSelector> selectorSupplier) {
37-
super(logger);
34+
public AcceptorEventHandler(Supplier<SocketSelector> selectorSupplier, Consumer<Exception> exceptionHandler) {
35+
super(exceptionHandler);
3836
this.selectorSupplier = selectorSupplier;
3937
}
4038

@@ -58,7 +56,7 @@ protected void handleRegistration(ServerChannelContext context) throws IOExcepti
5856
* @param exception that occurred
5957
*/
6058
protected void registrationException(ServerChannelContext context, Exception exception) {
61-
logger.error(new ParameterizedMessage("failed to register server channel: {}", context.getChannel()), exception);
59+
context.handleException(exception);
6260
}
6361

6462
/**
@@ -78,7 +76,6 @@ protected void acceptChannel(ServerChannelContext context) throws IOException {
7876
* @param exception that occurred
7977
*/
8078
protected void acceptException(ServerChannelContext context, Exception exception) {
81-
logger.debug(() -> new ParameterizedMessage("exception while accepting new channel from server channel: {}",
82-
context.getChannel()), exception);
79+
context.handleException(exception);
8380
}
8481
}

libs/elasticsearch-nio/src/main/java/org/elasticsearch/nio/ESSelector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void runLoop() {
8383
try {
8484
selector.close();
8585
} catch (IOException e) {
86-
eventHandler.closeSelectorException(e);
86+
eventHandler.selectorException(e);
8787
} finally {
8888
runLock.unlock();
8989
exitedLoop.countDown();
@@ -123,7 +123,7 @@ void singleLoop() {
123123
throw e;
124124
}
125125
} catch (IOException e) {
126-
eventHandler.selectException(e);
126+
eventHandler.selectorException(e);
127127
} catch (Exception e) {
128128
eventHandler.uncaughtException(e);
129129
}

libs/elasticsearch-nio/src/main/java/org/elasticsearch/nio/EventHandler.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,26 @@
1919

2020
package org.elasticsearch.nio;
2121

22-
import org.apache.logging.log4j.Logger;
23-
import org.apache.logging.log4j.message.ParameterizedMessage;
24-
2522
import java.io.IOException;
2623
import java.nio.channels.Selector;
24+
import java.util.function.Consumer;
2725

2826
public abstract class EventHandler {
2927

30-
protected final Logger logger;
31-
32-
EventHandler(Logger logger) {
33-
this.logger = logger;
34-
}
28+
protected final Consumer<Exception> exceptionHandler;
3529

36-
/**
37-
* This method handles an IOException that was thrown during a call to {@link Selector#select(long)}.
38-
*
39-
* @param exception the exception
40-
*/
41-
protected void selectException(IOException exception) {
42-
logger.warn(new ParameterizedMessage("io exception during select [thread={}]", Thread.currentThread().getName()), exception);
30+
protected EventHandler(Consumer<Exception> exceptionHandler) {
31+
this.exceptionHandler = exceptionHandler;
4332
}
4433

4534
/**
46-
* This method handles an IOException that was thrown during a call to {@link Selector#close()}.
35+
* This method handles an IOException that was thrown during a call to {@link Selector#select(long)} or
36+
* {@link Selector#close()}.
4737
*
4838
* @param exception the exception
4939
*/
50-
protected void closeSelectorException(IOException exception) {
51-
logger.warn(new ParameterizedMessage("io exception while closing selector [thread={}]", Thread.currentThread().getName()),
52-
exception);
40+
protected void selectorException(IOException exception) {
41+
exceptionHandler.accept(exception);
5342
}
5443

5544
/**
@@ -79,11 +68,11 @@ protected void handleClose(ChannelContext<?> context) {
7968
/**
8069
* This method is called when an attempt to close a channel throws an exception.
8170
*
82-
* @param context that was being closed
71+
* @param channel that was being closed
8372
* @param exception that occurred
8473
*/
85-
protected void closeException(ChannelContext<?> context, Exception exception) {
86-
logger.debug(() -> new ParameterizedMessage("exception while closing channel: {}", context.getChannel()), exception);
74+
protected void closeException(ChannelContext<?> channel, Exception exception) {
75+
channel.handleException(exception);
8776
}
8877

8978
/**
@@ -95,6 +84,6 @@ protected void closeException(ChannelContext<?> context, Exception exception) {
9584
* @param exception that was thrown
9685
*/
9786
protected void genericChannelException(ChannelContext<?> channel, Exception exception) {
98-
logger.debug(() -> new ParameterizedMessage("exception while handling event for channel: {}", channel.getChannel()), exception);
87+
channel.handleException(exception);
9988
}
10089
}

0 commit comments

Comments
 (0)