Class: RightScale::Result

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

Overview

Packet for a work result notification sent from actor node

Constant Summary

Constants inherited from Packet

Packet::DEFAULT_VERSION, Packet::GLOBAL, Packet::NOT_SERIALIZED, Packet::PACKET_SIZE_REGEXP, Packet::VERSION

Instance Attribute Summary collapse

Attributes inherited from Packet

#received_at, #size

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Packet

compatible, #enough_precision, #id_to_s, #ids_to_s, json_create, msgpack_create, #name, #one_way, #recv_version, #send_version, #send_version=, #to_json, #to_msgpack, #trace

Constructor Details

#initialize(token, to, results, from, request_from = nil, tries = nil, persistent = nil, duration = nil, version = [VERSION, VERSION], size = nil) ⇒ Result

Create packet

Parameters

token(String)

Generated request id that a router uses to identify replies

to(String)

Identity of the node to which result should be delivered

results(Any)

Arbitrary data that is transferred from actor, a result of actor’s work

from(String)

Sender identity

request_from(String)

Identity of the agent that sent the original request

tries(Array)

List of tokens for previous attempts to send associated request

persistent(Boolean)

Indicates if this result should be saved to persistent storage

by the AMQP broker
duration(Float)

Number of seconds required to produce the result

version(Array)

Protocol version of the original creator of the packet followed by the

protocol version of the packet contents to be used when sending
size(Integer)

Size of request in bytes used only for marshalling



554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/right_agent/packets.rb', line 554

def initialize(token, to, results, from, request_from = nil, tries = nil, persistent = nil, duration = nil,
               version = [VERSION, VERSION], size = nil)
  @token        = token
  @to           = to
  @results      = results
  @from         = from
  @request_from = request_from
  @tries        = tries || []
  @persistent   = persistent
  @duration     = duration
  @version      = version
  @size         = size
end

Instance Attribute Details

#durationObject

Returns the value of attribute duration.



537
538
539
# File 'lib/right_agent/packets.rb', line 537

def duration
  @duration
end

#fromObject

Returns the value of attribute from.



537
538
539
# File 'lib/right_agent/packets.rb', line 537

def from
  @from
end

#persistentObject

Returns the value of attribute persistent.



537
538
539
# File 'lib/right_agent/packets.rb', line 537

def persistent
  @persistent
end

#request_fromObject

Returns the value of attribute request_from.



537
538
539
# File 'lib/right_agent/packets.rb', line 537

def request_from
  @request_from
end

#resultsObject

Returns the value of attribute results.



537
538
539
# File 'lib/right_agent/packets.rb', line 537

def results
  @results
end

#toObject

Returns the value of attribute to.



537
538
539
# File 'lib/right_agent/packets.rb', line 537

def to
  @to
end

#tokenObject

Returns the value of attribute token.



537
538
539
# File 'lib/right_agent/packets.rb', line 537

def token
  @token
end

#triesObject

Returns the value of attribute tries.



537
538
539
# File 'lib/right_agent/packets.rb', line 537

def tries
  @tries
end

Class Method Details

.create(o) ⇒ Object

Create packet from unmarshalled data

Parameters

o(Hash)

Unmarshalled data

Return

(Result)

New packet



575
576
577
578
579
580
# File 'lib/right_agent/packets.rb', line 575

def self.create(o)
  i = o['data']
  new(i['token'], self.compatible(i['to']), i['results'], self.compatible(i['from']),
      self.compatible(i['request_from']), i['tries'], i['persistent'], i['duration'],
      i['version'] || [DEFAULT_VERSION, DEFAULT_VERSION], o['size'])
end

Instance Method Details

#target_for_encryptionObject

Get target to be used for encrypting the packet

Return

(String)

Target



626
627
628
# File 'lib/right_agent/packets.rb', line 626

def target_for_encryption
  @to
end

#to_s(filter = nil, version = nil) ⇒ Object

Generate log representation

Parameters

filter(Array(Symbol))

Attributes to be included in output

version(Symbol|nil)

Version to display: :recv_version, :send_version, or nil meaning none

Return

log_msg(String)

Log representation



590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
# File 'lib/right_agent/packets.rb', line 590

def to_s(filter = nil, version = nil)
  log_msg = "#{super(filter, version)} #{trace}"
  log_msg += " from #{id_to_s(@from)}" if filter.nil? || filter.include?(:from)
  log_msg += " to #{id_to_s(@to)}" if filter.nil? || filter.include?(:to)
  log_msg += ", request_from #{id_to_s(@request_from)}" if @request_from && (filter.nil? || filter.include?(:request_from))
  log_msg += ", persistent" if @persistent && (filter.nil? || filter.include?(:persistent))
  log_msg += ", tries #{tries_to_s}" if @tries && !@tries.empty? && (filter.nil? || filter.include?(:tries))
  if filter.nil? || !filter.include?(:results)
    if !@results.nil?
      if @results.is_a?(RightScale::OperationResult)   # Will be true when logging a 'SEND'
        res = @results
      elsif @results.is_a?(Hash) && @results.size == 1 # Will be true when logging a 'RECV' for version 9 or below
        res = @results.values.first
      end
      log_msg += " #{res.to_s}" if res
    end
  else
    log_msg += " results #{@results.inspect}"
  end
  log_msg
end

#tries_to_sObject

Convert tries list to string representation

Return

log_msg(String)

Tries list



616
617
618
619
620
# File 'lib/right_agent/packets.rb', line 616

def tries_to_s
  log_msg = ""
  @tries.each { |r| log_msg += "<#{r}>, " }
  log_msg = log_msg[0..-3] if log_msg.size > 1
end