Class: RightScale::Push

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

Overview

Packet for a work request for an actor node that has no result, i.e., one-way request

Constant Summary collapse

DEFAULT_OPTIONS =
{:selector => :any}

Constants inherited from Packet

RightScale::Packet::DEFAULT_VERSION, RightScale::Packet::GLOBAL, RightScale::Packet::NOT_SERIALIZED, RightScale::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(type, payload, opts = {}, version = [VERSION, VERSION], size = nil) ⇒ Push

Create packet

Parameters

type(String)

Dispatch route for the request

payload(Any)

Arbitrary data that is transferred to actor

opts(Hash)

Optional settings:

:from(String)

Sender identity

:scope(Hash)

Define behavior that should be used to resolve tag based routing

:token(String)

Generated request id that a router uses to identify replies

:selector(Symbol)

Selector used to route the request: :any or :all, defaults to :any

:target(String|Array)

Target recipient(s)

:persistent(Boolean)

Indicates if this request should be saved to persistent storage

  by the AMQP broker
:confirm(Boolean):: Whether require confirmation response from router containing targets
  to which request was published but not necessarily delivered
:expires_at(Integer|nil):: Time in seconds in Unix-epoch when this request expires and
   is to be ignored by the receiver; value 0 means never expire; defaults to 0
:tags(Array(Symbol)):: List of tags to be used for selecting target for this request
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



442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/right_agent/packets.rb', line 442

def initialize(type, payload, opts = {}, version = [VERSION, VERSION], size = nil)
  opts = DEFAULT_OPTIONS.merge(opts)
  @type       = type
  @payload    = payload
  @from       = opts[:from]
  @scope      = opts[:scope]
  @token      = opts[:token]
  @selector   = opts[:selector]
  @selector   = :any if ["least_loaded", "random"].include?(@selector.to_s)
  @target     = opts[:target]
  @persistent = opts[:persistent]
  @confirm    = opts[:confirm]
  @expires_at = opts[:expires_at] || 0
  @tags       = opts[:tags] || []
  @version    = version
  @size       = size
end

Instance Attribute Details

#confirmObject

Returns the value of attribute confirm.



416
417
418
# File 'lib/right_agent/packets.rb', line 416

def confirm
  @confirm
end

#expires_atObject

Returns the value of attribute expires_at.



416
417
418
# File 'lib/right_agent/packets.rb', line 416

def expires_at
  @expires_at
end

#fromObject

Returns the value of attribute from.



416
417
418
# File 'lib/right_agent/packets.rb', line 416

def from
  @from
end

#payloadObject

Returns the value of attribute payload.



416
417
418
# File 'lib/right_agent/packets.rb', line 416

def payload
  @payload
end

#persistentObject

Returns the value of attribute persistent.



416
417
418
# File 'lib/right_agent/packets.rb', line 416

def persistent
  @persistent
end

#scopeObject

Returns the value of attribute scope.



416
417
418
# File 'lib/right_agent/packets.rb', line 416

def scope
  @scope
end

#selectorObject

Returns the value of attribute selector.



416
417
418
# File 'lib/right_agent/packets.rb', line 416

def selector
  @selector
end

#tagsObject

Returns the value of attribute tags.



416
417
418
# File 'lib/right_agent/packets.rb', line 416

def tags
  @tags
end

#targetObject

Returns the value of attribute target.



416
417
418
# File 'lib/right_agent/packets.rb', line 416

def target
  @target
end

#tokenObject

Returns the value of attribute token.



416
417
418
# File 'lib/right_agent/packets.rb', line 416

def token
  @token
end

#typeObject

Returns the value of attribute type.



416
417
418
# File 'lib/right_agent/packets.rb', line 416

def type
  @type
end

Class Method Details

.create(o) ⇒ Object

Create packet from unmarshalled data

Parameters

o(Hash)

Unmarshalled data

Return

(Push)

New packet



484
485
486
487
488
489
490
491
492
# File 'lib/right_agent/packets.rb', line 484

def self.create(o)
  i = o['data']
  new(i['type'], i['payload'], { :from    => self.compatible(i['from']),   :scope      => i['scope'],
                                 :token   => i['token'],                   :selector   => i['selector'],
                                 :target  => self.compatible(i['target']), :persistent => i['persistent'],
                                 :confirm => i['confirm'],                 :expires_at => i['expires_at'],
                                 :tags    => i['tags']},
      i['version'] || [DEFAULT_VERSION, DEFAULT_VERSION], o['size'])
end

Instance Method Details

#fanout?Boolean

Test whether the request is being fanned out to multiple targets

Return

(Boolean)

true if is fanout, otherwise false

Returns:

  • (Boolean)


464
465
466
# File 'lib/right_agent/packets.rb', line 464

def fanout?
  @selector.to_s == 'all'
end

#target_for_encryptionObject

Get target to be used for encrypting the packet

Return

(String)

Target



520
521
522
# File 'lib/right_agent/packets.rb', line 520

def target_for_encryption
  @target
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



502
503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/right_agent/packets.rb', line 502

def to_s(filter = nil, version = nil)
  payload = PayloadFormatter.log(@type, @payload)
  log_msg = "#{super(filter, version)} #{trace} #{@type}"
  log_msg += " #{payload}" if payload
  log_msg += " from #{id_to_s(@from)}" if filter.nil? || filter.include?(:from)
  log_msg += ", target #{ids_to_s(@target)}" if @target && (filter.nil? || filter.include?(:target))
  log_msg += ", scope #{@scope.inspect}" if @scope && (filter.nil? || filter.include?(:scope))
  log_msg += ", fanout" if (filter.nil? || filter.include?(:fanout)) && fanout?
  log_msg += ", tags #{@tags.inspect}" if @tags && !@tags.empty? && (filter.nil? || filter.include?(:tags))
  log_msg += ", persistent" if @persistent && (filter.nil? || filter.include?(:persistent))
  log_msg += ", payload #{@payload.inspect}" if filter && filter.include?(:payload)
  log_msg
end

#triesObject

Keep interface consistent with Request packets A push never gets retried

Return

[]

Always return empty array



473
474
475
# File 'lib/right_agent/packets.rb', line 473

def tries
  []
end