Class: Server::ModularHandler

Inherits:
SimpleChannelInboundHandler
  • Object
show all
Includes:
Listenable
Defined in:
lib/server/modular_handler.rb

Overview

The ModularHandler class notifies listeners about events.

Constant Summary collapse

IdentifierTemplate =
'#<%<class>s:0x%<id>s>'.freeze

Instance Method Summary collapse

Methods included from Listenable

#add_listener, #listeners, #notify, #remove_listener, #replace_listeners

Constructor Details

#initialize(channel_group) ⇒ ModularHandler

Returns a new instance of ModularHandler.



26
27
28
29
# File 'lib/server/modular_handler.rb', line 26

def initialize(channel_group)
  super()
  @channel_group = channel_group
end

Instance Method Details

#channelActive(ctx) ⇒ Object



47
48
49
50
51
52
# File 'lib/server/modular_handler.rb', line 47

def channelActive(ctx)
  ::Server.log.debug "##{__method__} channel: #{ctx.channel}"
  @channel_group.add(ctx.channel)
  notify :channel_active, ctx
  super(ctx)
end

#channelInactive(ctx) ⇒ Object



54
55
56
57
58
# File 'lib/server/modular_handler.rb', line 54

def channelInactive(ctx)
  log.trace "##{__method__} channel: #{ctx.channel}"
  notify :channel_inactive, ctx
  super(ctx)
end

#channelRead(ctx, msg) ⇒ Object



60
61
62
63
64
# File 'lib/server/modular_handler.rb', line 60

def channelRead(ctx, msg)
  log.trace "##{__method__} channel: #{ctx.channel}, message: #{msg.inspect}"
  notify :channel_read, ctx, msg
  super(ctx, msg)
end

#channelRead0(ctx, msg) ⇒ Object

Please keep in mind that this method will be renamed to messageReceived(ChannelHandlerContext, I) in 5.0.

java_signature ‘protected abstract void channelRead0(ChannelHandlerContext ctx, I msg) throws Exception’



70
71
72
73
74
# File 'lib/server/modular_handler.rb', line 70

def channelRead0(ctx, msg)
  log.trace "##{__method__} channel: #{ctx.channel}, message: #{msg.inspect}"
  messageReceived(ctx, msg)
  # super(ctx, msg)
end

#channelReadComplete(ctx) ⇒ Object



82
83
84
85
86
# File 'lib/server/modular_handler.rb', line 82

def channelReadComplete(ctx)
  log.trace "##{__method__} channel: #{ctx.channel}"
  notify :channel_read_complete, ctx
  super(ctx)
end

#channelRegistered(ctx) ⇒ Object



35
36
37
38
39
# File 'lib/server/modular_handler.rb', line 35

def channelRegistered(ctx)
  log.trace "##{__method__} channel: #{ctx.channel}"
  notify :channel_registered, ctx
  super(ctx)
end

#channelUnregistered(ctx) ⇒ Object



41
42
43
44
45
# File 'lib/server/modular_handler.rb', line 41

def channelUnregistered(ctx)
  log.trace "##{__method__} channel: #{ctx.channel}"
  notify :channel_unregistered, ctx
  super(ctx)
end

#channelWritabilityChanged(ctx) ⇒ Object



94
95
96
97
98
# File 'lib/server/modular_handler.rb', line 94

def channelWritabilityChanged(ctx)
  log.trace "##{__method__} channel: #{ctx.channel}"
  notify :channel_writability_changed, ctx
  super(ctx)
end

#exceptionCaught(ctx, cause) ⇒ Object



100
101
102
103
104
105
# File 'lib/server/modular_handler.rb', line 100

def exceptionCaught(ctx, cause)
  ::Server.log.warn "##{__method__} channel: #{ctx.channel}, cause: #{cause.message}"
  cause.backtrace.each { |t| ::Server.log.error t }
  listeners = notify :exception_caught, ctx, cause
  super(ctx, cause) if listeners.nil? || listeners.empty?
end

#isSharableObject



31
32
33
# File 'lib/server/modular_handler.rb', line 31

def isSharable
  true
end

#messageReceived(ctx, msg) ⇒ Object



76
77
78
79
80
# File 'lib/server/modular_handler.rb', line 76

def messageReceived(ctx, msg)
  log.trace "##{__method__} channel: #{ctx.channel}, message: #{msg.inspect}"
  notify :message_received, ctx, msg
  # super(ctx, msg)
end

#to_sObject Also known as: inspect



109
110
111
# File 'lib/server/modular_handler.rb', line 109

def to_s
  format(IdentifierTemplate, class: self.class.name, id: object_id.to_s(16))
end

#userEventTriggered(ctx, evt) ⇒ Object



88
89
90
91
92
# File 'lib/server/modular_handler.rb', line 88

def userEventTriggered(ctx, evt)
  log.trace "##{__method__} channel: #{ctx.channel}, event: #{evt}"
  notify :user_event_triggered, ctx, evt
  super(ctx, evt)
end