Module: Client::InitializationMethods
- Included in:
- TCP::Client
- Defined in:
- lib/tcp_server/client.rb
Overview
The InitializationMethods module
Instance Method Summary collapse
- #bootstrap ⇒ Object
- #channelizer ⇒ Object
- #client_group ⇒ Object
- #configure_handlers(*handlers, &block) ⇒ Object
- #init(options) ⇒ Object
- #logging_handler ⇒ Object
Instance Method Details
#bootstrap ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/tcp_server/client.rb', line 66 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 [:log_requests] @bootstrap.handler(channelizer) end |
#channelizer ⇒ Object
79 80 81 |
# File 'lib/tcp_server/client.rb', line 79 def channelizer @channelizer ||= ::Client::Channelizer.new() end |
#client_group ⇒ Object
75 76 77 |
# File 'lib/tcp_server/client.rb', line 75 def client_group @client_group ||= NioEventLoopGroup.new end |
#configure_handlers(*handlers, &block) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/tcp_server/client.rb', line 87 def configure_handlers(*handlers, &block) channelizer.default_handler.add_listener(self) channelizer.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
59 60 61 62 63 64 |
# File 'lib/tcp_server/client.rb', line 59 def init() = @host = [:host] @port = [:port] @queue = LinkedBlockingQueue.new end |
#logging_handler ⇒ Object
83 84 85 |
# File 'lib/tcp_server/client.rb', line 83 def logging_handler @logging_handler ||= LoggingHandler.new(LogLevel::INFO) end |