Class: Uninterruptible::Binder

Inherits:
Object
  • Object
show all
Defined in:
lib/uninterruptible/binder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bind_address) ⇒ Binder

Returns a new instance of Binder.

Parameters:

  • bind_address (String)

    The config for a server we’re returning the socket for @example

    "unix:///tmp/server.sock"
    "tcp://127.0.0.1:8080"
    


11
12
13
# File 'lib/uninterruptible/binder.rb', line 11

def initialize(bind_address)
  @bind_uri = parse_bind_address(bind_address)
end

Instance Attribute Details

#bind_uriObject (readonly)

Returns the value of attribute bind_uri.



5
6
7
# File 'lib/uninterruptible/binder.rb', line 5

def bind_uri
  @bind_uri
end

Instance Method Details

#bind_to_socketTCPServer, UNIXServer

Bind to the TCP or UNIX socket defined in the #bind_uri

Returns:

  • (TCPServer, UNIXServer)

    Successfully bound server

Raises:



20
21
22
23
24
25
26
27
28
29
# File 'lib/uninterruptible/binder.rb', line 20

def bind_to_socket
  case bind_uri.scheme
  when 'tcp'
    bind_to_tcp_socket
  when 'unix'
    bind_to_unix_socket
  else
    raise Uninterruptible::ConfigurationError, "Can only bind to TCP and UNIX sockets"
  end
end