Class: Orchestra::Conductor
- Inherits:
-
Object
- Object
- Orchestra::Conductor
- Defined in:
- lib/orchestra/conductor.rb
Defined Under Namespace
Classes: ServiceRecorder
Instance Attribute Summary collapse
-
#observers ⇒ Object
readonly
Returns the value of attribute observers.
-
#services ⇒ Object
readonly
Returns the value of attribute services.
-
#thread_pool ⇒ Object
readonly
Returns the value of attribute thread_pool.
Instance Method Summary collapse
- #add_observer(observer) ⇒ Object
- #build_registry(observable) ⇒ Object
- #copy_observers(observable) ⇒ Object
- #delete_observer(observer) ⇒ Object
- #execute(operation, input = {}) ⇒ Object
-
#initialize(services = {}) ⇒ Conductor
constructor
A new instance of Conductor.
- #record(*args) ⇒ Object
- #resolve_service(observable, service_name) ⇒ Object
- #thread_count ⇒ Object
- #thread_count=(new_count) ⇒ Object
Constructor Details
#initialize(services = {}) ⇒ Conductor
Returns a new instance of Conductor.
5 6 7 8 9 10 11 12 13 |
# File 'lib/orchestra/conductor.rb', line 5 def initialize services = {} @services = services @thread_pool = ThreadPool.new @observers = Set.new self.thread_count = Configuration.thread_count if block_given? raise ArgumentError, "Supplied block to Conductor.new; did you mean to invoke Orchestra::Operation.new do … end?" end end |
Instance Attribute Details
#observers ⇒ Object (readonly)
Returns the value of attribute observers.
3 4 5 |
# File 'lib/orchestra/conductor.rb', line 3 def observers @observers end |
#services ⇒ Object (readonly)
Returns the value of attribute services.
3 4 5 |
# File 'lib/orchestra/conductor.rb', line 3 def services @services end |
#thread_pool ⇒ Object (readonly)
Returns the value of attribute thread_pool.
3 4 5 |
# File 'lib/orchestra/conductor.rb', line 3 def thread_pool @thread_pool end |
Instance Method Details
#add_observer(observer) ⇒ Object
33 34 35 |
# File 'lib/orchestra/conductor.rb', line 33 def add_observer observer observers << observer end |
#build_registry(observable) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/orchestra/conductor.rb', line 46 def build_registry observable hsh = { :conductor => self } services.each_with_object hsh do |(service_name, _), hsh| service = resolve_service observable, service_name hsh[service_name] = service if service end end |
#copy_observers(observable) ⇒ Object
41 42 43 44 |
# File 'lib/orchestra/conductor.rb', line 41 def copy_observers observable add_observer = observable.method :add_observer observers.each &add_observer end |
#delete_observer(observer) ⇒ Object
37 38 39 |
# File 'lib/orchestra/conductor.rb', line 37 def delete_observer observer observers.delete observer end |
#execute(operation, input = {}) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/orchestra/conductor.rb', line 15 def execute operation, input = {} operation.execute self, input do |execution| copy_observers execution yield execution if block_given? end end |
#record(*args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/orchestra/conductor.rb', line 22 def record *args recording = Recording.fresh add_observer recording execute *args do |execution| execution.add_observer recording end recording ensure delete_observer recording end |
#resolve_service(observable, service_name) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/orchestra/conductor.rb', line 54 def resolve_service observable, service_name return nil unless services.has_key? service_name service = Util.to_lazy_thunk services[service_name] recording = ServiceRecorder.new observable, service_name recording.wrap service.call self end |
#thread_count ⇒ Object
61 62 63 |
# File 'lib/orchestra/conductor.rb', line 61 def thread_count @thread_pool.count end |
#thread_count=(new_count) ⇒ Object
65 66 67 |
# File 'lib/orchestra/conductor.rb', line 65 def thread_count= new_count @thread_pool.count = new_count end |