module OmfEc

Copyright © 2012 National ICT Australia Limited (NICTA). This software may be used and distributed solely under the terms of the MIT license (License). You should find a copy of the License in LICENSE.TXT or at opensource.org/licenses/MIT. By downloading or using this software you accept the terms and the liability disclaimer in the License.

Copyright © 2012 National ICT Australia Limited (NICTA). This software may be used and distributed solely under the terms of the MIT license (License). You should find a copy of the License in LICENSE.TXT or at opensource.org/licenses/MIT. By downloading or using this software you accept the terms and the liability disclaimer in the License.

Copyright © 2012 National ICT Australia Limited (NICTA). This software may be used and distributed solely under the terms of the MIT license (License). You should find a copy of the License in LICENSE.TXT or at opensource.org/licenses/MIT. By downloading or using this software you accept the terms and the liability disclaimer in the License.

Copyright © 2006-2009 National ICT Australia (NICTA), Australia This software may be used and distributed solely under the terms of the MIT license (License). You should find a copy of the License in LICENSE.TXT or at opensource.org/licenses/MIT. By downloading or using this software you accept the terms and the liability disclaimer in the License.

Copyright © 2004-2009 WINLAB, Rutgers University, USA

Copyright © 2006-2009 National ICT Australia (NICTA), Australia

Copyright © 2004-2009 WINLAB, Rutgers University, USA

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Constants

VERSION

Public Class Methods

exp()
Alias for: experiment
experiment() click to toggle source

Experiment instance

@return [OmfEc::Experiment]

# File lib/omf_ec.rb, line 37
def experiment
  Experiment.instance
end
Also aliased as: exp
lib_root() click to toggle source

Full path of lib directory

# File lib/omf_ec.rb, line 44
def lib_root
  File.expand_path("../..", "#{__FILE__}/lib")
end
register_default_callback(topic) click to toggle source
# File lib/omf_ec.rb, line 48
def register_default_callback(topic)
  topic.on_inform do |msg|
    OmfEc::MPReceived.inject(Time.now.to_f, topic.id, msg.mid) if OmfCommon::Measure.enabled?
    case msg.itype.upcase
    when 'CREATION.FAILED'
      warn "RC reports creation.failed: '#{msg[:reason]}'", msg.src
      debug msg, msg.src
    when 'ERROR'
      warn "RC reports error: '#{msg[:reason]}'", msg.src
      debug msg, msg.src
    when 'WARN'
      warn "RC reports warning: '#{msg[:reason]}'", msg.src
      debug msg, msg.src
    when 'CREATION.OK'
      debug "Resource #{msg[:res_id]} created"
      debug "Received CREATION.OK via #{topic.id}"
      debug msg, msg.src

      OmfEc.experiment.add_or_update_resource_state(msg.resource_address, msg.properties)
      OmfEc.experiment.process_events
    when 'STATUS'
      props = []
      msg.each_property { |k, v| props << "#{k}: #{v}" }
      #debug "Received INFORM via #{topic.id} >> #{props.join(", ")}", msg.src

      if msg[:status_type] == 'APP_EVENT'
        info "APP_EVENT #{msg[:event]} from app #{msg[:app]} - msg: #{msg[:msg]}"
      end

      OmfEc.experiment.add_or_update_resource_state(msg.src, msg.properties)
      #OmfEc.experiment.process_events
    end
  end
end
subscribe_and_monitor(topic_id, context_obj = nil, &block) click to toggle source

TODO: Could we find a better name for this method?

# File lib/omf_ec.rb, line 84
def subscribe_and_monitor(topic_id, context_obj = nil, &block)
  topic = OmfCommon::Comm::Topic[topic_id]
  if topic.nil?
    OmfCommon.comm.subscribe(topic_id, routing_key: "o.info") do |topic|
      if topic.error?
        error "Failed to subscribe #{topic_id}"
      else
        debug "Subscribed to #{topic_id}"
        context_obj.associate_topic(topic) if context_obj
        block.call(context_obj || topic) if block
        register_default_callback(topic)
      end
    end
  else
    context_obj.associate_topic(topic) if context_obj
    block.call(context_obj || topic) if block
  end
end