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::PACKET_SIZE_REGEXP, 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



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

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.



418
419
420
# File 'lib/right_agent/packets.rb', line 418

def confirm
  @confirm
end

#expires_atObject

Returns the value of attribute expires_at.



418
419
420
# File 'lib/right_agent/packets.rb', line 418

def expires_at
  @expires_at
end

#fromObject

Returns the value of attribute from.



418
419
420
# File 'lib/right_agent/packets.rb', line 418

def from
  @from
end

#payloadObject

Returns the value of attribute payload.



418
419
420
# File 'lib/right_agent/packets.rb', line 418

def payload
  @payload
end

#persistentObject

Returns the value of attribute persistent.



418
419
420
# File 'lib/right_agent/packets.rb', line 418

def persistent
  @persistent
end

#scopeObject

Returns the value of attribute scope.



418
419
420
# File 'lib/right_agent/packets.rb', line 418

def scope
  @scope
end

#selectorObject

Returns the value of attribute selector.



418
419
420
# File 'lib/right_agent/packets.rb', line 418

def selector
  @selector
end

#tagsObject

Returns the value of attribute tags.



418
419
420
# File 'lib/right_agent/packets.rb', line 418

def tags
  @tags
end

#targetObject

Returns the value of attribute target.



418
419
420
# File 'lib/right_agent/packets.rb', line 418

def target
  @target
end

#tokenObject

Returns the value of attribute token.



418
419
420
# File 'lib/right_agent/packets.rb', line 418

def token
  @token
end

#typeObject

Returns the value of attribute type.



418
419
420
# File 'lib/right_agent/packets.rb', line 418

def type
  @type
end

Class Method Details

.create(o) ⇒ Object

Create packet from unmarshalled data

Parameters

o(Hash)

Unmarshalled data

Return

(Push)

New packet



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

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)


466
467
468
# File 'lib/right_agent/packets.rb', line 466

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

#target_for_encryptionObject

Get target to be used for encrypting the packet

Return

(String)

Target



522
523
524
# File 'lib/right_agent/packets.rb', line 522

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



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

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



475
476
477
# File 'lib/right_agent/packets.rb', line 475

def tries
  []
end