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



549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'lib/right_agent/packets.rb', line 549

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.



532
533
534
# File 'lib/right_agent/packets.rb', line 532

def duration
  @duration
end

#fromObject

Returns the value of attribute from.



532
533
534
# File 'lib/right_agent/packets.rb', line 532

def from
  @from
end

#persistentObject

Returns the value of attribute persistent.



532
533
534
# File 'lib/right_agent/packets.rb', line 532

def persistent
  @persistent
end

#request_fromObject

Returns the value of attribute request_from.



532
533
534
# File 'lib/right_agent/packets.rb', line 532

def request_from
  @request_from
end

#resultsObject

Returns the value of attribute results.



532
533
534
# File 'lib/right_agent/packets.rb', line 532

def results
  @results
end

#toObject

Returns the value of attribute to.



532
533
534
# File 'lib/right_agent/packets.rb', line 532

def to
  @to
end

#tokenObject

Returns the value of attribute token.



532
533
534
# File 'lib/right_agent/packets.rb', line 532

def token
  @token
end

#triesObject

Returns the value of attribute tries.



532
533
534
# File 'lib/right_agent/packets.rb', line 532

def tries
  @tries
end

Class Method Details

.create(o) ⇒ Object

Create packet from unmarshalled data

Parameters

o(Hash)

Unmarshalled data

Return

(Result)

New packet



570
571
572
573
574
575
# File 'lib/right_agent/packets.rb', line 570

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



621
622
623
# File 'lib/right_agent/packets.rb', line 621

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



585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
# File 'lib/right_agent/packets.rb', line 585

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



611
612
613
614
615
# File 'lib/right_agent/packets.rb', line 611

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