Class: Woodhouse::Layout::Node
- Inherits:
-
Object
- Object
- Woodhouse::Layout::Node
- Includes:
- Util
- Defined in:
- lib/woodhouse/layout.rb
Overview
A Node describes the set of workers present on a single Server.
More information about Woodhouse’s layout system can be found in the documentation for Woodhouse::Layout.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#workers ⇒ Object
readonly
Returns a frozen list of workers assigned to this node.
Instance Method Summary collapse
-
#add_worker(worker) ⇒ Object
Adds a Worker to this node.
- #clear ⇒ Object
-
#default_configuration!(config, options = {}) ⇒ Object
Configures this node with one worker per job (jobs obtained from Registry#each).
-
#frozen_clone ⇒ Object
Used by Layout#frozen_clone.
-
#initialize(name) ⇒ Node
constructor
A new instance of Node.
- #remove_worker(worker) ⇒ Object
- #worker_for_job(job) ⇒ Object
Constructor Details
#initialize(name) ⇒ Node
Returns a new instance of Node.
114 115 116 117 |
# File 'lib/woodhouse/layout.rb', line 114 def initialize(name) @name = name.to_sym @workers = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
112 113 114 |
# File 'lib/woodhouse/layout.rb', line 112 def name @name end |
#workers ⇒ Object
Returns a frozen list of workers assigned to this node.
120 121 122 |
# File 'lib/woodhouse/layout.rb', line 120 def workers @workers.frozen? ? @workers : @workers.dup.freeze end |
Instance Method Details
#add_worker(worker) ⇒ Object
Adds a Worker to this node.
125 126 127 128 |
# File 'lib/woodhouse/layout.rb', line 125 def add_worker(worker) expect_arg :worker, Woodhouse::Layout::Worker, worker @workers << worker end |
#clear ⇒ Object
141 142 143 |
# File 'lib/woodhouse/layout.rb', line 141 def clear @workers.clear end |
#default_configuration!(config, options = {}) ⇒ Object
Configures this node with one worker per job (jobs obtained from Registry#each). The default_threads
value of the given config
is used to determine how many threads should be assigned to each worker.
149 150 151 152 153 154 155 156 |
# File 'lib/woodhouse/layout.rb', line 149 def default_configuration!(config, = {}) [:threads] ||= config.default_threads config.registry.each do |name, klass| klass.public_instance_methods(false).each do |method| add_worker Woodhouse::Layout::Worker.new(name, method, ) end end end |
#frozen_clone ⇒ Object
Used by Layout#frozen_clone
159 160 161 162 163 164 |
# File 'lib/woodhouse/layout.rb', line 159 def frozen_clone # :nodoc: clone.tap do |cloned| cloned.workers = @workers.map{|worker| worker.frozen_clone }.freeze cloned.freeze end end |
#remove_worker(worker) ⇒ Object
130 131 132 133 |
# File 'lib/woodhouse/layout.rb', line 130 def remove_worker(worker) expect_arg :worker, Woodhouse::Layout::Worker, worker @workers.delete(worker) end |
#worker_for_job(job) ⇒ Object
135 136 137 138 139 |
# File 'lib/woodhouse/layout.rb', line 135 def worker_for_job(job) @workers.detect {|worker| worker.accepts_job?(job) } end |