Class: Sfp::Runtime
- Inherits:
-
Object
- Object
- Sfp::Runtime
- Defined in:
- lib/sfpagent/runtime.rb
Instance Attribute Summary collapse
-
#cloudfinder ⇒ Object
readonly
Returns the value of attribute cloudfinder.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #execute_action(action) ⇒ Object
- #get_state(as_sfp = false) ⇒ Object
-
#initialize(model) ⇒ Runtime
constructor
A new instance of Runtime.
- #normalise_parameters(params) ⇒ Object
- #set_model(model) ⇒ Object
- #whoami? ⇒ Boolean
Constructor Details
#initialize(model) ⇒ Runtime
Returns a new instance of Runtime.
6 7 8 9 10 11 12 |
# File 'lib/sfpagent/runtime.rb', line 6 def initialize(model) @mutex_procedure = Mutex.new @mutex_get_state = Mutex.new @root = nil @cloudfinder = Sfp::Helper::CloudFinder.new set_model(model) end |
Instance Attribute Details
#cloudfinder ⇒ Object (readonly)
Returns the value of attribute cloudfinder.
4 5 6 |
# File 'lib/sfpagent/runtime.rb', line 4 def cloudfinder @cloudfinder end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/sfpagent/runtime.rb', line 4 def model @model end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
4 5 6 |
# File 'lib/sfpagent/runtime.rb', line 4 def root @root end |
Instance Method Details
#execute_action(action) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sfpagent/runtime.rb', line 19 def execute_action(action) return false if !defined?(@root) or @root.nil? def normalise_parameters(params) p = {} params.each { |k,v| p[k[2,k.length-2]] = v } p end module_path, method_name = action['name'].pop_ref mod = @root.at?(module_path)[:_self] raise Exception, "Module #{module_path} cannot be found!" if mod.nil? raise Exception, "Cannot execute #{action['name']}!" if not mod.respond_to?(method_name) params = normalise_parameters(action['parameters']) if mod.synchronized.rindex(method_name) @mutex_procedure.synchronize { mod.send method_name.to_sym, params } else mod.send method_name.to_sym, params end # TODO - check post-execution state for verification end |
#get_state(as_sfp = false) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/sfpagent/runtime.rb', line 59 def get_state(as_sfp=false) @mutex_get_state.synchronize { update_state(@root) get_object_state(@root, @model) } end |
#normalise_parameters(params) ⇒ Object
22 23 24 25 26 |
# File 'lib/sfpagent/runtime.rb', line 22 def normalise_parameters(params) p = {} params.each { |k,v| p[k[2,k.length-2]] = v } p end |
#set_model(model) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sfpagent/runtime.rb', line 43 def set_model(model) @mutex_get_state.synchronize { @model = model if @model.is_a?(Hash) root_model = Sfp::Helper.deep_clone(@model) root_model.accept(SFPtoRubyValueConverter) root_model.accept(ParentEliminator) @root = update_model(root_model, root_model, '$') @root.accept(ParentGenerator) @cloudfinder.clouds = [] @model.accept(@cloudfinder.reset) end } end |
#whoami? ⇒ Boolean
14 15 16 17 |
# File 'lib/sfpagent/runtime.rb', line 14 def whoami? @model.each { |key,value| return key if key[0,1] != '_' and value['_context'] == 'object' } if !@model.nil? nil end |