Class: OMF::SFA::AM::AMLiaison
- Inherits:
-
Base::LObject
- Object
- Base::LObject
- OMF::SFA::AM::AMLiaison
- Includes:
- OmfCommon::DSL::Xmpp
- Defined in:
- lib/omf-sfa/am/am_liaison.rb
Overview
This class implements the AM Liaison
Instance Attribute Summary collapse
-
#comm ⇒ Object
Returns the value of attribute comm.
Instance Method Summary collapse
-
#enable_lease(lease, component) ⇒ Object
It will send the corresponding create messages to the components contained in the lease when the lease is about to start.
-
#initialize ⇒ AMLiaison
constructor
A new instance of AMLiaison.
Constructor Details
#initialize ⇒ AMLiaison
Returns a new instance of AMLiaison.
21 22 23 24 |
# File 'lib/omf-sfa/am/am_liaison.rb', line 21 def initialize #@comm = OmfCommon::Comm.new(:xmpp) #EM.next_tick { @comm.connect('am_liaison', 'pw', 'localhost') } end |
Instance Attribute Details
#comm ⇒ Object
Returns the value of attribute comm.
18 19 20 |
# File 'lib/omf-sfa/am/am_liaison.rb', line 18 def comm @comm end |
Instance Method Details
#enable_lease(lease, component) ⇒ Object
It will send the corresponding create messages to the components contained in the lease when the lease is about to start. At the end of the lease the corresponding release messages will be sent to the components.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/omf-sfa/am/am_liaison.rb', line 37 def enable_lease(lease, component) debug "enable_lease: lease: '#{lease.inspect}' component: '#{component.inspect}'" resource_topic = @comm.get_topic(component.name) raise UnknownResourceException.new "Cannot find resource's pubsub topic: '#{component.inspect}'" unless resource_topic msg = @comm. do || .property('name', component.name) .property('type', component.type) end msg.on_inform_created do || logger.info "Resource '#{.resource_id}' successfully created at #{Time.now}" created_topic = @comm.get_topic(.resource_id) # TODO: we need to define whether we ask for specific resource_id in the create # message or we let the resource_factory to pick one. We need to keep it synced # with the resource_id we have in the DB. resource_id = created_topic.id r_msg = @comm. { |m| m.element('resource_id', resource_id) } r_msg.on_inform_released do || logger.info "Resource (#{.resource_id}) released at #{Time.now}" end timer = EventMachine::Timer.new(lease[:valid_until] - Time.now) do r_msg.publish resource_topic.id @leases[lease].delete(component.id) @leases.delete(lease) if @leases[lease].empty? end @leases[lease][component.id] = {:end => timer} end timer = EventMachine::Timer.new(lease[:valid_from] - Time.now) do resource_topic.subscribe do # If subscribed, we publish a 'create' message msg.publish resource_topic.id end end @leases[lease] = {} unless @leases[lease] @leases[lease] = { component.id => {:start => timer} } end |