Class: Staccato::Proxy::Listener

Inherits:
Object
  • Object
show all
Includes:
Celluloid::IO
Defined in:
lib/staccato/proxy/listener.rb

Constant Summary collapse

FRAME_SIZE =
4096

Instance Method Summary collapse

Constructor Details

#initialize(host, port, debug = false) ⇒ Listener

Returns a new instance of Listener.



7
8
9
10
11
12
# File 'lib/staccato/proxy/listener.rb', line 7

def initialize(host, port, debug = false)
  @socket = UDPSocket.new.tap {|s| s.bind(host, port)}
  @debug = debug

  async.run
end

Instance Method Details

#debug(msg) ⇒ Object



35
36
37
# File 'lib/staccato/proxy/listener.rb', line 35

def debug(msg)
  log(msg) if @debug
end

#finalizeObject



14
15
16
# File 'lib/staccato/proxy/listener.rb', line 14

def finalize
  @socket.close if @socket
end

#log(msg) ⇒ Object



31
32
33
# File 'lib/staccato/proxy/listener.rb', line 31

def log(msg)
  Celluloid.logger.info(msg)
end

#receive(data) ⇒ Object



22
23
24
25
# File 'lib/staccato/proxy/listener.rb', line 22

def receive(data)
  debug data
  sender.async.submit(data[0])
end

#runObject



18
19
20
# File 'lib/staccato/proxy/listener.rb', line 18

def run
  loop {async.receive(@socket.recvfrom(FRAME_SIZE))}
end

#senderObject



27
28
29
# File 'lib/staccato/proxy/listener.rb', line 27

def sender
  Celluloid::Actor[:staccato_proxy_sender]
end