Class BlockchainEvent

java.lang.Object
com.privatechain.core.event.BlockchainEvent
Direct Known Subclasses:
BlockchainEvent.BlockAddedEvent, BlockchainEvent.ForkDetectedEvent, BlockchainEvent.PeerConnectedEvent, BlockchainEvent.PeerDisconnectedEvent, BlockchainEvent.TransactionSubmittedEvent

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

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
  • Constructor Details

    • BlockchainEvent

      protected BlockchainEvent()
      Protected constructor for subclasses; sets occurredAt to the current time.
  • Method Details

    • getOccurredAt

      public Instant getOccurredAt()
      Returns the UTC instant at which this event occurred.
      Returns:
      non-null event timestamp