ChannelPipeline pipeline = pipeline(); // Note the static import.
if (_debug)
pipeline.addLast("logging1", new LoggingFilter(_controller.getLog(), "controller"));
// allow new connections only if state != LOGGED_ON
pipeline.addLast("checkWaiting", new ConditionFilter(new Condition()
{
public boolean isOk(ChannelHandlerContext ctx, ChannelEvent e)
{
boolean result = true;
int currentState = _controller.getState();
if (currentState == JVMController.STATE_LOGGED_ON)
{
_controller.getLog().info("app already logged on -> rejecting new connedction");
result = false;
}
return result;
}
}));
// create a firewall allowing only localhosts to connect
WhitelistFilter firewall = new WhitelistFilter();
try
{
firewall.allowAll(InetAddress.getAllByName("127.0.0.1"));
firewall.allow(InetAddress.getLocalHost());
pipeline.addLast("firewall", firewall);
}
catch (UnknownHostException e)
{
_controller.getLog().throwing(JVMController.class.getName(), "start", e);
}
// add a framer to split incoming bytes to message chunks
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, true, Delimiters.nulDelimiter()));
// add messge codec
pipeline.addLast("messageEncoder", new MessageEncoder());
pipeline.addLast("messageDecoder", new MessageDecoder());
if (_controller.isDebug())
{
pipeline.addLast("logging", new LoggingFilter(_controller.getLog(), "controller"));
_controller.getLog().info("Logging ON");
}
// if we found our partner close all other open connections
pipeline.addLast("removeConnected", new ChannelGroupFilter(new Condition()
{
public boolean isOk(ChannelHandlerContext ctx, ChannelEvent e)
{
boolean result = false;
if (e instanceof MessageEvent)