Class: Puggernaut::Client

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/puggernaut/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#logger, logger

Constructor Details

#initialize(*servers) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
# File 'lib/puggernaut/client.rb', line 12

def initialize(*servers)
  @connections = {}
  @retry = []
  @servers = servers.collect { |s| s.split(':') }
end

Instance Attribute Details

#connectionsObject

Returns the value of attribute connections.



10
11
12
# File 'lib/puggernaut/client.rb', line 10

def connections
  @connections
end

Instance Method Details

#closeObject



18
19
20
21
22
23
# File 'lib/puggernaut/client.rb', line 18

def close
  @connections.each do |host_port, connection|
    connection.close
    logger.info "Client#close - #{host_port}"
  end
end

#push(messages) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/puggernaut/client.rb', line 25

def push(messages)
  messages = messages.collect do |channel, message|
    if message.is_a?(::Array)
      message.collect { |m| "#{channel}|#{m}" }.join("\n")
    else
      "#{channel}|#{message}"
    end
  end
  unless messages.empty?
    @servers.each do |(host, port)|
      send host, port, messages.join("\n")
    end
  end
end