Module: Client::InitializationMethods
- Included in:
- TCP::Client
- Defined in:
- lib/client.rb
Overview
The InitializationMethods module
Instance Method Summary collapse
- #bootstrap ⇒ Object
- #channel_initializer ⇒ Object
- #client_group ⇒ Object
- #configure_handlers(*handlers, &block) ⇒ Object
- #init(options) ⇒ Object
- #logging_handler ⇒ Object
Instance Method Details
#bootstrap ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/client.rb', line 55 def bootstrap @bootstrap = Bootstrap.new @bootstrap.group(client_group) @bootstrap.channel(::TCP::CHANNEL_TYPE) @bootstrap.option(ChannelOption::TCP_NODELAY, true) @bootstrap.handler(logging_handler) if @options[:log_requests] @bootstrap.handler(channel_initializer) end |
#channel_initializer ⇒ Object
68 69 70 |
# File 'lib/client.rb', line 68 def channel_initializer @channel_initializer ||= ::Client::ChannelInitializer.new(@options) end |
#client_group ⇒ Object
64 65 66 |
# File 'lib/client.rb', line 64 def client_group @client_group ||= NioEventLoopGroup.new end |
#configure_handlers(*handlers, &block) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/client.rb', line 76 def configure_handlers(*handlers, &block) channel_initializer.default_handler.add_listener(self) channel_initializer.default_handler.listeners.addAll(handlers) @user_app = block @application_handler = lambda do |ctx, msg| if @user_app.nil? || @user_app.arity == 1 @queue.add(msg.chomp) else @user_app.call(ctx, msg) end end end |
#init(options) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/client.rb', line 48 def init() @options = @host = @options[:host] @port = @options[:port] @queue = java.util.concurrent.LinkedBlockingQueue.new end |
#logging_handler ⇒ Object
72 73 74 |
# File 'lib/client.rb', line 72 def logging_handler @logging_handler ||= LoggingHandler.new(LogLevel::INFO) end |