Class: Fyrehose::AbstractClient

Inherits:
Object
  • Object
show all
Defined in:
lib/fyrehose/abstract_client.rb

Direct Known Subclasses

TCPClient, UDPClient

Constant Summary collapse

TIMEOUT =
0.1

Instance Method Summary collapse

Constructor Details

#initialize(host, port, opts = {}) ⇒ AbstractClient

Returns a new instance of AbstractClient.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/fyrehose/abstract_client.rb', line 5

def initialize(host, port, opts = {})
  @host = host
  @port = port
  @opts = opts

  @timeout = if opts[:timeout]
    opts[:timeout].to_f
  else
    TIMEOUT
  end
end

Instance Method Details

#deliver(channel, data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fyrehose/abstract_client.rb', line 17

def deliver(channel, data)
  channel = channel.to_s
  data = data.to_s

  if channel.include?(" ")
    raise Fyrehose::Error.new("channel names must not include whitespace")
  end

  txid = Fyrehose.next_txid
  send_data("##{txid} @#{channel} *#{data.size} #{data}\n")
end