Note that there are some explanatory texts on larger screens.

plurals
  1. POAttributes handover from TelnetServer to TelnetServerHandler netty-4.0.10 Final
    text
    copied!<p>I have the plan to read my config file in the server part into the memory and use the data in the handler.</p> <p>Attached the code snippets.</p> <p>// from the example directory </p> <pre><code>public class TelnetServer { private final int port; private final String myConfFile; // MyConf is a singleton class which read the config // from my app into memory private static final AttributeKey&lt;MyConf&gt; myCAttribute = new AttributeKey&lt;MyConf&gt;("MyConf"); public TelnetServer(int port,String confFile) { this.port = port; this.myConfFile = confFile; } public void run() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.childAttr(myCAttribute, MyConf.getInstance(myConfFile)); b.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .childHandler(new TelnetServerInitializer()); b.bind(port).sync().channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } } } </code></pre> <p>Now I want to use the value in the TelnetServerHandler. </p> <pre><code>public void channelRead0(ChannelHandlerContext ctx, String request) throws Exception { // Generate and write a response. String response; boolean close = false; if (request.isEmpty()) { response = "Please type something.\r\n"; } else if ("bye".equals(request.toLowerCase())) { response = "Have a good day!\r\n"; close = true; } else { response = "Did you say '" + request + "'?\r\n"; MyConf mc = (MyConf)ctx.attr("MyConf"); } // We do not need to write a ChannelBuffer here. // We know the encoder inserted at TelnetPipelineFactory will do the conversion. ChannelFuture future = ctx.write(response); // Close the connection after sending 'Have a good day!' // if the client has sent 'bye'. if (close) { future.addListener(ChannelFutureListener.CLOSE); } } </code></pre> <p>But this doesn't works. Please can anybody point me to the right doc or give me a hint how I can realize this plan.</p> <p>Thanks for help. John</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload