Module: Telnet::ClientInitializationMethods

Included in:
Client
Defined in:
lib/telnet_client.rb

Overview

The ClientInitializationMethods module

Instance Method Summary collapse

Instance Method Details

#bootstrapObject



61
62
63
64
65
66
67
# File 'lib/telnet_client.rb', line 61

def bootstrap
  @bootstrap = Bootstrap.new
  @bootstrap.group(client_group)
  @bootstrap.channel(::Telnet::CHANNEL_TYPE)
  @bootstrap.handler(logging_handler) if @options[:log_requests]
  @bootstrap.handler(channel_initializer)
end

#channel_initializerObject



77
78
79
# File 'lib/telnet_client.rb', line 77

def channel_initializer
  @channel_initializer ||= ::Telnet::ClientChannelInitializer.new(@host, @port, @options)
end

#client_groupObject



69
70
71
# File 'lib/telnet_client.rb', line 69

def client_group
  @client_group ||= NioEventLoopGroup.new
end

#configure_handlers(*handlers, &block) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/telnet_client.rb', line 81

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)
    else
      @user_app.call(ctx, msg)
    end
  end
end

#init(options) ⇒ Object



54
55
56
57
58
59
# File 'lib/telnet_client.rb', line 54

def init(options)
  @options = options
  @host = options[:host]
  @port = options[:port]
  @queue = java.util.concurrent.LinkedBlockingQueue.new
end

#logging_handlerObject



73
74
75
# File 'lib/telnet_client.rb', line 73

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