Module com.hedera.hashgraph.sdk
Package com.hedera.hashgraph.sdk
Class BaseNetwork<BaseNetworkT extends BaseNetwork<BaseNetworkT,KeyT,BaseNodeT>,KeyT,BaseNodeT extends BaseNode<BaseNodeT,KeyT>>
java.lang.Object
com.hedera.hashgraph.sdk.BaseNetwork<BaseNetworkT,KeyT,BaseNodeT>
- Type Parameters:
BaseNetworkT- - The network that is extending this class. This is used for builder pattern setter methods.KeyT- - The identifying type for the network.BaseNodeT- - The specific node type for this network.
- Direct Known Subclasses:
MirrorNetwork,Network
abstract class BaseNetwork<BaseNetworkT extends BaseNetwork<BaseNetworkT,KeyT,BaseNodeT>,KeyT,BaseNodeT extends BaseNode<BaseNodeT,KeyT>>
extends Object
Abstracts away most of the similar functionality between
Network and MirrorNetwork-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DurationTimeout for closing either a single node when setting a new network, or closing the entire network.protected static final Integerprotected InstantThe instant that readmission will happen after.protected final ExecutorService(package private) booleanThe list of currently healthy nodes.protected intLimit for how many times we retry a node which has returned a bad gRPC statusprotected DurationThe current maximum backoff for the nodes in the network.protected DurationThe max time to wait for readmitting nodes.protected DurationThe current minimum backoff for the nodes in the network.protected DurationThe min time to wait before attempting to readmit nodes.Map of node identifiers to nodes.The list of all nodes.protected static final Randomprotected booleanIs the network using transport security -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) ThrowableawaitClose(Instant deadline, Throwable previousError) (package private) voidprotected abstract BaseNodeT(package private) voiddecreaseBackoff(BaseNodeT node) (package private) DurationExtract the close timeout.(package private) LedgerIdExtract the ledger id.(package private) intExtract the node attempts.(package private) DurationExtract the maximum node backoff time.Extract the maximum node readmit time.(package private) DurationExtract the minimum node backoff time.Extract the minimum node readmit time.getNodeProxies(KeyT key) Get all node proxies by keygetNodesToRemove(Map<String, KeyT> network) Returns a list of index in descending order to remove from the current node list.getNumberOfMostHealthyNodes(int count) Returns `count` number of the most healthy nodes.(package private) BaseNodeTGet a random healthy node.(package private) voidincreaseBackoff(BaseNodeT node) (package private) booleanIs transport Security enabled?(package private) voidReadmits nodes from the `nodes` list into the `healthyNodes` list when the time is passed theearliestReadmitTime.protected voidRemove any nodes from the network when they've exceeded themaxNodeAttemptslimit(package private) BaseNetworkTsetCloseTimeout(Duration closeTimeout) Assign the close timeout.(package private) BaseNetworkTsetLedgerId(LedgerId ledgerId) Set the new LedgerId for this network.(package private) BaseNetworkTsetMaxNodeAttempts(int maxNodeAttempts) Set the max number of times a node can return a bad gRPC status before we remove it from the list.(package private) BaseNetworkTsetMaxNodeBackoff(Duration maxNodeBackoff) Set the maximum backoff a node should use when receiving a bad gRPC status.voidsetMaxNodeReadmitTime(Duration maxNodeReadmitTime) Assign the maximum node readmit time.(package private) BaseNetworkTsetMinNodeBackoff(Duration minNodeBackoff) Set the minimum backoff a node should use when receiving a bad gRPC status.voidsetMinNodeReadmitTime(Duration minNodeReadmitTime) Assign the minimum node readmit time.(package private) BaseNetworkTsetNetwork(Map<String, KeyT> network) Intelligently overwrites the current network.
-
Field Details
-
DEFAULT_MAX_NODE_ATTEMPTS
-
random
-
executor
-
network
Map of node identifiers to nodes. Used to quickly fetch node for identifier. -
nodes
The list of all nodes. -
healthyNodes
The list of currently healthy nodes. -
minNodeBackoff
The current minimum backoff for the nodes in the network. This backoff is used when nodes return a bad gRPC status. -
maxNodeBackoff
The current maximum backoff for the nodes in the network. This backoff is used when nodes return a bad gRPC status. -
closeTimeout
Timeout for closing either a single node when setting a new network, or closing the entire network. -
maxNodeAttempts
protected int maxNodeAttemptsLimit for how many times we retry a node which has returned a bad gRPC status -
transportSecurity
protected boolean transportSecurityIs the network using transport security -
minNodeReadmitTime
The min time to wait before attempting to readmit nodes. -
maxNodeReadmitTime
The max time to wait for readmitting nodes. -
earliestReadmitTime
The instant that readmission will happen after. -
hasShutDownNow
boolean hasShutDownNow
-
-
Constructor Details
-
BaseNetwork
-
-
Method Details
-
getLedgerId
Extract the ledger id.- Returns:
- the ledger id
-
setLedgerId
Set the new LedgerId for this network. LedgerIds are used for TLS certificate checking and entity ID checksum validation.- Parameters:
ledgerId- the ledger id- Returns:
this
-
getMaxNodeAttempts
int getMaxNodeAttempts()Extract the node attempts.- Returns:
- maximum node attempts
-
setMaxNodeAttempts
Set the max number of times a node can return a bad gRPC status before we remove it from the list.- Parameters:
maxNodeAttempts- the max node attempts- Returns:
this
-
getMinNodeBackoff
Duration getMinNodeBackoff()Extract the minimum node backoff time.- Returns:
- the minimum node backoff time
-
setMinNodeBackoff
Set the minimum backoff a node should use when receiving a bad gRPC status.- Parameters:
minNodeBackoff- the min node backoff- Returns:
this
-
getMaxNodeBackoff
Duration getMaxNodeBackoff()Extract the maximum node backoff time.- Returns:
- the maximum node backoff time
-
setMaxNodeBackoff
Set the maximum backoff a node should use when receiving a bad gRPC status.- Parameters:
maxNodeBackoff- the max node backoff- Returns:
this
-
getMinNodeReadmitTime
Extract the minimum node readmit time.- Returns:
- the minimum node readmit time
-
setMinNodeReadmitTime
Assign the minimum node readmit time.- Parameters:
minNodeReadmitTime- the minimum node readmit time
-
getMaxNodeReadmitTime
Extract the maximum node readmit time.- Returns:
- the maximum node readmit time
-
setMaxNodeReadmitTime
Assign the maximum node readmit time.- Parameters:
maxNodeReadmitTime- the maximum node readmit time
-
isTransportSecurity
boolean isTransportSecurity()Is transport Security enabled?- Returns:
- using transport security
-
getCloseTimeout
Duration getCloseTimeout()Extract the close timeout.- Returns:
- the close timeout
-
setCloseTimeout
Assign the close timeout.- Parameters:
closeTimeout- the close timeout- Returns:
this
-
createNodeFromNetworkEntry
-
getNodesToRemove
Returns a list of index in descending order to remove from the current node list. Descending order is important here becausesetNetwork(Map<String, KeyT>)uses a for-each loop.- Parameters:
network- - the new network- Returns:
- - list of indexes in descending order
-
setNetwork
Intelligently overwrites the current network. Shutdown and remove any node from the current network if the new network doesn't contain it. This includes checking both the URL andAccountIdwhen the network is aNetwork. Add any nodes from the new network that don't already exist in the network.- Parameters:
network- - The new network- Returns:
- -
this - Throws:
TimeoutException- - when shutting down nodesInterruptedException- - when acquiring the lock
-
increaseBackoff
-
decreaseBackoff
-
removeDeadNodes
Remove any nodes from the network when they've exceeded themaxNodeAttemptslimit- Throws:
InterruptedException- - when shutting down nodes
-
readmitNodes
void readmitNodes()Readmits nodes from the `nodes` list into the `healthyNodes` list when the time is passed theearliestReadmitTime. While readmitting nodes the `earliestReadmitTime` will be updated to a new value. This value is either the value of the node with the smallest readmission time from now, or `minNodeReadmitTime` or `maxNodeReadmitTime`. -
getRandomNode
BaseNodeT getRandomNode()Get a random healthy node.- Returns:
- the node
-
getNodeProxies
Get all node proxies by key- Parameters:
key- the desired key- Returns:
- the list of node proxies
-
getNumberOfMostHealthyNodes
Returns `count` number of the most healthy nodes. Healthy-ness is determined by sort order; leftmost being most healthy. This will also remove any nodes which have hit or exceededmaxNodeAttempts. Returns a list of nodes where each node has a unique key.- Parameters:
count- number of nodes to return- Returns:
- List of nodes to use
- Throws:
InterruptedException- when a thread is interrupted while it's waiting, sleeping, or otherwise occupied
-
beginClose
void beginClose() -
awaitClose
-