Class: Yup::State::BDB::FeedbackHandler

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/yup/state/bdb.rb

Instance Method Summary collapse

Constructor Details

#initialize(state) ⇒ FeedbackHandler

Returns a new instance of FeedbackHandler.



75
76
77
78
79
80
81
82
83
# File 'lib/yup/state/bdb.rb', line 75

def initialize(state)
  @state = state

  @yajl = Yajl::Parser.new(:symbolize_keys => true)
  @yajl.on_parse_complete = method(:on_message)

  @logger = Yup.logger.clone
  @logger.progname = "Yup::State::BDB::FeedbackHandler"
end

Instance Method Details

#on_message(req) ⇒ Object



93
94
95
# File 'lib/yup/state/bdb.rb', line 93

def on_message(req)
  @state.push(Yajl::Encoder.encode(req))
end

#receive_data(data) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/yup/state/bdb.rb', line 85

def receive_data(data)
  begin
    @yajl << data
  rescue Yajl::ParseError
    @logger.error { "Error while parsing \"#{data}\"" }
  end
end