Class: Woodhouse::Layout::Node

Inherits:
Object
  • Object
show all
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)

Instance Method Summary (collapse)

Constructor Details

- (Node) initialize(name)

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

- (Object) name (readonly)

Returns the value of attribute name



112
113
114
# File 'lib/woodhouse/layout.rb', line 112

def name
  @name
end

- (Object) workers

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

- (Object) add_worker(worker)

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

- (Object) clear



141
142
143
# File 'lib/woodhouse/layout.rb', line 141

def clear
  @workers.clear
end

- (Object) default_configuration!(config, options = {})

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, options = {})
  options[:threads] ||= config.default_threads
  config.registry.each do |name, klass|
    klass.available_jobs.each do |method|
      add_worker Woodhouse::Layout::Worker.new(name, method, options)
    end
  end
end

- (Object) frozen_clone

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

- (Object) remove_worker(worker)



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

- (Object) worker_for_job(job)



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