Class: FluQ::Input::Socket

Inherits:
Base
  • Object
show all
Defined in:
lib/fluq/input/socket.rb

Defined Under Namespace

Classes: Connection

Instance Attribute Summary collapse

Attributes inherited from Base

#config, #reactor

Instance Method Summary collapse

Methods inherited from Base

#flush!, #new_buffer

Methods included from Mixins::Loggable

#logger

Constructor Details

#initializeSocket

Constructor.

Examples:

Launch a server


server = FluQ::Server.new(reactor, bind: "tcp://localhost:7654")

Parameters:

  • options (Hash)

    a customizable set of options

Raises:

  • (ArgumentError)


14
15
16
17
18
19
# File 'lib/fluq/input/socket.rb', line 14

def initialize(*)
  super

  raise ArgumentError, 'No URL to bind to provided, make sure you pass :bind option' unless config[:bind]
  @url = FluQ::URL.parse(config[:bind], protocols)
end

Instance Attribute Details

#urlObject (readonly)



4
5
6
# File 'lib/fluq/input/socket.rb', line 4

def url
  @url
end

Instance Method Details

#nameString

Returns descriptive name.

Returns:

  • (String)

    descriptive name



22
23
24
# File 'lib/fluq/input/socket.rb', line 22

def name
  @name ||= "#{super} (#{@url})"
end

#runObject

Start the server



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fluq/input/socket.rb', line 27

def run
  args = [self.class::Connection, self]
  case @url.scheme
  when 'tcp'
    EventMachine.start_server @url.host, @url.port, *args
  when 'udp'
    EventMachine.open_datagram_socket @url.host, @url.port, *args
  when 'unix'
    EventMachine.start_server @url.path, *args
  end
end