Class: Orchestrator::Master
- Inherits:
-
Object
- Object
- Orchestrator::Master
- Defined in:
- lib/orchestrator/remote/master.rb
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
- #bind ⇒ Object
-
#initialize(thread) ⇒ Master
constructor
A new instance of Master.
- #online?(id) ⇒ Boolean
- #request(edge_id, details) ⇒ Object
- #unbind ⇒ Object
Constructor Details
#initialize(thread) ⇒ Master
Returns a new instance of Master.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/orchestrator/remote/master.rb', line 8 def initialize(thread) @thread = thread @accept_connection = method :accept_connection @new_connection = method :new_connection @bind_error = method :bind_error @shutdown = true @edge_nodes = ::ThreadSafe::Cache.new # id => connection @requests = {} # req_id => defer @req_map = {} # connection => ::Set.new (req_id) @signal_bind = @thread.async method(:bind_actual) @signal_unbind = @thread.async method(:unbind_actual) @request_id = 0 end |
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
27 28 29 |
# File 'lib/orchestrator/remote/master.rb', line 27 def thread @thread end |
Instance Method Details
#bind ⇒ Object
81 82 83 |
# File 'lib/orchestrator/remote/master.rb', line 81 def bind @signal_bind.call end |
#online?(id) ⇒ Boolean
72 73 74 75 |
# File 'lib/orchestrator/remote/master.rb', line 72 def online?(id) edge = @edge_nodes[id] edge && edge.connected ? edge : false end |
#request(edge_id, details) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/orchestrator/remote/master.rb', line 41 def request(edge_id, details) defer = @thread.defer # Lookup node connection = online? id if connection @thread.schedule do if connection.connected @request_id += 1 @requests[@request_id] = defer @req_map[connection] ||= ::Set.new @req_map[connection] << @request_id # Send the request connection.write(::JSON.fast_generate({ id: @request_id, })).catch do |reason| on_failure(defer, edge_id, details) end else on_failure(defer, edge_id, details) end end else on_failure(defer, edge_id, details) end defer.promise end |
#unbind ⇒ Object
77 78 79 |
# File 'lib/orchestrator/remote/master.rb', line 77 def unbind @signal_unbind.call end |