Class: Async::Container::Notify::Server
- Inherits:
-
Object
- Object
- Async::Container::Notify::Server
- Defined in:
- lib/async/container/notify/server.rb
Overview
A simple UDP server that can be used to receive messages from a child process, tracking readiness, status changes, etc.
Defined Under Namespace
Classes: Context
Constant Summary collapse
- MAXIMUM_MESSAGE_SIZE =
4096
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
- #The path to the UNIX socket.(pathtotheUNIXsocket.) ⇒ Object readonly
Class Method Summary collapse
-
.generate_path ⇒ Object
Generate a new unique path for the UNIX socket.
-
.load(message) ⇒ Object
Parse a message, according to the ‘sd_notify` protocol.
-
.open(path = self.generate_path) ⇒ Object
Open a new server instance with a temporary and unique path.
Instance Method Summary collapse
-
#bind ⇒ Object
Generate a bound context for receiving messages.
-
#initialize(path) ⇒ Server
constructor
Initialize the server with the given path.
Constructor Details
#initialize(path) ⇒ Server
Initialize the server with the given path.
64 65 66 |
# File 'lib/async/container/notify/server.rb', line 64 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
69 70 71 |
# File 'lib/async/container/notify/server.rb', line 69 def path @path end |
#The path to the UNIX socket.(pathtotheUNIXsocket.) ⇒ Object (readonly)
69 |
# File 'lib/async/container/notify/server.rb', line 69 attr :path |
Class Method Details
.generate_path ⇒ Object
Generate a new unique path for the UNIX socket.
49 50 51 52 53 54 |
# File 'lib/async/container/notify/server.rb', line 49 def self.generate_path File.( "async-container-#{::Process.pid}-#{SecureRandom.hex(8)}.ipc", Dir.tmpdir ) end |
.load(message) ⇒ Object
Parse a message, according to the ‘sd_notify` protocol.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/async/container/notify/server.rb', line 22 def self.load() lines = .split("\n") lines.pop if lines.last == "" pairs = lines.map do |line| key, value = line.split("=", 2) key = key.downcase.to_sym if value == "0" value = false elsif value == "1" value = true elsif key == :errno and value =~ /\A\-?\d+\z/ value = Integer(value) end next [key, value] end return Hash[pairs] end |
.open(path = self.generate_path) ⇒ Object
Open a new server instance with a temporary and unique path.
57 58 59 |
# File 'lib/async/container/notify/server.rb', line 57 def self.open(path = self.generate_path) self.new(path) end |