class ThriftHelpers::Server

Public Class Methods

new(connection_string, cached = true) click to toggle source
# File lib/thrift_client/server.rb, line 7
def initialize(connection_string, cached = true)
  @connection_string = connection_string
  @connection = nil
  @cached = cached
  @marked_down_til = nil
end

Public Instance Methods

close(teardown = false) click to toggle source
# File lib/thrift_client/server.rb, line 52
def close(teardown = false)
  if teardown || !@cached
    @connection.close rescue nil #TODO
    @connection = nil
  end
end
down?() click to toggle source
# File lib/thrift_client/server.rb, line 23
def down?
  @marked_down_til && @marked_down_til > Time.now
end
mark_down!(til) click to toggle source
# File lib/thrift_client/server.rb, line 14
def mark_down!(til)
  close(true)
  @marked_down_til = Time.now + til
end
open(trans, wrap, conn_timeout, trans_timeout) click to toggle source
# File lib/thrift_client/server.rb, line 31
def open(trans, wrap, conn_timeout, trans_timeout)
  if down?
    raise ServerMarkedDown, "marked down until #{@marked_down_til}"
  end

  if @connection.nil? || (@cached && !@connection.open?)
    @connection = Connection::Factory.create(trans, wrap, @connection_string, conn_timeout)
    @connection.connect!
  end

  if wrap || trans.respond_to?(:timeout=)
    timeout = trans_timeout
  end

  self
end
open?() click to toggle source
# File lib/thrift_client/server.rb, line 48
def open?
  @connection && @connection.open?
end
to_s() click to toggle source
# File lib/thrift_client/server.rb, line 27
def to_s
  @connection_string
end
transport() click to toggle source
# File lib/thrift_client/server.rb, line 59
def transport
  return nil unless @connection
  @connection.transport
end
up?() click to toggle source
# File lib/thrift_client/server.rb, line 19
def up?
  !down?
end