Class: DRbDump::MessageSend

Inherits:
Message
  • Object
show all
Defined in:
lib/drbdump/message_send.rb

Overview

Wraps a DRb message-send after consuming it from a stream.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Message

#destination, from_stream, #resolve_addresses, #source

Constructor Details

#initialize(drbdump, packet, receiver, stream) ⇒ MessageSend

Creates a new MessageSend for the creating drbdump instance. The last packet in the message is packet and the Marshal::Structure for the first argument is receiver. The rest of the message will be loaded from stream.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/drbdump/message_send.rb', line 32

def initialize drbdump, packet, receiver, stream
  super drbdump, packet

  @argc         = nil
  @argv         = nil
  @block        = nil
  @message      = nil
  @raw_receiver = receiver
  @stream       = stream

  load_message if stream
end

Instance Attribute Details

#argcObject (readonly)

The number of arguments, not including the block



9
10
11
# File 'lib/drbdump/message_send.rb', line 9

def argc
  @argc
end

#raw_argvObject (readonly)

The arguments, each as a Marshal::Structure



14
15
16
# File 'lib/drbdump/message_send.rb', line 14

def raw_argv
  @raw_argv
end

#raw_blockObject (readonly)

The block as a Marshal::Structure



19
20
21
# File 'lib/drbdump/message_send.rb', line 19

def raw_block
  @raw_block
end

#raw_messageObject (readonly)

The message sent as a Marshal::Structure



24
25
26
# File 'lib/drbdump/message_send.rb', line 24

def raw_message
  @raw_message
end

Instance Method Details

#allocationsObject

The number of allocations required to load the message.



48
49
50
51
52
53
54
55
56
57
# File 'lib/drbdump/message_send.rb', line 48

def allocations
  allocations = 0

  allocations += @raw_receiver.count_allocations
  allocations += @raw_message.count_allocations
  @raw_argv.each { |arg| allocations += arg.count_allocations }
  allocations += @raw_block.count_allocations

  allocations
end

#argument_countObject

Number of arguments including the block



71
72
73
# File 'lib/drbdump/message_send.rb', line 71

def argument_count
  @argc + (block ? 1 : 0)
end

#argumentsObject

A string containing all loaded arguments including the block.



62
63
64
65
66
# File 'lib/drbdump/message_send.rb', line 62

def arguments
  arguments = argv.map { |obj| obj.inspect }
  (arguments << '&block') if block
  arguments.join ', '
end

#argvObject

The loaded arguments



78
79
80
# File 'lib/drbdump/message_send.rb', line 78

def argv
  @argv ||= @raw_argv.map { |obj| @drbdump.load_marshal_data obj }
end

#blockObject

The loaded block



85
86
87
# File 'lib/drbdump/message_send.rb', line 85

def block
  @block ||= @raw_block.load
end

#displayObject

Prints the message information to standard output



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/drbdump/message_send.rb', line 92

def display
  update_statistics

  return if @drbdump.quiet

  timestamp = self.timestamp.strftime DRbDump::TIMESTAMP_FORMAT

  puts "%s %s \u21d2 (%s, %p).%s(%s)" % [
    timestamp, source, destination, receiver, message, arguments
  ]
end

#load_messageObject

Returns the message, arguments and block for the DRb message-send in stream.



108
109
110
111
112
113
# File 'lib/drbdump/message_send.rb', line 108

def load_message # :nodoc:
  @raw_message = @loader.load @stream
  @argc        = @loader.load(@stream).load
  @raw_argv    = @argc.times.map { @loader.load @stream }
  @raw_block   = @loader.load @stream
end

#messageObject

The loaded message



118
119
120
# File 'lib/drbdump/message_send.rb', line 118

def message
  @message ||= @raw_message.load
end

#receiverObject

The loaded receiver for the message



125
126
127
# File 'lib/drbdump/message_send.rb', line 125

def receiver
  @receiver ||= @raw_receiver.load
end

#timestampObject

Returns the timestamp for the first packet in the incomplete stream for packet or the packet’s timestamp if this is the only packet in the stream.



134
135
136
# File 'lib/drbdump/message_send.rb', line 134

def timestamp
  @drbdump.incomplete_timestamps.delete(@packet.source) || @packet.timestamp
end

#update_statisticsObject

Updates the drbdump’s statistics with information from this message.



141
142
143
# File 'lib/drbdump/message_send.rb', line 141

def update_statistics # :nodoc:
  @statistics.add_message_send self
end