Class: Omega::Client::DSL::Base
- Includes:
- Omega::Client::DSL
- Defined in:
- lib/omega/client/dsl.rb
Overview
Internal helper, used to track dsl state
Instance Attribute Summary collapse
-
#parallel ⇒ Object
Boolean indicating if dsl should be run in parallel.
-
#workers ⇒ Object
Threads being managed.
Instance Method Summary collapse
-
#dsl ⇒ Object
override DSL::dsl, return self.
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#invoke(*args) ⇒ Object
Proxy invoke to client node.
-
#join ⇒ Object
Wait until all workers complete.
-
#node ⇒ Object
internally managed client node.
-
#notify(*args) ⇒ Object
Proxy notify to client node.
-
#rjr_node ⇒ Object
get underlying rjr_node.
-
#rjr_node=(val) ⇒ Object
set underlying rjr node.
-
#run(params, attrs = {}, &bl) ⇒ Object
Set attributes and run block w/ params (via worker if parallel is true).
Methods included from Omega::Client::DSL
#asteroid, #asteroid_belt, #asteroid_field, #dock, #galaxy, #gen_uuid, #interconnect, #jump_gate, #loc, #login, #logout, #mission, #missions_event_handler, #moon, #moons, #orbit, #planet, #proxied_system, #rand_location, #rand_resource, #random_axis, #random_orbit, #resource, #role, #schedule_event, #ship, #station, #station_orbit, #system, #user
Constructor Details
#initialize ⇒ Base
612 613 614 615 |
# File 'lib/omega/client/dsl.rb', line 612 def initialize @parallel = false @workers = [] end |
Instance Attribute Details
#parallel ⇒ Object
Boolean indicating if dsl should be run in parallel
582 583 584 |
# File 'lib/omega/client/dsl.rb', line 582 def parallel @parallel end |
#workers ⇒ Object
Threads being managed
585 586 587 |
# File 'lib/omega/client/dsl.rb', line 585 def workers @workers end |
Instance Method Details
#dsl ⇒ Object
override DSL::dsl, return self
552 553 554 |
# File 'lib/omega/client/dsl.rb', line 552 def dsl self end |
#invoke(*args) ⇒ Object
Proxy invoke to client node
572 573 574 |
# File 'lib/omega/client/dsl.rb', line 572 def invoke(*args) self.node.invoke *args end |
#join ⇒ Object
Wait until all workers complete
588 589 590 |
# File 'lib/omega/client/dsl.rb', line 588 def join @workers.each { |w| w.join } end |
#node ⇒ Object
internally managed client node
557 558 559 |
# File 'lib/omega/client/dsl.rb', line 557 def node @node ||= Client::Node.new end |
#notify(*args) ⇒ Object
Proxy notify to client node
577 578 579 |
# File 'lib/omega/client/dsl.rb', line 577 def notify(*args) self.node.notify *args end |
#rjr_node ⇒ Object
get underlying rjr_node
562 563 564 |
# File 'lib/omega/client/dsl.rb', line 562 def rjr_node self.node.rjr_node end |
#rjr_node=(val) ⇒ Object
set underlying rjr node
567 568 569 |
# File 'lib/omega/client/dsl.rb', line 567 def rjr_node=(val) self.node.rjr_node = val end |
#run(params, attrs = {}, &bl) ⇒ Object
Set attributes and run block w/ params (via worker if parallel is true)
TODO use thread pool for this?
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/omega/client/dsl.rb', line 595 def run(params, attrs={}, &bl) if @parallel @workers << Thread.new(params, attrs) { |params,attrs| # create new base instance and run # block there to safely set attributes b = Base.new b.rjr_node = self.node.rjr_node b.run params, attrs, &bl } else attrs.each { |k,v| self.instance_variable_set("@#{k}".intern, v)} instance_exec params, &bl unless bl.nil? attrs.each { |k,v| self.instance_variable_set("@#{k}".intern, nil)} end end |