Class: Fabric::EventHub

Inherits:
ClientStub show all
Defined in:
lib/fabric/event_hub.rb

Constant Summary collapse

MAX_BLOCK_NUMBER =
4_611_686_018_427_387_903.freeze

Constants inherited from ClientStub

ClientStub::VALID_OPTIONS_KEYS

Instance Attribute Summary

Attributes inherited from ClientStub

#creds, #host, #logger, #options

Instance Method Summary collapse

Methods inherited from ClientStub

#initialize

Constructor Details

This class inherits a constructor from Fabric::ClientStub

Instance Method Details

#clientObject



5
6
7
# File 'lib/fabric/event_hub.rb', line 5

def client
  @client ||= ::Protos::Deliver::Stub.new host, creds, options
end

#connectionObject



13
14
15
# File 'lib/fabric/event_hub.rb', line 13

def connection
  @connection ||= client.deliver(queue.each).each
end

#observe(channel_id, identity, start_block = :newest, stop_block = MAX_BLOCK_NUMBER) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fabric/event_hub.rb', line 17

def observe(channel_id, identity, start_block = :newest, stop_block = MAX_BLOCK_NUMBER)
  tx_info = Fabric::TransactionInfo.new identity
  seek_header = build_seek_header channel_id, tx_info
  seek_info = build_seek_info start_block, stop_block
  envelope = build_envelope tx_info, seek_header, seek_info

  loop do
    queue.push envelope

    event = connection.next

    block = Fabric::BlockDecoder.decode_block(event.block)

    yield block if block_given?
  end
end

#queueObject



9
10
11
# File 'lib/fabric/event_hub.rb', line 9

def queue
  @queue ||= Fabric::EnumeratorQueue.new client
end