Class: Server::ChannelInitializer

Inherits:
Object
  • Object
show all
Defined in:
lib/server/channel_initializer.rb

Overview

The ChannelInitializer class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel_group, options = {}) ⇒ ChannelInitializer

Returns a new instance of ChannelInitializer.



36
37
38
39
40
41
42
43
# File 'lib/server/channel_initializer.rb', line 36

def initialize(channel_group, options = {})
  super()
  @channel_group = channel_group
  @options = options
  @user_handlers = options.fetch(:handlers, [])
  @decoder = StringDecoder.new
  @encoder = StringEncoder.new
end

Instance Attribute Details

#decoderObject

Returns the value of attribute decoder.



33
34
35
# File 'lib/server/channel_initializer.rb', line 33

def decoder
  @decoder
end

#encoderObject

Returns the value of attribute encoder.



33
34
35
# File 'lib/server/channel_initializer.rb', line 33

def encoder
  @encoder
end

#optionsObject (readonly)

Returns the value of attribute options.



34
35
36
# File 'lib/server/channel_initializer.rb', line 34

def options
  @options
end

#user_handlersObject

Returns the value of attribute user_handlers.



33
34
35
# File 'lib/server/channel_initializer.rb', line 33

def user_handlers
  @user_handlers
end

Instance Method Details

#<<(handler) ⇒ Object



45
46
47
# File 'lib/server/channel_initializer.rb', line 45

def <<(handler)
  @user_handlers << handler
end

#add_listener(*listener) ⇒ Object



65
66
67
# File 'lib/server/channel_initializer.rb', line 65

def add_listener(*listener)
  default_handler.add_listener(*listener)
end

#default_handlerObject



61
62
63
# File 'lib/server/channel_initializer.rb', line 61

def default_handler
  @default_handler ||= ::Server::ModularHandler.new(@channel_group)
end

#frame_decoderObject



57
58
59
# File 'lib/server/channel_initializer.rb', line 57

def frame_decoder
  DelimiterBasedFrameDecoder.new(@options[:max_frame_length], @options[:delimiter])
end

#initChannel(channel) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/server/channel_initializer.rb', line 49

def initChannel(channel)
  pipeline = channel.pipeline
  pipeline.addLast(ssl_handler(channel)) if @options[:ssl]
  pipeline.addLast(frame_decoder, @decoder, @encoder)
  add_user_handlers(pipeline)
  pipeline.addLast(default_handler)
end

#replace_listeners(*listener) ⇒ Object



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

def replace_listeners(*listener)
  default_handler.replace_listeners(*listener)
end