class Baleen::Connection

Public Class Methods

new(socket=nil) click to toggle source
# File lib/baleen/connection.rb, line 3
def initialize(socket=nil)
  @socket = socket
end

Public Instance Methods

close() click to toggle source
# File lib/baleen/connection.rb, line 23
def close
  @socket.close
end
notify_error(msg) click to toggle source
# File lib/baleen/connection.rb, line 15
def notify_error(msg)
  notify_to_client(msg, "error")
end
notify_exception(msg) click to toggle source
# File lib/baleen/connection.rb, line 27
def notify_exception(msg)
  response = Baleen::Message::Exception.new({:message => msg})
  write(response.to_json)
end
notify_info(msg) click to toggle source
# File lib/baleen/connection.rb, line 7
def notify_info(msg)
  notify_to_client(msg, "info")
end
notify_warn(msg) click to toggle source
# File lib/baleen/connection.rb, line 11
def notify_warn(msg)
  notify_to_client(msg, "warn")
end
respond(response) click to toggle source
# File lib/baleen/connection.rb, line 19
def respond(response)
  write(response.to_json)
end

Private Instance Methods

notify_to_client(msg, level) click to toggle source
# File lib/baleen/connection.rb, line 34
def notify_to_client(msg, level)
  response = Baleen::Message::ToClient.new({:message => msg, :level => level})
  write(response.to_json)
end
write(json_data) click to toggle source
# File lib/baleen/connection.rb, line 39
def write(json_data)
  if @socket
    @socket.puts(json_data)
  else
    nil
  end
end