Package com.privatechain.core.event
Class BlockchainEvent
java.lang.Object
com.privatechain.core.event.BlockchainEvent
- Direct Known Subclasses:
BlockchainEvent.BlockAddedEvent,BlockchainEvent.ForkDetectedEvent,BlockchainEvent.PeerConnectedEvent,BlockchainEvent.PeerDisconnectedEvent,BlockchainEvent.TransactionSubmittedEvent
public abstract sealed class BlockchainEvent
extends Object
permits BlockchainEvent.BlockAddedEvent, BlockchainEvent.TransactionSubmittedEvent, BlockchainEvent.PeerConnectedEvent, BlockchainEvent.PeerDisconnectedEvent, BlockchainEvent.ForkDetectedEvent
Sealed base type for all events published on the
BlockchainEventBus.
The sealed hierarchy guarantees that every event variant is known at compile
time, enabling exhaustive switch expressions in consumer code (FR-EVENT-01).
New event types can only be added by the library maintainer, which is intentional:
it prevents external subclasses from breaking switch exhaustiveness.
Event variants
BlockchainEvent.BlockAddedEvent— a new block was appended to the chainBlockchainEvent.TransactionSubmittedEvent— a transaction entered the mempoolBlockchainEvent.PeerConnectedEvent— a remote peer established a connectionBlockchainEvent.PeerDisconnectedEvent— a remote peer disconnectedBlockchainEvent.ForkDetectedEvent— two competing blocks at the same height were found
Handling events
eventBus.register(event -> {
if (event instanceof BlockchainEvent.BlockAddedEvent e) {
log.info("Block #{} added", e.getBlock().getIndex());
} else if (event instanceof BlockchainEvent.TransactionSubmittedEvent e) {
metricsCounter.increment();
}
});
- Since:
- 1.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classFired after a new block is successfully appended to the canonical chain.static final classFired when the node detects two competing valid blocks at the same chain height.static final classFired when a new peer successfully establishes a TCP connection to this node.static final classFired when a peer connection is closed, either gracefully or due to an error.static final classFired after a transaction successfully passes validation and enters the mempool. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedProtected constructor for subclasses; setsoccurredAtto the current time. -
Method Summary
Modifier and TypeMethodDescriptionReturns the UTC instant at which this event occurred.
-
Constructor Details
-
BlockchainEvent
protected BlockchainEvent()Protected constructor for subclasses; setsoccurredAtto the current time.
-
-
Method Details
-
getOccurredAt
Returns the UTC instant at which this event occurred.- Returns:
- non-null event timestamp
-