class Server

Public Class Methods

new(connect_string, options = {}) click to toggle source
# File lib/thrift_client/server.rb, line 3
def initialize(connect_string, options = {})
  @active = false
  @host, @port = parse_connect_string(connect_string)
  @options = options
  pool_class = nil
  if @options[:transport] == Thrift::EventMachineTransport
    require "thrift_client/pool/fiber_connection_pool"
    pool_class = FiberConnectionPool
  else
    require "thrift_client/pool/thread_connection_pool"
    pool_class = ThreadConnectionPool
  end
  @connection_pool = pool_class.new(:size => @options[:size]){
    create_client
  }
  @active = true
end

Public Instance Methods

active?() click to toggle source
# File lib/thrift_client/server.rb, line 21
def active?
  @active
end
destroy() click to toggle source
# File lib/thrift_client/server.rb, line 25
def destroy
  @active = false
  @connection_pool.destroy
end
to_s() click to toggle source
# File lib/thrift_client/server.rb, line 39
def to_s
  "#{@host}:#{@port}"
end
with() { |connection| ... } click to toggle source
# File lib/thrift_client/server.rb, line 30
def with
  @connection_pool.execute { | connection |
    if connection == nil
      puts "fetal error, connection is nil"
    end
    yield connection
  }
end

Protected Instance Methods

create_client() click to toggle source
# File lib/thrift_client/server.rb, line 44
def create_client
  transport = @options[:transport].new(@host, @port, @options[:timeout])
  transport = @options[:transport_wrapper].new(transport) if @options[:transport_wrapper]
  protocol = @options[:protocol].new(transport)
  if @options[:multiplexed]
    protocol = Thrift::MultiplexedProtocol.new(protocol,@options[:client_class].name.split("::")[-2].downcase.gsub("service",""))
  end
  client = @options[:client_class].new(protocol)
  # client.connect
  client
end
parse_connect_string(connect_string) click to toggle source
# File lib/thrift_client/server.rb, line 56
def parse_connect_string(connect_string)
  host, port = connect_string.split(":")
  raise ArgumentError, 'Server must be in the format "host:port"' unless host and port
  [host, port]
end