Skip to content

Commit 264f10e

Browse files
committed
Wrap into a CheckedRunnable directly
1 parent 69ce93e commit 264f10e

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

server/src/main/java/org/elasticsearch/action/ActionListener.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.function.Consumer;
2929
import java.util.function.Function;
3030

31+
import static org.elasticsearch.action.ActionListenerImplementations.checkedRunnableFromReleasable;
3132
import static org.elasticsearch.action.ActionListenerImplementations.runnableFromReleasable;
3233
import static org.elasticsearch.action.ActionListenerImplementations.safeAcceptException;
3334
import static org.elasticsearch.action.ActionListenerImplementations.safeOnFailure;
@@ -340,18 +341,9 @@ static <Response> ActionListener<Response> runBefore(ActionListener<Response> de
340341
* resource before the listener is notified via either {@code #onResponse} or {@code #onFailure}.
341342
*/
342343
static <Response> ActionListener<Response> releaseBefore(ActionListener<Response> delegate, Releasable releaseBefore) {
343-
Runnable releasableRunnable = runnableFromReleasable(releaseBefore);
344-
return assertOnce(new ActionListenerImplementations.RunBeforeActionListener<>(delegate, new CheckedRunnable<>() {
345-
@Override
346-
public void run() {
347-
releasableRunnable.run();
348-
}
349-
350-
@Override
351-
public String toString() {
352-
return releasableRunnable.toString();
353-
}
354-
}));
344+
return assertOnce(
345+
new ActionListenerImplementations.RunBeforeActionListener<>(delegate, checkedRunnableFromReleasable(releaseBefore))
346+
);
355347
}
356348

357349
/**

server/src/main/java/org/elasticsearch/action/ActionListenerImplementations.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ public String toString() {
5858
};
5959
}
6060

61+
static CheckedRunnable<Exception> checkedRunnableFromReleasable(Releasable releasable) {
62+
return new CheckedRunnable<>() {
63+
@Override
64+
public void run() {
65+
Releasables.closeExpectNoException(releasable);
66+
}
67+
68+
@Override
69+
public String toString() {
70+
return "release[" + releasable + "]";
71+
}
72+
};
73+
}
74+
6175
static void safeAcceptException(Consumer<Exception> consumer, Exception e) {
6276
assert e != null;
6377
try {

0 commit comments

Comments
 (0)