Class: CDC::Core::EventPosition

Inherits:
Object
  • Object
show all
Defined in:
lib/cdc/core/event_position.rb

Overview

Immutable representation of an event’s position metadata.

EventPosition is intentionally small and transport-agnostic. It captures the position strategy plus the event fields that a runtime may use to preserve ordering guarantees.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategy:, value:, transaction_id: nil, sequence_number: nil, occurred_at: nil) ⇒ EventPosition

Build an event position.

Parameters:

  • strategy (#to_sym)

    position strategy

  • value (Object, nil)

    primary position value

  • transaction_id (Object, nil) (defaults to: nil)

    transaction identifier

  • sequence_number (Integer, nil) (defaults to: nil)

    sequence number

  • occurred_at (Time, nil) (defaults to: nil)

    event timestamp



25
26
27
28
29
30
31
32
# File 'lib/cdc/core/event_position.rb', line 25

def initialize(strategy:, value:, transaction_id: nil, sequence_number: nil, occurred_at: nil)
  @strategy = strategy.to_sym
  @value = value
  @transaction_id = transaction_id
  @sequence_number = sequence_number
  @occurred_at = occurred_at
  Ractor.make_shareable(self)
end

Instance Attribute Details

#occurred_atSymbol, ... (readonly)

Returns:

  • (Symbol)

    position strategy

  • (Object, nil)

    primary position value for the chosen strategy

  • (Object, nil)

    transaction identifier associated with the event

  • (Integer, nil)

    sequence number within a transaction or stream

  • (Time, nil)

    timestamp associated with the event



16
17
18
# File 'lib/cdc/core/event_position.rb', line 16

def occurred_at
  @occurred_at
end

#sequence_numberSymbol, ... (readonly)

Returns:

  • (Symbol)

    position strategy

  • (Object, nil)

    primary position value for the chosen strategy

  • (Object, nil)

    transaction identifier associated with the event

  • (Integer, nil)

    sequence number within a transaction or stream

  • (Time, nil)

    timestamp associated with the event



16
17
18
# File 'lib/cdc/core/event_position.rb', line 16

def sequence_number
  @sequence_number
end

#strategySymbol, ... (readonly)

Returns:

  • (Symbol)

    position strategy

  • (Object, nil)

    primary position value for the chosen strategy

  • (Object, nil)

    transaction identifier associated with the event

  • (Integer, nil)

    sequence number within a transaction or stream

  • (Time, nil)

    timestamp associated with the event



16
17
18
# File 'lib/cdc/core/event_position.rb', line 16

def strategy
  @strategy
end

#transaction_idSymbol, ... (readonly)

Returns:

  • (Symbol)

    position strategy

  • (Object, nil)

    primary position value for the chosen strategy

  • (Object, nil)

    transaction identifier associated with the event

  • (Integer, nil)

    sequence number within a transaction or stream

  • (Time, nil)

    timestamp associated with the event



16
17
18
# File 'lib/cdc/core/event_position.rb', line 16

def transaction_id
  @transaction_id
end

#valueSymbol, ... (readonly)

Returns:

  • (Symbol)

    position strategy

  • (Object, nil)

    primary position value for the chosen strategy

  • (Object, nil)

    transaction identifier associated with the event

  • (Integer, nil)

    sequence number within a transaction or stream

  • (Time, nil)

    timestamp associated with the event



16
17
18
# File 'lib/cdc/core/event_position.rb', line 16

def value
  @value
end

Instance Method Details

#to_hHash{String=>Object,nil}

Convert the position into a Ractor-shareable hash.

Returns:

  • (Hash{String=>Object,nil})


37
38
39
40
41
42
43
44
45
# File 'lib/cdc/core/event_position.rb', line 37

def to_h
  Ractor.make_shareable({
    'strategy' => strategy,
    'value' => value,
    'transaction_id' => transaction_id,
    'sequence_number' => sequence_number,
    'occurred_at' => occurred_at
  }.freeze)
end