Class: DRbDump::MessageResult

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

Overview

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

Instance Method Summary collapse

Methods inherited from Message

#destination, from_stream, #resolve_addresses, #source

Constructor Details

#initialize(drbdump, packet, status, stream) ⇒ MessageResult

Creates a new MessageResult for the creating drbdump instance. The last packet in the message is packet and the Marshal::Structure for the result type is status. The rest of the message will be loaded from stream.



12
13
14
15
16
17
18
19
20
21
# File 'lib/drbdump/message_result.rb', line 12

def initialize drbdump, packet, status, stream
  super drbdump, packet

  @result     = nil
  @status     = nil
  @stream     = stream

  @raw_result = @loader.load stream
  @raw_status = status
end

Instance Method Details

#allocationsObject

The number of allocations required to load the result.



26
27
28
# File 'lib/drbdump/message_result.rb', line 26

def allocations
  @raw_status.count_allocations + @raw_result.count_allocations
end

#displayObject

Prints the message information to standard output



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

def display
  update_statistics

  return if @drbdump.quiet

  message   = status ? 'success' : 'exception'
  arrow     = status ? "\u21d0"  : "\u2902"
  timestamp = self.timestamp.strftime DRbDump::TIMESTAMP_FORMAT

  puts "%s %s %s %s %s: %s" % [
    timestamp, destination, arrow, source, message, result
  ]
end

#resultObject

The loaded result object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/drbdump/message_result.rb', line 50

def result
  return @result if @result

  result = @drbdump.load_marshal_data @raw_result

  @result = if DRb::DRbObject === result then
             "(\"druby://#{result.__drburi}\", #{result.__drbref})"
           else
             result.inspect
           end
end

#statusObject

The loaded status object



65
66
67
# File 'lib/drbdump/message_result.rb', line 65

def status
  @status ||= @raw_status.load
end

#timestampObject

The timestamp of the last packet in the result



72
73
74
# File 'lib/drbdump/message_result.rb', line 72

def timestamp
  @packet.timestamp
end

#update_statisticsObject

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



79
80
81
# File 'lib/drbdump/message_result.rb', line 79

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