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
:skewed_by(Integer|nil):: Amount of skew already applied to expires_at in seconds
: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



448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/right_agent/packets.rb', line 448

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
  @skewed_by  = opts[:skewed_by] || 0
  @tags       = opts[:tags] || []
  @version    = version
  @size       = size
end

Instance Attribute Details

#confirmObject

Returns the value of attribute confirm.



421
422
423
# File 'lib/right_agent/packets.rb', line 421

def confirm
  @confirm
end

#expires_atObject

Returns the value of attribute expires_at.



421
422
423
# File 'lib/right_agent/packets.rb', line 421

def expires_at
  @expires_at
end

#fromObject

Returns the value of attribute from.



421
422
423
# File 'lib/right_agent/packets.rb', line 421

def from
  @from
end

#payloadObject

Returns the value of attribute payload.



421
422
423
# File 'lib/right_agent/packets.rb', line 421

def payload
  @payload
end

#persistentObject

Returns the value of attribute persistent.



421
422
423
# File 'lib/right_agent/packets.rb', line 421

def persistent
  @persistent
end

#scopeObject

Returns the value of attribute scope.



421
422
423
# File 'lib/right_agent/packets.rb', line 421

def scope
  @scope
end

#selectorObject

Returns the value of attribute selector.



421
422
423
# File 'lib/right_agent/packets.rb', line 421

def selector
  @selector
end

#skewed_byObject

Returns the value of attribute skewed_by.



421
422
423
# File 'lib/right_agent/packets.rb', line 421

def skewed_by
  @skewed_by
end

#tagsObject

Returns the value of attribute tags.



421
422
423
# File 'lib/right_agent/packets.rb', line 421

def tags
  @tags
end

#targetObject

Returns the value of attribute target.



421
422
423
# File 'lib/right_agent/packets.rb', line 421

def target
  @target
end

#tokenObject

Returns the value of attribute token.



421
422
423
# File 'lib/right_agent/packets.rb', line 421

def token
  @token
end

#typeObject

Returns the value of attribute type.



421
422
423
# File 'lib/right_agent/packets.rb', line 421

def type
  @type
end

Class Method Details

.create(o) ⇒ Object

Create packet from unmarshalled data

Parameters

o(Hash)

Unmarshalled data

Return

(Push)

New packet



491
492
493
494
495
496
497
498
499
# File 'lib/right_agent/packets.rb', line 491

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'],
                                 :skewed_by => i['skewed_by'],               :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)


471
472
473
# File 'lib/right_agent/packets.rb', line 471

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

#target_for_encryptionObject

Get target to be used for encrypting the packet

Return

(String)

Target



527
528
529
# File 'lib/right_agent/packets.rb', line 527

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



509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/right_agent/packets.rb', line 509

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



480
481
482
# File 'lib/right_agent/packets.rb', line 480

def tries
  []
end