Skip to content

Introduce ActionListener#empty() #39655

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

Closed
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions server/src/main/java/org/elasticsearch/action/ActionListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,18 @@ static <Response> void completeWith(ActionListener<Response> listener, CheckedSu
listener.onFailure(e);
}
}

class Empty<Response> implements ActionListener<Response> {
@Override
public void onResponse(Response response) {
}

@Override
public void onFailure(Exception e) {
}
}

static <Response> ActionListener<Response> empty() {
return new Empty<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent imple
private final ShardStateAction shardStateAction;
private final NodeMappingRefreshAction nodeMappingRefreshAction;

private static final ActionListener<Void> SHARD_STATE_ACTION_LISTENER = ActionListener.wrap(() -> {});
private static final ActionListener<Void> SHARD_STATE_ACTION_LISTENER = ActionListener.empty();

private final Settings settings;
// a list of shards that failed during recovery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ void registerNodeConnection(List<TcpChannel> nodeChannels, ConnectionProfile con

for (TcpChannel channel : nodeChannels) {
scheduledPing.addChannel(channel);

channel.addCloseListener(ActionListener.wrap(() -> {
scheduledPing.removeChannel(channel);
}));
channel.addCloseListener(ActionListener.wrap(() -> scheduledPing.removeChannel(channel)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testAddOrRenewRetentionLease() {
}
minimumRetainingSequenceNumbers[i] = randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, Long.MAX_VALUE);
replicationTracker.addRetentionLease(
Integer.toString(i), minimumRetainingSequenceNumbers[i], "test-" + i, ActionListener.wrap(() -> {}));
Integer.toString(i), minimumRetainingSequenceNumbers[i], "test-" + i, ActionListener.empty());
assertRetentionLeases(replicationTracker, i + 1, minimumRetainingSequenceNumbers, primaryTerm, 1 + i, true, false);
}

Expand Down Expand Up @@ -118,11 +118,11 @@ public void testAddDuplicateRetentionLease() {
final String id = randomAlphaOfLength(8);
final long retainingSequenceNumber = randomNonNegativeLong();
final String source = randomAlphaOfLength(8);
replicationTracker.addRetentionLease(id, retainingSequenceNumber, source, ActionListener.wrap(() -> {}));
replicationTracker.addRetentionLease(id, retainingSequenceNumber, source, ActionListener.empty());
final long nextRetaininSequenceNumber = randomLongBetween(retainingSequenceNumber, Long.MAX_VALUE);
final RetentionLeaseAlreadyExistsException e = expectThrows(
RetentionLeaseAlreadyExistsException.class,
() -> replicationTracker.addRetentionLease(id, nextRetaininSequenceNumber, source, ActionListener.wrap(() -> {})));
() -> replicationTracker.addRetentionLease(id, nextRetaininSequenceNumber, source, ActionListener.empty()));
assertThat(e, hasToString(containsString("retention lease with ID [" + id + "] already exists")));
}

Expand Down Expand Up @@ -187,7 +187,7 @@ public void testAddRetentionLeaseCausesRetentionLeaseSync() {
final String id = randomAlphaOfLength(8);
final long retainingSequenceNumber = randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, Long.MAX_VALUE);
retainingSequenceNumbers.put(id, retainingSequenceNumber);
replicationTracker.addRetentionLease(id, retainingSequenceNumber, "test", ActionListener.wrap(() -> {}));
replicationTracker.addRetentionLease(id, retainingSequenceNumber, "test", ActionListener.empty());
// assert that the new retention lease callback was invoked
assertTrue(invoked.get());

Expand Down Expand Up @@ -225,7 +225,7 @@ public void testRemoveRetentionLease() {
}
minimumRetainingSequenceNumbers[i] = randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, Long.MAX_VALUE);
replicationTracker.addRetentionLease(
Integer.toString(i), minimumRetainingSequenceNumbers[i], "test-" + i, ActionListener.wrap(() -> {}));
Integer.toString(i), minimumRetainingSequenceNumbers[i], "test-" + i, ActionListener.empty());
}

for (int i = 0; i < length; i++) {
Expand All @@ -237,7 +237,7 @@ public void testRemoveRetentionLease() {
* Remove from the end since it will make the following assertion easier; we want to ensure that only the intended lease was
* removed.
*/
replicationTracker.removeRetentionLease(Integer.toString(length - i - 1), ActionListener.wrap(() -> {}));
replicationTracker.removeRetentionLease(Integer.toString(length - i - 1), ActionListener.empty());
assertRetentionLeases(
replicationTracker,
length - i - 1,
Expand Down Expand Up @@ -270,7 +270,7 @@ public void testRemoveNotFound() {
final String id = randomAlphaOfLength(8);
final RetentionLeaseNotFoundException e = expectThrows(
RetentionLeaseNotFoundException.class,
() -> replicationTracker.removeRetentionLease(id, ActionListener.wrap(() -> {})));
() -> replicationTracker.removeRetentionLease(id, ActionListener.empty()));
assertThat(e, hasToString(containsString("retention lease with ID [" + id + "] not found")));
}

Expand Down Expand Up @@ -310,14 +310,14 @@ public void testRemoveRetentionLeaseCausesRetentionLeaseSync() {
final String id = randomAlphaOfLength(8);
final long retainingSequenceNumber = randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, Long.MAX_VALUE);
retainingSequenceNumbers.put(id, retainingSequenceNumber);
replicationTracker.addRetentionLease(id, retainingSequenceNumber, "test", ActionListener.wrap(() -> {}));
replicationTracker.addRetentionLease(id, retainingSequenceNumber, "test", ActionListener.empty());
// assert that the new retention lease callback was invoked
assertTrue(invoked.get());

// reset the invocation marker so that we can assert the callback was not invoked when removing the lease
invoked.set(false);
retainingSequenceNumbers.remove(id);
replicationTracker.removeRetentionLease(id, ActionListener.wrap(() -> {}));
replicationTracker.removeRetentionLease(id, ActionListener.empty());
assertTrue(invoked.get());
}
}
Expand Down Expand Up @@ -361,7 +361,7 @@ private void runExpirationTest(final boolean primaryMode) {
final long[] retainingSequenceNumbers = new long[1];
retainingSequenceNumbers[0] = randomLongBetween(0, Long.MAX_VALUE);
if (primaryMode) {
replicationTracker.addRetentionLease("0", retainingSequenceNumbers[0], "test-0", ActionListener.wrap(() -> {}));
replicationTracker.addRetentionLease("0", retainingSequenceNumbers[0], "test-0", ActionListener.empty());
} else {
final RetentionLeases retentionLeases = new RetentionLeases(
primaryTerm,
Expand Down Expand Up @@ -491,7 +491,7 @@ public void testLoadAndPersistRetentionLeases() throws IOException {
}
final long retainingSequenceNumber = randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, Long.MAX_VALUE);
replicationTracker.addRetentionLease(
Integer.toString(i), retainingSequenceNumber, "test-" + i, ActionListener.wrap(() -> {}));
Integer.toString(i), retainingSequenceNumber, "test-" + i, ActionListener.empty());
}

final Path path = createTempDir();
Expand Down Expand Up @@ -531,7 +531,7 @@ public void testPersistRetentionLeasesUnderConcurrency() throws IOException {
}
final long retainingSequenceNumber = randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, Long.MAX_VALUE);
replicationTracker.addRetentionLease(
Integer.toString(i), retainingSequenceNumber, "test-" + i, ActionListener.wrap(() -> {}));
Integer.toString(i), retainingSequenceNumber, "test-" + i, ActionListener.empty());
}

final Path path = createTempDir();
Expand All @@ -544,7 +544,7 @@ public void testPersistRetentionLeasesUnderConcurrency() throws IOException {
try {
barrier.await();
final long retainingSequenceNumber = randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, Long.MAX_VALUE);
replicationTracker.addRetentionLease(id, retainingSequenceNumber, "test-" + id, ActionListener.wrap(() -> {}));
replicationTracker.addRetentionLease(id, retainingSequenceNumber, "test-" + id, ActionListener.empty());
replicationTracker.persistRetentionLeases(path);
barrier.await();
} catch (final BrokenBarrierException | InterruptedException | WriteStateException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected Logger getLogger() {
};

// execution happens on the test thread, so no need to register an actual listener to callback
action.sync(indexShard.shardId(), retentionLeases, ActionListener.wrap(() -> {}));
action.sync(indexShard.shardId(), retentionLeases, ActionListener.empty());
assertTrue(invoked.get());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void testAddOrRenewRetentionLease() throws IOException {
for (int i = 0; i < length; i++) {
minimumRetainingSequenceNumbers[i] = randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, Long.MAX_VALUE);
indexShard.addRetentionLease(
Integer.toString(i), minimumRetainingSequenceNumbers[i], "test-" + i, ActionListener.wrap(() -> {}));
Integer.toString(i), minimumRetainingSequenceNumbers[i], "test-" + i, ActionListener.empty());
assertRetentionLeases(
indexShard, i + 1, minimumRetainingSequenceNumbers, primaryTerm, 1 + i, true, false);
}
Expand Down Expand Up @@ -110,13 +110,13 @@ public void testRemoveRetentionLease() throws IOException {
for (int i = 0; i < length; i++) {
minimumRetainingSequenceNumbers[i] = randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, Long.MAX_VALUE);
indexShard.addRetentionLease(
Integer.toString(i), minimumRetainingSequenceNumbers[i], "test-" + i, ActionListener.wrap(() -> {}));
Integer.toString(i), minimumRetainingSequenceNumbers[i], "test-" + i, ActionListener.empty());
assertRetentionLeases(
indexShard, i + 1, minimumRetainingSequenceNumbers, primaryTerm, 1 + i, true, false);
}

for (int i = 0; i < length; i++) {
indexShard.removeRetentionLease(Integer.toString(length - i - 1), ActionListener.wrap(() -> {}));
indexShard.removeRetentionLease(Integer.toString(length - i - 1), ActionListener.empty());
assertRetentionLeases(
indexShard,
length - i - 1,
Expand Down Expand Up @@ -154,7 +154,7 @@ private void runExpirationTest(final boolean primary) throws IOException {
final long[] retainingSequenceNumbers = new long[1];
retainingSequenceNumbers[0] = randomLongBetween(0, Long.MAX_VALUE);
if (primary) {
indexShard.addRetentionLease("0", retainingSequenceNumbers[0], "test-0", ActionListener.wrap(() -> {}));
indexShard.addRetentionLease("0", retainingSequenceNumbers[0], "test-0", ActionListener.empty());
} else {
final RetentionLeases retentionLeases = new RetentionLeases(
primaryTerm,
Expand Down Expand Up @@ -224,7 +224,7 @@ public void testPersistence() throws IOException {
minimumRetainingSequenceNumbers[i] = randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, Long.MAX_VALUE);
currentTimeMillis.set(TimeUnit.NANOSECONDS.toMillis(randomNonNegativeLong()));
indexShard.addRetentionLease(
Integer.toString(i), minimumRetainingSequenceNumbers[i], "test-" + i, ActionListener.wrap(() -> {}));
Integer.toString(i), minimumRetainingSequenceNumbers[i], "test-" + i, ActionListener.empty());
}

currentTimeMillis.set(TimeUnit.NANOSECONDS.toMillis(Long.MAX_VALUE));
Expand Down Expand Up @@ -275,7 +275,7 @@ public void testRetentionLeaseStats() throws IOException {
for (int i = 0; i < length; i++) {
minimumRetainingSequenceNumbers[i] = randomLongBetween(SequenceNumbers.NO_OPS_PERFORMED, Long.MAX_VALUE);
indexShard.addRetentionLease(
Integer.toString(i), minimumRetainingSequenceNumbers[i], "test-" + i, ActionListener.wrap(() -> {}));
Integer.toString(i), minimumRetainingSequenceNumbers[i], "test-" + i, ActionListener.empty());
}
final RetentionLeaseStats stats = indexShard.getRetentionLeaseStats();
assertRetentionLeases(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public void testRemoteClusterLicenseCallUsesSystemContext() throws InterruptedEx

final List<String> remoteClusterAliases = Collections.singletonList("valid");
licenseChecker.checkRemoteClusterLicenses(
remoteClusterAliases, doubleInvocationProtectingListener(ActionListener.wrap(() -> {})));
remoteClusterAliases, doubleInvocationProtectingListener(ActionListener.empty()));

verify(client, times(1)).execute(same(XPackInfoAction.INSTANCE), any(), any());
} finally {
Expand Down