Class Qpid::Messaging::Duration
In: qpid/ruby/lib/qpid_messaging/duration.rb
Parent: Object

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.

Methods

*   milliseconds   new  

Public Class methods

Creates a Duration with the specified length, in milliseconds.

Options

Examples

  # creates a duration of 15 seconds
  # REMEMBER: Duration deals in milliseconds
  delay = Qpid::Messaging::Duration.new 15000

Public Instance methods

Multiplies the duration of the Duration and returns a new instance.

Raises exceptions on a negative factor. Returns Qpid::Messaging::Duration::IMMEDIATE when the factor is 0.

Examples

  # return a duration that is 2 minutes (120,000 ms)
  twominutes = Qpid::Messaging::Duration::MINUTE * 2

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

[Validate]