Class: TcpServer::ModularHandler
- Inherits:
-
SimpleChannelInboundHandler
- Object
- SimpleChannelInboundHandler
- TcpServer::ModularHandler
show all
- Includes:
- Listenable
- Defined in:
- lib/tcp_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/tcp_server/modular_handler.rb', line 26
def initialize(channel_group)
super()
@channel_group = channel_group
end
|
Instance Method Details
#channelActive(ctx) ⇒ Object
51
52
53
54
55
56
|
# File 'lib/tcp_server/modular_handler.rb', line 51
def channelActive(ctx)
TcpServer.log.debug "#channelActive channel: #{ctx.channel}"
@channel_group.add(ctx.channel)
notify :channel_active, ctx
super
end
|
#channelInactive(ctx) ⇒ Object
58
59
60
61
62
|
# File 'lib/tcp_server/modular_handler.rb', line 58
def channelInactive(ctx)
log.trace "#channelInactive channel: #{ctx.channel}"
notify :channel_inactive, ctx
super
end
|
#channelRead(ctx, msg) ⇒ Object
64
65
66
67
68
|
# File 'lib/tcp_server/modular_handler.rb', line 64
def channelRead(ctx, msg)
log.trace "#channelRead channel: #{ctx.channel}, message: #{msg.inspect}"
notify :channel_read, ctx, msg
super
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'
74
75
76
77
78
|
# File 'lib/tcp_server/modular_handler.rb', line 74
def channelRead0(ctx, msg)
log.trace "#channelRead0 channel: #{ctx.channel}, message: #{msg.inspect}"
messageReceived(ctx, msg)
end
|
#channelReadComplete(ctx) ⇒ Object
86
87
88
89
90
|
# File 'lib/tcp_server/modular_handler.rb', line 86
def channelReadComplete(ctx)
log.trace "#channelReadComplete channel: #{ctx.channel}"
notify :channel_read_complete, ctx
super
end
|
#channelRegistered(ctx) ⇒ Object
rubocop: enable Naming/PredicateMethod
39
40
41
42
43
|
# File 'lib/tcp_server/modular_handler.rb', line 39
def channelRegistered(ctx)
log.trace "#channelRegistered channel: #{ctx.channel}"
notify :channel_registered, ctx
super
end
|
#channelUnregistered(ctx) ⇒ Object
45
46
47
48
49
|
# File 'lib/tcp_server/modular_handler.rb', line 45
def channelUnregistered(ctx)
log.trace "#channelUnregistered channel: #{ctx.channel}"
notify :channel_unregistered, ctx
super
end
|
#channelWritabilityChanged(ctx) ⇒ Object
98
99
100
101
102
|
# File 'lib/tcp_server/modular_handler.rb', line 98
def channelWritabilityChanged(ctx)
log.trace "#channelWritabilityChanged channel: #{ctx.channel}"
notify :channel_writability_changed, ctx
super
end
|
#exceptionCaught(ctx, cause) ⇒ Object
104
105
106
107
108
109
110
|
# File 'lib/tcp_server/modular_handler.rb', line 104
def exceptionCaught(ctx, cause)
TcpServer.log.warn "#exceptionCaught channel: #{ctx.channel}, " \
"cause: #{cause.message}"
cause.backtrace.each { |t| TcpServer.log.error t }
listeners = notify :exception_caught, ctx, cause
super if listeners.nil? || listeners.empty?
end
|
#isSharable ⇒ Object
Overrides the Java::IoNettyChannel::SimpleChannelInboundHandler#isSharable
method
rubocop: disable Naming/PredicateMethod
34
35
36
|
# File 'lib/tcp_server/modular_handler.rb', line 34
def isSharable
true
end
|
#messageReceived(ctx, msg) ⇒ Object
80
81
82
83
84
|
# File 'lib/tcp_server/modular_handler.rb', line 80
def messageReceived(ctx, msg)
log.trace "#messageReceived channel: #{ctx.channel}, message: #{msg.inspect}"
notify :message_received, ctx, msg
end
|
#to_s ⇒ Object
Also known as:
inspect
114
115
116
|
# File 'lib/tcp_server/modular_handler.rb', line 114
def to_s
format(IdentifierTemplate, class: self.class.name, id: object_id.to_s(16))
end
|
#userEventTriggered(ctx, evt) ⇒ Object
92
93
94
95
96
|
# File 'lib/tcp_server/modular_handler.rb', line 92
def userEventTriggered(ctx, evt)
log.trace "#userEventTriggered channel: #{ctx.channel}, event: #{evt}"
notify :user_event_triggered, ctx, evt
super
end
|