Class: Dizby::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/dizby/service.rb

Constant Summary collapse

DEFAULT_CONFIG =
{
  idconv: IdConverter,
  argc_limit: 256,
  load_limit: 256 * 1024 * 100,
  logging: {
    level: Logger::ERROR,
    output: $stderr
  },
  tcp_acl: nil
}

Instance Method Summary collapse

Constructor Details

#initialize(uri = '', front = nil, config = {}) ⇒ Service

Returns a new instance of Service.


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dizby/service.rb', line 9

def initialize(uri = '', front = nil, config = {})
  config = DEFAULT_CONFIG.merge(config)

  self.server = ProtocolManager.open_server(uri, front, config)
rescue NonAcceptingServer => err
  # This is to allow servers that don't accept connections
  # Not all servers will allow connections back to them, so don't allow it
  self.server = err.server
  @server.log.warn('using a server that does not allow connections')
else
  @worker = ServiceWorker.new(@server)
ensure
  Dizby.register_server(@server)
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)

38
39
40
# File 'lib/dizby/service.rb', line 38

def alive?
  @server.alive?
end

#close


32
33
34
35
36
# File 'lib/dizby/service.rb', line 32

def close
  Dizby.unregister_server @server
  return unless alive?
  @server.shutdown
end

#connect_to(uri)


24
25
26
# File 'lib/dizby/service.rb', line 24

def connect_to(uri)
  ObjectProxy.new(*@server.connect_to(uri))
end

#server=(srvr) (private)


59
60
61
62
# File 'lib/dizby/service.rb', line 59

def server=(srvr)
  fail DistributedError, 'server could not be opened' unless srvr
  @server = srvr
end

#spawn_on(command, uri)


28
29
30
# File 'lib/dizby/service.rb', line 28

def spawn_on(command, uri)
  ObjectProxy.new(*@server.spawn_on(command, uri))
end

#wait


42
43
44
# File 'lib/dizby/service.rb', line 42

def wait
  @worker.join if @worker
end