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 Details

    • DEFAULT_MAX_NODE_ATTEMPTS

      protected static final Integer DEFAULT_MAX_NODE_ATTEMPTS
    • random

      protected static final Random random
    • executor

      protected final ExecutorService executor
    • network

      protected Map<KeyT,List<BaseNodeT extends BaseNode<BaseNodeT,KeyT>>> network
      Map of node identifiers to nodes. Used to quickly fetch node for identifier.
    • nodes

      protected List<BaseNodeT extends BaseNode<BaseNodeT,KeyT>> nodes
      The list of all nodes.
    • healthyNodes

      protected List<BaseNodeT extends BaseNode<BaseNodeT,KeyT>> healthyNodes
      The list of currently healthy nodes.
    • minNodeBackoff

      protected Duration minNodeBackoff
      The current minimum backoff for the nodes in the network. This backoff is used when nodes return a bad gRPC status.
    • maxNodeBackoff

      protected Duration maxNodeBackoff
      The current maximum backoff for the nodes in the network. This backoff is used when nodes return a bad gRPC status.
    • closeTimeout

      protected Duration closeTimeout
      Timeout for closing either a single node when setting a new network, or closing the entire network.
    • maxNodeAttempts

      protected int maxNodeAttempts
      Limit for how many times we retry a node which has returned a bad gRPC status
    • transportSecurity

      protected boolean transportSecurity
      Is the network using transport security
    • minNodeReadmitTime

      protected Duration minNodeReadmitTime
      The min time to wait before attempting to readmit nodes.
    • maxNodeReadmitTime

      protected Duration maxNodeReadmitTime
      The max time to wait for readmitting nodes.
    • earliestReadmitTime

      protected Instant earliestReadmitTime
      The instant that readmission will happen after.
    • hasShutDownNow

      boolean hasShutDownNow
  • Constructor Details

  • Method Details

    • getLedgerId

      @Nullable LedgerId getLedgerId()
      Extract the ledger id.
      Returns:
      the ledger id
    • setLedgerId

      BaseNetworkT setLedgerId(@Nullable LedgerId ledgerId)
      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

      BaseNetworkT setMaxNodeAttempts(int maxNodeAttempts)
      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

      BaseNetworkT setMinNodeBackoff(Duration minNodeBackoff)
      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

      BaseNetworkT setMaxNodeBackoff(Duration maxNodeBackoff)
      Set the maximum backoff a node should use when receiving a bad gRPC status.
      Parameters:
      maxNodeBackoff - the max node backoff
      Returns:
      this
    • getMinNodeReadmitTime

      public Duration getMinNodeReadmitTime()
      Extract the minimum node readmit time.
      Returns:
      the minimum node readmit time
    • setMinNodeReadmitTime

      public void setMinNodeReadmitTime(Duration minNodeReadmitTime)
      Assign the minimum node readmit time.
      Parameters:
      minNodeReadmitTime - the minimum node readmit time
    • getMaxNodeReadmitTime

      public Duration getMaxNodeReadmitTime()
      Extract the maximum node readmit time.
      Returns:
      the maximum node readmit time
    • setMaxNodeReadmitTime

      public void setMaxNodeReadmitTime(Duration maxNodeReadmitTime)
      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

      BaseNetworkT setCloseTimeout(Duration closeTimeout)
      Assign the close timeout.
      Parameters:
      closeTimeout - the close timeout
      Returns:
      this
    • createNodeFromNetworkEntry

      protected abstract BaseNodeT createNodeFromNetworkEntry(Map.Entry<String,KeyT> entry)
    • getNodesToRemove

      protected List<Integer> getNodesToRemove(Map<String,KeyT> network)
      Returns a list of index in descending order to remove from the current node list. Descending order is important here because setNetwork(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 and AccountId when the network is a Network. 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 nodes
      InterruptedException - - when acquiring the lock
    • increaseBackoff

      void increaseBackoff(BaseNodeT node)
    • decreaseBackoff

      void decreaseBackoff(BaseNodeT node)
    • removeDeadNodes

      protected void removeDeadNodes() throws InterruptedException
      Remove any nodes from the network when they've exceeded the maxNodeAttempts limit
      Throws:
      InterruptedException - - when shutting down nodes
    • readmitNodes

      void readmitNodes()
      Readmits nodes from the `nodes` list into the `healthyNodes` list when the time is passed the earliestReadmitTime. 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

      List<BaseNodeT> getNodeProxies(KeyT key)
      Get all node proxies by key
      Parameters:
      key - the desired key
      Returns:
      the list of node proxies
    • getNumberOfMostHealthyNodes

      protected List<BaseNodeT> getNumberOfMostHealthyNodes(int count) throws InterruptedException
      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 exceeded maxNodeAttempts. 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

      @Nullable Throwable awaitClose(Instant deadline, @Nullable Throwable previousError)