Class: Thrift::NonblockingServer::IOManager

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

Overview

:nodoc:

Defined Under Namespace

Classes: Worker

Constant Summary collapse

DEFAULT_BUFFER =
2**20

Instance Method Summary collapse

Constructor Details

#initialize(processor, server_transport, transport_factory, protocol_factory, num, logger) ⇒ IOManager

Returns a new instance of IOManager.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/thrift/server/nonblocking_server.rb', line 101

def initialize(processor, server_transport, transport_factory, protocol_factory, num, logger)
  @processor = processor
  @server_transport = server_transport
  @transport_factory = transport_factory
  @protocol_factory = protocol_factory
  @num_threads = num
  @logger = logger
  @connections = []
  @buffers = Hash.new { |h,k| h[k] = '' }
  @signal_queue = Queue.new
  @signal_pipes = IO.pipe
  @signal_pipes[1].sync = true
  @worker_queue = Queue.new
  @shutdown_queue = Queue.new
end

Instance Method Details

#add_connection(socket) ⇒ Object



117
118
119
# File 'lib/thrift/server/nonblocking_server.rb', line 117

def add_connection(socket)
  signal [:connection, socket]
end

#ensure_closedObject



139
140
141
142
# File 'lib/thrift/server/nonblocking_server.rb', line 139

def ensure_closed
  kill_worker_threads if @worker_threads
  @iom_thread.kill
end

#shutdown(timeout = 0) ⇒ Object



128
129
130
131
132
133
134
135
136
137
# File 'lib/thrift/server/nonblocking_server.rb', line 128

def shutdown(timeout = 0)
  @logger.debug "#{self} is shutting down workers"
  @worker_queue.clear
  @num_threads.times { @worker_queue.push [:shutdown] }
  signal [:shutdown, timeout]
  @shutdown_queue.pop
  @signal_pipes[0].close
  @signal_pipes[1].close
  @logger.debug "#{self} is shutting down, goodbye"
end

#spawnObject



121
122
123
124
125
126
# File 'lib/thrift/server/nonblocking_server.rb', line 121

def spawn
  @iom_thread = Thread.new do
    @logger.debug "Starting #{self}"
    run
  end
end