Class: Dynflow::Listeners::Socket

Inherits:
Abstract
  • Object
show all
Includes:
Algebrick::Matching, Serialization
Defined in:
lib/dynflow/listeners/socket.rb

Constant Summary collapse

Terminate =
Algebrick.atom

Instance Attribute Summary

Attributes inherited from Abstract

#logger, #world

Instance Method Summary collapse

Methods included from Serialization

#dump, #load, #receive_message, #send_message

Constructor Details

#initialize(world, socket_path, interval = 1) ⇒ Socket

Returns a new instance of Socket.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dynflow/listeners/socket.rb', line 9

def initialize(world, socket_path, interval = 1)
  super(world)

  File.delete socket_path if File.exist? socket_path
  @server = UNIXServer.new socket_path
  File.chmod(0600, socket_path)

  @clients         = []
  @client_barriers = {}
  @terminate       = false
  @loop            = Thread.new do
    Thread.current.abort_on_exception = true
    catch(Terminate) { loop { listen(interval) } }
    @terminate.resolve true
  end
end

Instance Method Details

#terminate(future = Future.new) ⇒ Object



26
27
28
29
# File 'lib/dynflow/listeners/socket.rb', line 26

def terminate(future = Future.new)
  raise 'multiple calls' if @terminate
  @terminate = future
end