Class: Omega::Client::DSL::Base

Inherits:
Object
  • Object
show all
Includes:
Omega::Client::DSL
Defined in:
lib/omega/client/dsl.rb

Overview

Internal helper, used to track dsl state

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#initializeBase

Returns a new instance of Base


612
613
614
615
# File 'lib/omega/client/dsl.rb', line 612

def initialize
  @parallel = false
  @workers  = []
end

Instance Attribute Details

#parallelObject

Boolean indicating if dsl should be run in parallel


582
583
584
# File 'lib/omega/client/dsl.rb', line 582

def parallel
  @parallel
end

#workersObject

Threads being managed


585
586
587
# File 'lib/omega/client/dsl.rb', line 585

def workers
  @workers
end

Instance Method Details

#dslObject

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

#joinObject

Wait until all workers complete


588
589
590
# File 'lib/omega/client/dsl.rb', line 588

def join
  @workers.each { |w| w.join }
end

#nodeObject

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_nodeObject

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