Class BlockchainHealthIndicator

java.lang.Object
com.privatechain.spring.BlockchainHealthIndicator

public class BlockchainHealthIndicator extends Object
Provides blockchain health and status details as a plain Spring bean.

This class intentionally does not implement org.springframework.boot.actuate.health.HealthIndicator so that blockchain-spring compiles without a mandatory dependency on any particular Spring Boot Actuator version. The full health payload is exposed via getDetails() and isUp(), making it trivial for consuming applications to bridge to whichever Actuator API they use:


 // In your @Configuration class (spring-boot-actuator on YOUR classpath):
 @Bean
 HealthIndicator blockchainHealth(BlockchainHealthIndicator indicator) {
     return () -> indicator.isUp()
         ? Health.up().withDetails(indicator.getDetails()).build()
         : Health.down().withDetails(indicator.getDetails()).build();
 }
 

Sample detail map


 {
   "status":         "UP",
   "chainHeight":    42,
   "mempoolSize":    3,
   "peerCount":      2,
   "consensusEngine":"ProofOfWork",
   "lastBlockTime":  "2026-06-05T10:15:30Z"
 }
 
Since:
1.0.0
See Also:
  • Field Details

    • KEY_STATUS

      public static final String KEY_STATUS
      Detail key: overall UP / DOWN status string.
      See Also:
    • KEY_CHAIN_HEIGHT

      public static final String KEY_CHAIN_HEIGHT
      Detail key: current chain height (number of blocks including genesis).
      See Also:
    • KEY_MEMPOOL_SIZE

      public static final String KEY_MEMPOOL_SIZE
      Detail key: number of transactions currently in the mempool.
      See Also:
    • KEY_PEER_COUNT

      public static final String KEY_PEER_COUNT
      Detail key: number of currently connected peers.
      See Also:
    • KEY_ENGINE

      public static final String KEY_ENGINE
      Detail key: name of the active consensus engine.
      See Also:
    • KEY_LAST_BLOCK

      public static final String KEY_LAST_BLOCK
      Detail key: ISO-8601 timestamp of the most recently added block.
      See Also:
    • KEY_REASON

      public static final String KEY_REASON
      Detail key: human-readable error reason when status is DOWN.
      See Also:
  • Constructor Details

    • BlockchainHealthIndicator

      public BlockchainHealthIndicator(BlockchainNode node)
      Creates a health indicator wrapping the given blockchain node.

      Called by BlockchainAutoConfiguration — do not invoke directly.

      Parameters:
      node - the node to report on (non-null)
      Throws:
      NullPointerException - if node is null
  • Method Details

    • isUp

      public boolean isUp()
      Returns true when the node is running and BlockchainNode.status() can be called without throwing.
      Returns:
      true if the node is UP
    • getDetails

      public Map<String,Object> getDetails()
      Returns a snapshot of the node's health details as an immutable map.

      Always contains KEY_STATUS ("UP" or "DOWN"). When UP, also contains chain height, mempool size, peer count, consensus engine name, and last block time. When DOWN, also contains KEY_REASON with a human-readable explanation.

      Returns:
      non-null, non-empty detail map