Module: Client::InitializationMethods

Included in:
TCP::Client
Defined in:
lib/client.rb

Overview

The InitializationMethods module

Instance Method Summary collapse

Instance Method Details

#bootstrapObject



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_initializerObject



68
69
70
# File 'lib/client.rb', line 68

def channel_initializer
  @channel_initializer ||= ::Client::ChannelInitializer.new(@options)
end

#client_groupObject



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)
  @options = options
  @host = @options[:host]
  @port = @options[:port]
  @queue = java.util.concurrent.LinkedBlockingQueue.new
end

#logging_handlerObject



72
73
74
# File 'lib/client.rb', line 72

def logging_handler
  @logging_handler ||= LoggingHandler.new(LogLevel::INFO)
end