Class: Qpid::Messaging::Duration
- Inherits:
-
Object
- Object
- Qpid::Messaging::Duration
- Defined in:
- lib/qpid_messaging/duration.rb
Overview
A Duration represents a period of time in milliseconds
Named Durations
The following named Durations
are available as symbols:
- FOREVER
-
The maximum integer value for the platform. Effectively this will wait forever.
- IMMEDIATE
-
An alias for 0 milliseconds.
- SECOND
-
An alias for 1,000 milliseconds.
- MINUTE
-
And alias for 60,000 millisecons.
Class Method Summary collapse
-
.add_item(key, value) ⇒ Object
:nodoc:.
-
.const_missing(key) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#*(factor) ⇒ Object
Multiplies the duration of the
Duration
and returns a new instance. -
#duration_impl ⇒ Object
:nodoc:.
-
#initialize(length) ⇒ Duration
constructor
Creates a Duration with the specified length, in milliseconds.
-
#milliseconds ⇒ Object
Returns the period of time in
milliseconds
.
Constructor Details
Class Method Details
.add_item(key, value) ⇒ Object
:nodoc:
109 110 111 112 |
# File 'lib/qpid_messaging/duration.rb', line 109 def self.add_item(key, value) # :nodoc: @hash ||= {} @hash[key] = Duration.new value end |
.const_missing(key) ⇒ Object
:nodoc:
114 115 116 |
# File 'lib/qpid_messaging/duration.rb', line 114 def self.const_missing(key) # :nodoc: @hash[key] end |
Instance Method Details
#*(factor) ⇒ Object
103 104 105 106 107 |
# File 'lib/qpid_messaging/duration.rb', line 103 def *(factor) raise TypeError.new "Factors must be non-zero positive values" if factor < 0 return Qpid::Messaging::Duration::IMMEDIATE if factor.zero? Qpid::Messaging::Duration.new((self.milliseconds * factor).floor) end |
#duration_impl ⇒ Object
:nodoc:
61 62 63 |
# File 'lib/qpid_messaging/duration.rb', line 61 def duration_impl # :nodoc: @duration_impl end |
#milliseconds ⇒ Object
Returns the period of time in milliseconds
.
Examples
# doubling growth in waiting for messages in a loop
do loop
set the base duration waiting length
timeout = Qpid::Messaging::Duration::SECOND
msg = nil
# loop until we receive a message
while msg.nil?
puts "Waiting #{timeout.milliseconds}ms"
msg = recv.get timeout
# if nothing was received, double the duration
if msg.nil?
# double out timeout
timeout = timeout * 2
else
# do something with the message
puts "Received: #{msg.content}"
end
end
end
89 90 91 |
# File 'lib/qpid_messaging/duration.rb', line 89 def milliseconds @duration_impl.getMilliseconds end |