Module: Telnet::ClientInitializationMethods

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

Overview

The ClientInitializationMethods module

Instance Method Summary collapse

Instance Method Details

#bootstrapObject



65
66
67
68
69
70
71
# File 'lib/telnet_client.rb', line 65

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



81
82
83
# File 'lib/telnet_client.rb', line 81

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

#client_groupObject



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

def client_group
  @client_group ||= NioEventLoopGroup.new
end

#configure_handlers(*handlers, &block) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/telnet_client.rb', line 85

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



58
59
60
61
62
63
# File 'lib/telnet_client.rb', line 58

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

#logging_handlerObject



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

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