class Thrift::ThreadPoolServer
Public Class Methods
Source
# File lib/thrift/server/thread_pool_server.rb 25 def initialize(processor, server_transport, transport_factory = nil, protocol_factory = nil, num = 20) 26 super(processor, server_transport, transport_factory, protocol_factory) 27 @thread_q = SizedQueue.new(num) 28 @exception_q = Queue.new 29 @running = false 30 end
Calls superclass method
Thrift::BaseServer::new
Public Instance Methods
Source
# File lib/thrift/server/thread_pool_server.rb 35 def rescuable_serve 36 Thread.new { serve } unless @running 37 @running = true 38 raise @exception_q.pop 39 end
exceptions that happen in worker threads will be relayed here and must be caught. ‘retry’ can be used to continue. (threads will continue to run while the exception is being handled.)
Source
# File lib/thrift/server/thread_pool_server.rb 43 def serve 44 @server_transport.listen 45 46 begin 47 loop do 48 @thread_q.push(:token) 49 Thread.new do 50 loop do 51 begin 52 client = @server_transport.accept 53 rescue => e 54 next if defined?(OpenSSL::SSL::SSLError) && e.is_a?(OpenSSL::SSL::SSLError) 55 raise 56 end 57 trans = @transport_factory.get_transport(client) 58 prot = @protocol_factory.get_protocol(trans) 59 begin 60 loop do 61 @processor.process(prot, prot) 62 end 63 rescue Thrift::TransportException, Thrift::ProtocolException 64 ensure 65 trans.close 66 end 67 end 68 rescue => e 69 @exception_q.push(e) 70 ensure 71 @thread_q.pop # thread died! 72 end 73 end 74 ensure 75 @server_transport.close 76 end 77 end
exceptions that happen in worker threads simply cause that thread to die and another to be spawned in its place.
Source
# File lib/thrift/server/thread_pool_server.rb 79 def to_s 80 "threadpool(#{super})" 81 end