Package com.privatechain.spring
Class BlockchainHealthIndicator
java.lang.Object
com.privatechain.spring.BlockchainHealthIndicator
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDetail key: current chain height (number of blocks including genesis).static final StringDetail key: name of the active consensus engine.static final StringDetail key: ISO-8601 timestamp of the most recently added block.static final StringDetail key: number of transactions currently in the mempool.static final StringDetail key: number of currently connected peers.static final StringDetail key: human-readable error reason when status is DOWN.static final StringDetail key: overall UP / DOWN status string. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a health indicator wrapping the given blockchain node. -
Method Summary
Modifier and TypeMethodDescriptionReturns a snapshot of the node's health details as an immutable map.booleanisUp()Returnstruewhen the node is running andBlockchainNode.status()can be called without throwing.
-
Field Details
-
KEY_STATUS
Detail key: overall UP / DOWN status string.- See Also:
-
KEY_CHAIN_HEIGHT
Detail key: current chain height (number of blocks including genesis).- See Also:
-
KEY_MEMPOOL_SIZE
Detail key: number of transactions currently in the mempool.- See Also:
-
KEY_PEER_COUNT
Detail key: number of currently connected peers.- See Also:
-
KEY_ENGINE
Detail key: name of the active consensus engine.- See Also:
-
KEY_LAST_BLOCK
Detail key: ISO-8601 timestamp of the most recently added block.- See Also:
-
KEY_REASON
Detail key: human-readable error reason when status is DOWN.- See Also:
-
-
Constructor Details
-
BlockchainHealthIndicator
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- ifnodeis null
-
-
Method Details
-
isUp
public boolean isUp()Returnstruewhen the node is running andBlockchainNode.status()can be called without throwing.- Returns:
trueif the node is UP
-
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 containsKEY_REASONwith a human-readable explanation.- Returns:
- non-null, non-empty detail map
-