class Messagebus::Connection

Constants

STARTED
STOPPED

Attributes

host_params[RW]
options[RW]

Public Class Methods

new(host_params, passed_options = {}) click to toggle source
# File lib/messagebus/connection.rb, line 44
def initialize(host_params, passed_options = {})
  @host_params = host_params
  @host_params = [@host_params] unless @host_params.is_a?(Array)

  @options = DottableHash.new({
    :user => '', :passwd => '',
    :conn_lifetime_sec => 300, :receipt_wait_timeout_ms => 5000,
    :destination_name => nil, :destination_type => nil,
    :ack_type => Messagebus::ACK_TYPE_AUTO_CLIENT, :num_threads_per_server => 1,
    :enable_dynamic_serverlist_fetch => false, :dynamic_fetch_timeout_ms => 1000,
    :dynamic_serverlist_fetch_url_override => nil
  }).merge(passed_options)

  @state = STOPPED
end

Public Instance Methods

do_with_timeout(timeout_ms) { || ... } click to toggle source
# File lib/messagebus/connection.rb, line 68
def do_with_timeout(timeout_ms)
  if not block_given?
    raise "do_with_timeout expects a block to be run"
  end

  start_time = Time.now
  while (Time.now - start_time) * 1000 < timeout_ms
    yield
  end
end
host_params=(host_params) click to toggle source
# File lib/messagebus/connection.rb, line 105
def host_params=(host_params)
  @host_params = host_params
end
options=(options) click to toggle source
# File lib/messagebus/connection.rb, line 109
def options=(options)
  @options = options
end
start_server(host_params, user, passwd, subscription_id=nil) click to toggle source
# File lib/messagebus/connection.rb, line 79
def start_server(host_params, user, passwd, subscription_id=nil)
  case host_params
  when Array
    host_param = host_params[rand(host_params.length)]
  when String
    host_param = host_params
  end

  host, port = host_param.split(':')

  connect_headers = {}
  connect_headers.merge!("client-id" => subscription_id) if subscription_id

  stomp = Stomp::Client.new(user, passwd, host, port, logger,  connect_headers)
  logger.info "Started client for host_param:#{host_param} stomp-client:#{stomp} user:#{user}"
  @state = STARTED

  return stomp
end
started?() click to toggle source
# File lib/messagebus/connection.rb, line 60
def started?
  @state == STARTED
end
stop_server(stomp) click to toggle source
# File lib/messagebus/connection.rb, line 99
def stop_server(stomp)
  Client.logger.info "Stopping stomp-client:#{stomp}"
  stomp.close if stomp
  @state = STOPPED
end
stopped?() click to toggle source
# File lib/messagebus/connection.rb, line 64
def stopped?
  @state == STOPPED
end

Private Instance Methods

logger() click to toggle source
# File lib/messagebus/connection.rb, line 114
def logger
  @logger ||= Client.logger
end