Messages
of a
communication channel.
An NetSwitch server has two types of devices: Connectors
and
Listeners
. A Connector (or client) connects to a remote
listener, and can have one (or more) bidirectional communication channels (or
sockets). A Listener (or server) waits for connections from remote
clients, and can have several bidirectional communication channels, one for
each client.
A ChannelFilter
is specified in the configuration file of the server,
and can be assigned to a Connector or a Listener. Each time a
device channel is created, a new instance of the ChannelFilter
is
initialized
and then bound to the channel.
From that point on, every inbound or outbound Message
is passed to
the ChannelFilter
for inspection and possible modification. Finally,
when the channel is closed, the ChannelFilter
instance is terminated
and released.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
afterInboundReceived
(FilterContext context, Message inbound) Called after an inbound message is received.boolean
beforeOutboundSent
(FilterContext context, Message outbound) Called before an outbound message is sent.void
initialize
(FilterContext context) Called to initialize the ChannelFilter.void
terminate
(FilterContext context) Called to terminate the ChannelFilter.
-
Method Details
-
initialize
Called to initialize the ChannelFilter.This method is called only once at the beginning of the life cycle of a channel. This method can be used to perform one-time initializations.
If this message throws and exception, the exception will be logged, and then processing will continue as if nothing had happened. In other worlds, the exception will be ignored.
- Parameters:
context
- the context of the filter.- Throws:
NullPointerException
- ifcontext
isnull
.Exception
- if another error occurs.
-
afterInboundReceived
Called after an inbound message is received.If this method modifies the
inbound
message, the modified version will be dispatched to its destination.If this method returns
true
, theinbound
message will dispatched, otherwise it will be discarded.If this message throws and exception, the exception will be logged, and then processing will continue as if the method had returned
true
. In other words, the exception will be ignored.- Parameters:
context
- the context of the filter.inbound
- the inbound message.- Returns:
true
if theinbound
message should be dispatched.- Throws:
NullPointerException
- if an argument isnull
.Exception
- if another error occurs.
-
beforeOutboundSent
Called before an outbound message is sent.If this method modifies the
outbound
message, the modified version will be written (sent) to the channel.If this method returns
true
, theoutbound
message will be sent, otherwise it will be discarded.If this message throws and exception, the exception will be logged, and then processing will continue as if the method had returned
true
. In other words, the exception will be ignored.- Parameters:
context
- the context of the filter.outbound
- the outbound message.- Returns:
true
if theoutbound
message should be sent.- Throws:
NullPointerException
- if an argument isnull
.Exception
- if another error occurs.
-
terminate
Called to terminate the ChannelFilter.This method is called only once at the end of the life cycle of a channel. This method can be used to release resources, and perform other cleanup activities.
If this message throws and exception, the exception will be logged, and then processing will continue as if nothing had happened. In other worlds, the exception will be ignored.
- Parameters:
context
- the context of the filter.- Throws:
NullPointerException
- ifcontext
isnull
.Exception
- if another error occurs.
-