Class: Server

Inherits:
Object
  • Object
show all
Defined in:
lib/thrift_client/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(connect_string, options = {}) ⇒ Server

Returns a new instance of Server.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/thrift_client/server.rb', line 21

def active?
  @active
end

#destroyObject



25
26
27
28
# File 'lib/thrift_client/server.rb', line 25

def destroy
  @active = false
  @connection_pool.destroy
end

#to_sObject



39
40
41
# File 'lib/thrift_client/server.rb', line 39

def to_s
  "#{@host}:#{@port}"
end

#withObject



30
31
32
33
34
35
36
37
# 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