Class: WiseOMF::Client::WiseGroup
- Inherits:
-
Object
- Object
- WiseOMF::Client::WiseGroup
- Defined in:
- lib/wise_omf/client.rb
Overview
The WiseGroup is the representation of an omf resource group which provides the ability to register callback for requests and configure messages. You should not create an instance of this group directly. This can cause unwanted side effects. The better way is to ask the ReservationManager (factory) for a group for a list of node urns.
Constant Summary collapse
- @@default_message_types =
Message types to call callbacks for
[:response, :inform]
Instance Attribute Summary collapse
-
#default_callback ⇒ Object
Returns the value of attribute default_callback.
-
#group ⇒ Object
Returns the value of attribute group.
-
#name ⇒ Object
Returns the value of attribute name.
-
#uid ⇒ Object
Returns the value of attribute uid.
Instance Method Summary collapse
-
#configure(property, value, &block) ⇒ Object
Send a configure message for the given property and callback.
-
#delete_callback(requestId) ⇒ Object
Method for deleting a callback from the callback cache.
-
#done ⇒ Object
Terminates this group (unsubscribes topic…).
-
#init_callback(&block) ⇒ Object
This method initializes the callback handler on the group topic.
-
#initialize(name, uid) ⇒ WiseGroup
constructor
Creates a new WiseGroup which handles an OmfEc::Group for the given name And connects the resource with the given uid.
-
#method_missing(name, *args, &block) ⇒ Object
This method translates calls to configure_xxx and request_xxx into proper FRCP messages (like in the OMF).
-
#request(property, &block) ⇒ Object
Send a request message for the given property and callback.
Constructor Details
#initialize(name, uid) ⇒ WiseGroup
Creates a new WiseGroup which handles an OmfEc::Group for the given name And connects the resource with the given uid. Speaking in OMF, the resource represented by the given uid becomes a member of the newly created Group. The WiseGroup encapsulates the OMF group and handles the proper registration of callbacks for configure and request messages.
However, you are free to use the OmfEc::Group directly, but it’s highly recommended to use a WiseGroup as helper.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/wise_omf/client.rb', line 56 def initialize(name, uid) @callback_cache = LRUCache.new(ttl: 30.minutes) @name = name @uid = uid group = OmfEc::Group.new(name) OmfEc.experiment.add_group(group) group.add_resource(uid) @group = group info "Finished intialization of WiseGroup (#{name})" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
This method translates calls to configure_xxx and request_xxx into proper FRCP messages (like in the OMF)
129 130 131 132 133 134 135 |
# File 'lib/wise_omf/client.rb', line 129 def method_missing(name, *args, &block) if name =~ /set_(.+)/ configure($1, args[0], &block) else request(name, &block) end end |
Instance Attribute Details
#default_callback ⇒ Object
Returns the value of attribute default_callback.
38 39 40 |
# File 'lib/wise_omf/client.rb', line 38 def default_callback @default_callback end |
#group ⇒ Object
Returns the value of attribute group.
38 39 40 |
# File 'lib/wise_omf/client.rb', line 38 def group @group end |
#name ⇒ Object
Returns the value of attribute name.
38 39 40 |
# File 'lib/wise_omf/client.rb', line 38 def name @name end |
#uid ⇒ Object
Returns the value of attribute uid.
38 39 40 |
# File 'lib/wise_omf/client.rb', line 38 def uid @uid end |
Instance Method Details
#configure(property, value, &block) ⇒ Object
Send a configure message for the given property and callback
116 117 118 119 120 121 122 |
# File 'lib/wise_omf/client.rb', line 116 def configure(property, value, &block) mid = WiseOMF::Client::ExperimentHelper. unless block.nil? @callback_cache.store(mid, block) end @group.topic.configure({property => {requestId: mid, value: value}}) end |
#delete_callback(requestId) ⇒ Object
Method for deleting a callback from the callback cache. After deleting the callback, it will not be called for messages arriving with the given requestId
141 142 143 |
# File 'lib/wise_omf/client.rb', line 141 def delete_callback(requestId) @callback_cache.delete(requestId) end |
#done ⇒ Object
Terminates this group (unsubscribes topic…)
146 147 148 |
# File 'lib/wise_omf/client.rb', line 146 def done self.group.topic.unsubscribe(:wise_group_callback_handler) end |
#init_callback(&block) ⇒ Object
This method initializes the callback handler on the group topic. The topic might be nil direct after the intialization.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/wise_omf/client.rb', line 71 def init_callback(&block) if @group.topic.nil? debug "Delaying callback creation for 1 seconds" OmfCommon.el.after(1) { init_callback(&block) } return end info "Setting message callback for WiseGroup (#{self.name})" @group.topic.(:wise_group_callback_handler) { |msg| rid = msg.content.properties.requestId if rid.nil? && @@default_message_types.include?(msg.content.type) self.default_callback.call(msg) unless self.default_callback.nil? else callback = @callback_cache.fetch(rid) unless callback.nil? callback.call(msg.content.properties) else if @@default_message_types.include? msg.content.type self.default_callback.call(msg) unless self.default_callback.nil? end end end } block.call(self) if block end |
#request(property, &block) ⇒ Object
Send a request message for the given property and callback
103 104 105 106 107 108 109 110 |
# File 'lib/wise_omf/client.rb', line 103 def request(property, &block) mid = WiseOMF::Client::ExperimentHelper. unless block.nil? @callback_cache.store(mid, block) end fail "Can't request topic here" if property.to_sym.eql? 'topic'.to_sym @group.topic.configure({property => mid}) end |