Skip to content

Commit

Permalink
catch exception
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Jul 18, 2024
1 parent c332be3 commit 2a91446
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import com.aerospike.client.cluster.Node;
import com.aerospike.client.listener.InfoListener;
import com.aerospike.client.policy.InfoPolicy;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;

@Slf4j
@UtilityClass
public class InfoCommandUtils {

public static String sendInfoCommand(IAerospikeClient client, Node node, String command) {
Expand All @@ -38,17 +40,25 @@ public void onFailure(AerospikeException ae) {
}
};

client.info(client.getCluster().eventLoops.next(), listener, infoPolicy, node, command);
try {
client.info(client.getCluster().eventLoops.next(), listener, infoPolicy, node, command);
} catch (AerospikeException ae) {
fail(command, ae);
}

String value;
String value = null;
try {
value = listener.getValueFuture().join();
} catch (CompletionException ce) {
throw new AerospikeException(String.format("Info command %s failed", command), ce.getCause());
fail(command, ce.getCause());
}
return value == null ? "" : value;
}

private static void fail(String command, Throwable t) {
throw new AerospikeException(String.format("Info command %s failed", command), t);
}

interface InfoListenerWithStringValue extends InfoListener {

CompletableFuture<String> getValueFuture();
Expand Down

0 comments on commit 2a91446

Please sign in to comment.