Module com.hedera.hashgraph.sdk
Package com.hedera.hashgraph.sdk
Class Executable<SdkRequestT,ProtoRequestT extends com.google.protobuf.MessageLite,ResponseT extends com.google.protobuf.MessageLite,O>
java.lang.Object
com.hedera.hashgraph.sdk.Executable<SdkRequestT,ProtoRequestT,ResponseT,O>
- Type Parameters:
SdkRequestT- the sdk requestProtoRequestT- the proto requestResponseT- the responseO- the O type
- Direct Known Subclasses:
Query,Transaction
abstract class Executable<SdkRequestT,ProtoRequestT extends com.google.protobuf.MessageLite,ResponseT extends com.google.protobuf.MessageLite,O>
extends Object
Abstract base utility class.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanIndicates if the request has been attempted to be sent to all nodes(package private) Function<Executable<SdkRequestT, ProtoRequestT, ResponseT, O>.GrpcRequest, ResponseT> protected DurationThe timeout for each execution attemptprotected Loggerprotected IntegerThe maximum times execution will be attemptedprotected DurationThe maximum amount of time to wait between retriesprotected DurationThe minimum amount of time to wait between retriesprotected LockableList<AccountId> List of account IDs for nodes with which execution will be attempted.protected LockableList<Node> List of healthy and unhealthy nodes with which execution will be attempted.protected static final Random(package private) static final Pattern -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void(package private) voidExecute this transaction or queryExecute this transaction or query with a timeoutexecuteAsync(Client client) Execute this transaction or query asynchronously.executeAsync(Client client, Duration timeout) Execute this transaction or query asynchronously.voidexecuteAsync(Client client, Duration timeout, BiConsumer<O, Throwable> callback) Execute this transaction or query asynchronously.voidExecute this transaction or query asynchronously.voidexecuteAsync(Client client, BiConsumer<O, Throwable> callback) Execute this transaction or query asynchronously.voidExecute this transaction or query asynchronously.(package private) ExecutionStategetExecutionState(Status status, ResponseT response) Default implementation, may be overridden in subclasses (especially for query case).(package private) Executable<SdkRequestT,ProtoRequestT, ResponseT, O>.GrpcRequest getGrpcRequest(int attempt) final intGet the maximum times execution will be attempted.final DurationThe maximum amount of time to wait between retriesfinal intDeprecated.(package private) abstract io.grpc.MethodDescriptor<ProtoRequestT, ResponseT> Called to direct the invocation of the query to the appropriate gRPC service.final DurationThe minimum amount of time to wait between retriesGet the list of account IDs for nodes with which execution will be attempted.(package private) NodegetNodeForExecute(int attempt) Return the next node for execution.(package private) abstract TransactionIdfinal DurationWhen execution is attempted, a single attempt will time out when this deadline is reached.protected booleanprotected voidlogTransaction(TransactionId transactionId, Client client, Node node, boolean isAsync, int attempt, ResponseT response, Throwable error) Logs the transaction's parameters(package private) abstract ProtoRequestT(package private) abstract OmapResponse(ResponseT response, AccountId nodeId, ProtoRequestT request) Called after receiving the query response from Hedera.(package private) abstract StatusmapResponseStatus(ResponseT response) (package private) voidmergeFromClient(Client client) (package private) abstract void(package private) abstract CompletableFuture<Void> onExecuteAsync(Client client) final SdkRequestTsetGrpcDeadline(Duration grpcDeadline) When execution is attempted, a single attempt will timeout when this deadline is reached.Set the loggerfinal SdkRequestTsetMaxAttempts(int maxAttempts) Set the maximum times execution will be attempted.final SdkRequestTsetMaxBackoff(Duration maxBackoff) The maximum amount of time to wait between retries.final SdkRequestTsetMaxRetry(int count) Deprecated.UsesetMaxAttempts(int)instead.final SdkRequestTsetMinBackoff(Duration minBackoff) The minimum amount of time to wait between retries.setNodeAccountIds(List<AccountId> nodeAccountIds) Set the account IDs of the nodes that this transaction will be submitted to.(package private) voidsetNodesFromNodeAccountIds(Client client) final SdkRequestTsetRequestListener(UnaryOperator<ProtoRequestT> requestListener) Set a callback that will be called right before the request is sent.final SdkRequestTsetResponseListener(UnaryOperator<ResponseT> responseListener) Set a callback that will be called right before the response is returned.(package private) boolean
-
Field Details
-
random
-
RST_STREAM
-
maxAttempts
The maximum times execution will be attempted -
maxBackoff
The maximum amount of time to wait between retries -
minBackoff
The minimum amount of time to wait between retries -
nodeAccountIds
List of account IDs for nodes with which execution will be attempted. -
nodes
List of healthy and unhealthy nodes with which execution will be attempted. -
attemptedAllNodes
protected boolean attemptedAllNodesIndicates if the request has been attempted to be sent to all nodes -
grpcDeadline
The timeout for each execution attempt -
logger
-
blockingUnaryCall
Function<Executable<SdkRequestT,ProtoRequestT extends com.google.protobuf.MessageLite, blockingUnaryCallResponseT extends com.google.protobuf.MessageLite, O>.GrpcRequest, ResponseT extends com.google.protobuf.MessageLite>
-
-
Constructor Details
-
Executable
Executable()
-
-
Method Details
-
grpcDeadline
When execution is attempted, a single attempt will time out when this deadline is reached. (The SDK may subsequently retry the execution.)- Returns:
- The timeout for each execution attempt
-
setGrpcDeadline
When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.)- Parameters:
grpcDeadline- The timeout for each execution attempt- Returns:
this
-
getMaxBackoff
The maximum amount of time to wait between retries- Returns:
- maxBackoff
-
setMaxBackoff
The maximum amount of time to wait between retries. Every retry attempt will increase the wait time exponentially until it reaches this time.- Parameters:
maxBackoff- The maximum amount of time to wait between retries- Returns:
this
-
getMinBackoff
The minimum amount of time to wait between retries- Returns:
- minBackoff
-
setMinBackoff
The minimum amount of time to wait between retries. When retrying, the delay will start at this time and increase exponentially until it reaches the maxBackoff.- Parameters:
minBackoff- The minimum amount of time to wait between retries- Returns:
this
-
getMaxRetry
Deprecated.UsegetMaxAttempts()instead.- Returns:
- Number of errors before execution will fail.
-
setMaxRetry
Deprecated.UsesetMaxAttempts(int)instead.- Parameters:
count- Number of errors before execution will fail- Returns:
this
-
getMaxAttempts
public final int getMaxAttempts()Get the maximum times execution will be attempted.- Returns:
- Number of errors before execution will fail.
-
setMaxAttempts
Set the maximum times execution will be attempted.- Parameters:
maxAttempts- Execution will fail after this many errors.- Returns:
this
-
getNodeAccountIds
Get the list of account IDs for nodes with which execution will be attempted.- Returns:
- the list of account IDs
-
setNodeAccountIds
Set the account IDs of the nodes that this transaction will be submitted to.Providing an explicit node account ID interferes with client-side load balancing of the network. By default, the SDK will pre-generate a transaction for 1/3 of the nodes on the network. If a node is down, busy, or otherwise reports a fatal error, the SDK will try again with a different node.
- Parameters:
nodeAccountIds- The list of node AccountIds to be set- Returns:
this
-
setRequestListener
Set a callback that will be called right before the request is sent. As input, the callback will receive the protobuf of the request, and the callback should return the request protobuf. This means the callback has an opportunity to read, copy, or modify the request that will be sent.- Parameters:
requestListener- The callback to use- Returns:
this
-
setResponseListener
Set a callback that will be called right before the response is returned. As input, the callback will receive the protobuf of the response, and the callback should return the response protobuf. This means the callback has an opportunity to read, copy, or modify the response that will be read.- Parameters:
responseListener- The callback to use- Returns:
this
-
setLogger
Set the logger- Parameters:
logger- the new logger- Returns:
this
-
checkNodeAccountIds
void checkNodeAccountIds() -
onExecute
-
onExecuteAsync
-
mergeFromClient
-
execute
Execute this transaction or query- Parameters:
client- The client with which this will be executed.- Returns:
- Result of execution
- Throws:
TimeoutException- when the transaction times outPrecheckStatusException- when the precheck fails
-
execute
Execute this transaction or query with a timeout- Parameters:
client- The client with which this will be executed.timeout- The timeout after which the execution attempt will be cancelled.- Returns:
- Result of execution
- Throws:
TimeoutException- when the transaction times outPrecheckStatusException- when the precheck fails
-
isBatchedAndNotBatchTransaction
protected boolean isBatchedAndNotBatchTransaction() -
executeAsync
Execute this transaction or query asynchronously.Note: This method requires API level 33 or higher. It will not work on devices running API versions below 31 because it uses features introduced in API level 31 (Android 12).
*- Parameters:
client- The client with which this will be executed.- Returns:
- Future result of execution
-
executeAsync
Execute this transaction or query asynchronously.Note: This method requires API level 33 or higher. It will not work on devices running API versions below 31 because it uses features introduced in API level 31 (Android 12).
*- Parameters:
client- The client with which this will be executed.timeout- The timeout after which the execution attempt will be cancelled.- Returns:
- Future result of execution
-
executeAsync
Execute this transaction or query asynchronously.- Parameters:
client- The client with which this will be executed.callback- a BiConsumer which handles the result or error.
-
executeAsync
Execute this transaction or query asynchronously.- Parameters:
client- The client with which this will be executed.timeout- The timeout after which the execution attempt will be cancelled.callback- a BiConsumer which handles the result or error.
-
executeAsync
Execute this transaction or query asynchronously.- Parameters:
client- The client with which this will be executed.onSuccess- a Consumer which consumes the result on success.onFailure- a Consumer which consumes the error on failure.
-
executeAsync
public void executeAsync(Client client, Duration timeout, Consumer<O> onSuccess, Consumer<Throwable> onFailure) Execute this transaction or query asynchronously.- Parameters:
client- The client with which this will be executed.timeout- The timeout after which the execution attempt will be cancelled.onSuccess- a Consumer which consumes the result on success.onFailure- a Consumer which consumes the error on failure.
-
logTransaction
protected void logTransaction(TransactionId transactionId, Client client, Node node, boolean isAsync, int attempt, @Nullable ResponseT response, @Nullable Throwable error) Logs the transaction's parameters- Parameters:
transactionId- the transaction's idclient- the client that executed the transactionnode- the node the transaction was sent toisAsync- whether the transaction was executed asynchronouslyattempt- the attempt numberresponse- the transaction response if the transaction was successfulerror- the error if the transaction was not successful
-
setNodesFromNodeAccountIds
-
getNodeForExecute
Return the next node for execution. Will select the first node that is deemed healthy. If we cannot find such a node and have tried n nodes (n being the size of the node list), we will select the node with the smallest remaining delay. All delays MUST be executed in calling layer as this method will be called for sync + async scenarios. -
makeRequest
-
getGrpcRequest
-
advanceRequest
void advanceRequest() -
mapResponse
Called after receiving the query response from Hedera. The derived class should map into its output type. -
mapResponseStatus
-
getMethodDescriptor
Called to direct the invocation of the query to the appropriate gRPC service. -
getTransactionIdInternal
-
shouldRetryExceptionally
-
getExecutionState
Default implementation, may be overridden in subclasses (especially for query case). Called just after receiving the query response from Hedera. By default it triggers a retry when the pre-check status isBUSY.
-
getMaxAttempts()instead.