Class: Unleash::StreamingEventProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/unleash/streaming_event_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(toggle_engine) ⇒ StreamingEventProcessor

Returns a new instance of StreamingEventProcessor.



8
9
10
11
# File 'lib/unleash/streaming_event_processor.rb', line 8

def initialize(toggle_engine)
  self.toggle_engine = toggle_engine
  self.mutex = Mutex.new
end

Instance Attribute Details

#mutexObject

Returns the value of attribute mutex.



6
7
8
# File 'lib/unleash/streaming_event_processor.rb', line 6

def mutex
  @mutex
end

#toggle_engineObject

Returns the value of attribute toggle_engine.



6
7
8
# File 'lib/unleash/streaming_event_processor.rb', line 6

def toggle_engine
  @toggle_engine
end

Instance Method Details

#handle_delta_event(event_data) ⇒ Object



29
30
31
32
33
# File 'lib/unleash/streaming_event_processor.rb', line 29

def handle_delta_event(event_data)
  self.mutex.synchronize do
    self.toggle_engine.take_state(event_data)
  end
end

#process_event(event) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/unleash/streaming_event_processor.rb', line 13

def process_event(event)
  case event.type.to_s
  when 'unleash-connected'
    Unleash.logger.debug "Streaming client connected"
    handle_connected_event(event)
  when 'unleash-updated'
    Unleash.logger.debug "Received streaming update"
    handle_updated_event(event)
  else
    Unleash.logger.debug "Received unknown event type: #{event.type}"
  end
rescue StandardError => e
  Unleash.logger.error "Error handling streaming event threw exception #{e.class}: '#{e}'"
  Unleash.logger.debug "stacktrace: #{e.backtrace}"
end