Class: Nanite::Push

Inherits:
Packet show all
Defined in:
lib/nanite/packets.rb

Overview

packet that means a work push from mapper to actor node

type is a service name payload is arbitrary data that is transferred from mapper to actor

Options: from is sender identity token is a generated request id that mapper uses to identify replies selector is the selector used to route the request target is the target nanite for the request persistent signifies if this request should be saved to persistent storage by the AMQP broker

Constant Summary collapse

DEFAULT_OPTIONS =
{:selector => :least_loaded}

Instance Attribute Summary collapse

Attributes inherited from Packet

#size

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Packet

#id_to_s, #to_json

Constructor Details

#initialize(type, payload, size = nil, opts = {}) ⇒ Push

Returns a new instance of Push.



179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/nanite/packets.rb', line 179

def initialize(type, payload, size=nil, opts={})
  opts = DEFAULT_OPTIONS.merge(opts)
  @type       = type
  @payload    = payload
  @size       = size
  @from       = opts[:from]
  @token      = opts[:token]
  @selector   = opts[:selector]
  @target     = opts[:target]
  @persistent = opts[:persistent]
  @tags       = opts[:tags] || []
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



175
176
177
# File 'lib/nanite/packets.rb', line 175

def from
  @from
end

#payloadObject

Returns the value of attribute payload.



175
176
177
# File 'lib/nanite/packets.rb', line 175

def payload
  @payload
end

#persistentObject

Returns the value of attribute persistent.



175
176
177
# File 'lib/nanite/packets.rb', line 175

def persistent
  @persistent
end

#selectorObject

Returns the value of attribute selector.



175
176
177
# File 'lib/nanite/packets.rb', line 175

def selector
  @selector
end

#tagsObject

Returns the value of attribute tags.



175
176
177
# File 'lib/nanite/packets.rb', line 175

def tags
  @tags
end

#targetObject

Returns the value of attribute target.



175
176
177
# File 'lib/nanite/packets.rb', line 175

def target
  @target
end

#tokenObject

Returns the value of attribute token.



175
176
177
# File 'lib/nanite/packets.rb', line 175

def token
  @token
end

#typeObject

Returns the value of attribute type.



175
176
177
# File 'lib/nanite/packets.rb', line 175

def type
  @type
end

Class Method Details

.json_create(o) ⇒ Object



192
193
194
195
196
197
# File 'lib/nanite/packets.rb', line 192

def self.json_create(o)
  i = o['data']
  new(i['type'], i['payload'], o['size'], { :from       => i['from'],       :token  => i['token'],
                                            :selector   => i['selector'],   :target => i['target'],
                                            :persistent => i['persistent'], :tags   => i['tags'] })
end

Instance Method Details

#to_s(filter = nil) ⇒ Object



199
200
201
202
203
204
205
206
# File 'lib/nanite/packets.rb', line 199

def to_s(filter=nil)
  log_msg = "#{super} <#{token}> #{type}"
  log_msg += " from #{id_to_s(from)}" if filter.nil? || filter.include?(:from)
  log_msg += ", target #{id_to_s(target)}" if target && (filter.nil? || filter.include?(:target))
  log_msg += ", tags #{tags.inspect}" if tags && !tags.empty? && (filter.nil? || filter.include?(:tags))
  log_msg += ", payload #{payload.inspect}" if filter.nil? || filter.include?(:payload)
  log_msg
end