<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Thanks all for your help. &nbsp;Very much appreciated. &nbsp;I have closed with:<div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #7f0055">public</span> <span style="color: #7f0055">void</span> messageReceivedUpstream (</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>ChannelHandlerContext ctx, MessageEvent evt ) <span style="color: #7f0055">throws</span> Exception {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>Object originalMessage = evt.getMessage ( );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>Object decodedMessage =</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>decode ( ctx, evt.getChannel ( ), originalMessage );</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px"><span class="Apple-tab-span" style="white-space:pre">                </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #7f0055">if</span> (decodedMessage <span style="color: #7f0055">instanceof</span> KarmaChannelClose) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="Apple-tab-span" style="white-space:pre">                </span>evt.getChannel().close();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>}</div></div><div><br></div><div>Mike</div><div><br></div><div><br><div><div>On Aug 11, 2009, at 11:36 PM, Christian Migowski wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>I am not sure if i understand your problem, but in case you just want<br>to close the connection to the server in your client/sender class,<br>shouldn't it be enough to replace the last line in your notify methods<br>with something like<br><br>this.channel.write(buffer).awaitUninterruptibly();<br>this.channel.close().awaitUninterruptibly();<br><br>(you could skip the last await)?<br>Then you could dispose the factory with releaseExternalResources() and<br>Netty should eat none of your bread anymore ;)<br><br>hth,<br>christian!<br><br><br>On Tue, Aug 11, 2009 at 8:38 PM, Michael<br>McGrady&lt;<a href="mailto:mmcgrady@topiatechnology.com">mmcgrady@topiatechnology.com</a>&gt; wrote:<br><blockquote type="cite">Sorry, forgot the text. &nbsp;How do I close the client after notify(....) sends<br></blockquote><blockquote type="cite">the data to the application logic without closing the server?<br></blockquote><blockquote type="cite">Mike<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Mike McGrady<br></blockquote><blockquote type="cite">Principal Investigator AF081-028 AFRL SBIR<br></blockquote><blockquote type="cite">Senior Engineer<br></blockquote><blockquote type="cite">Topia Technology, Inc<br></blockquote><blockquote type="cite">1.253.720.3365<br></blockquote><blockquote type="cite"><a href="mailto:mmcgrady@topiatechnology.com">mmcgrady@topiatechnology.com</a><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">SERVER Manager Code<br></blockquote><blockquote type="cite">NettyKarmaReceiverAdapter receiver = new NettyKarmaReceiverAdapter(new<br></blockquote><blockquote type="cite">InetSocketAddress("localhost", 8080)) ;<br></blockquote><blockquote type="cite">receiver.start() ;<br></blockquote><blockquote type="cite">CLIENT Manager Code<br></blockquote><blockquote type="cite">NettyKarmaSenderAdapter sender = new NettyKarmaSenderAdapter("localhost",<br></blockquote><blockquote type="cite">8080) ;<br></blockquote><blockquote type="cite">sender.start() ;<br></blockquote><blockquote type="cite">sender.notify("Hello, World!") ;<br></blockquote><blockquote type="cite">sender.stop() ;<br></blockquote><blockquote type="cite">RECEIVER ADAPTER Code<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public NettyKarmaReceiverAdapter(InetSocketAddress address) {<br></blockquote><blockquote type="cite">this.address = address;<br></blockquote><blockquote type="cite">&nbsp; &nbsp; &nbsp; &nbsp; this.factory =<br></blockquote><blockquote type="cite">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new NioServerSocketChannelFactory(<br></blockquote><blockquote type="cite">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Executors.newCachedThreadPool(),<br></blockquote><blockquote type="cite">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Executors.newCachedThreadPool());<br></blockquote><blockquote type="cite">&nbsp; &nbsp; &nbsp; &nbsp; this.bootstrap = new ServerBootstrap(factory);<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">private void setup ( ) {<br></blockquote><blockquote type="cite">&nbsp; &nbsp; &nbsp; &nbsp; this.bootstrap.setOption("child.tcpNoDelay", true);<br></blockquote><blockquote type="cite">&nbsp; &nbsp; &nbsp; &nbsp; this.bootstrap.setOption("child.keepAlive", true);<br></blockquote><blockquote type="cite">&nbsp; &nbsp; &nbsp; &nbsp; this.bootstrap.setPipelineFactory(new<br></blockquote><blockquote type="cite">KarmaReceiverPipelineFactory(this));<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">public void start ( ) {<br></blockquote><blockquote type="cite">setup() ;<br></blockquote><blockquote type="cite">&nbsp; &nbsp; &nbsp; &nbsp; this.bootstrap.bind(address); }<br></blockquote><blockquote type="cite">SENDER ADAPTER Code<br></blockquote><blockquote type="cite">public NettyKarmaSenderAdapter ( String host, int port ) {<br></blockquote><blockquote type="cite">this.host = host;<br></blockquote><blockquote type="cite">this.port = port;<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">public void setup ( ) {<br></blockquote><blockquote type="cite">ChannelFactory factory =<br></blockquote><blockquote type="cite">new NioClientSocketChannelFactory ( Executors<br></blockquote><blockquote type="cite">.newCachedThreadPool ( ), Executors.newCachedThreadPool ( ) );<br></blockquote><blockquote type="cite">this.bootstrap = new ClientBootstrap ( factory );<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">this.bootstrap<br></blockquote><blockquote type="cite">.setPipelineFactory ( new KarmaSenderPipelineFactory (this) );<br></blockquote><blockquote type="cite">this.bootstrap.setOption ( "tcpNoDelay", true );<br></blockquote><blockquote type="cite">this.bootstrap.setOption ( "keepAlive", true );<br></blockquote><blockquote type="cite">ChannelFuture future =<br></blockquote><blockquote type="cite">this.bootstrap.connect ( new InetSocketAddress ( this.host, this.port ) );<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">// Wait until the connection attempt succeeds or fails.<br></blockquote><blockquote type="cite">this.channel = future.awaitUninterruptibly ( ).getChannel ( );<br></blockquote><blockquote type="cite">if ( !future.isSuccess ( ) ) {<br></blockquote><blockquote type="cite">future.getCause ( ).printStackTrace ( );<br></blockquote><blockquote type="cite">factory.releaseExternalResources ( );<br></blockquote><blockquote type="cite">return;<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public void start ( ) {<br></blockquote><blockquote type="cite">setup ( );<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public int stop ( ) {<br></blockquote><blockquote type="cite">????????????????????????????????????????<br></blockquote><blockquote type="cite">return +2;<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">public void notify ( File file ) {<br></blockquote><blockquote type="cite">try {<br></blockquote><blockquote type="cite">KarmaChunkedFile chunks = new KarmaChunkedFile(file) ;<br></blockquote><blockquote type="cite">try {<br></blockquote><blockquote type="cite">while (chunks.hasNextChunk()) {<br></blockquote><blockquote type="cite">Object object = chunks.nextChunk ( ) ;<br></blockquote><blockquote type="cite">byte [] bytes = ByteObjectConverter.toBytes(object) ;<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(bytes) ;<br></blockquote><blockquote type="cite">this.channel.write ( buffer );<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">} catch ( Exception e ) {<br></blockquote><blockquote type="cite">// TODO Auto-generated catch block<br></blockquote><blockquote type="cite">e.printStackTrace();<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">} catch ( IOException e ) {<br></blockquote><blockquote type="cite">// TODO Auto-generated catch block<br></blockquote><blockquote type="cite">e.printStackTrace();<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">public void notify ( KarmaAumlet aumlet ) {<br></blockquote><blockquote type="cite">byte [] bytes = ByteObjectConverter.toBytes(aumlet) ;<br></blockquote><blockquote type="cite">ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(bytes) ;<br></blockquote><blockquote type="cite">this.channel.write ( buffer );<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public void notify ( String message ) {<br></blockquote><blockquote type="cite">byte [] bytes = ByteObjectConverter.toBytes(new KarmaMessage(message)) ;<br></blockquote><blockquote type="cite">ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(bytes) ;<br></blockquote><blockquote type="cite">this.channel.write ( buffer );<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">SENDER PIPELINE Code<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public class KarmaSenderPipelineFactory implements ChannelPipelineFactory {<br></blockquote><blockquote type="cite">private final NettyKarmaSenderAdapter adapter ;<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public KarmaSenderPipelineFactory (NettyKarmaSenderAdapter adapter) {<br></blockquote><blockquote type="cite">this.adapter = adapter;<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public ChannelPipeline getPipeline ( ) throws Exception {<br></blockquote><blockquote type="cite">ChannelPipeline pipeline = pipeline ( );<br></blockquote><blockquote type="cite">SSLEngine engine =<br></blockquote><blockquote type="cite">KarmaSslContextFactory.getClientContext ( ).createSSLEngine ( );<br></blockquote><blockquote type="cite">engine.setUseClientMode ( true );<br></blockquote><blockquote type="cite">pipeline.addLast ( "ssl", new KarmaSslHandler ( engine ) );<br></blockquote><blockquote type="cite">pipeline.addLast ( "universal", new KarmaSenderCodecHandler (<br></blockquote><blockquote type="cite">adapter) );<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">return pipeline;<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">SENDER CODEC HANDLER Code<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public class KarmaReceiverPipelineFactory implements ChannelPipelineFactory<br></blockquote><blockquote type="cite">{<br></blockquote><blockquote type="cite">private final NettyKarmaReceiverAdapter adapter ;<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public KarmaReceiverPipelineFactory ( NettyKarmaReceiverAdapter adapter ) {<br></blockquote><blockquote type="cite">this.adapter = adapter;<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public ChannelPipeline getPipeline ( ) throws Exception {<br></blockquote><blockquote type="cite">ChannelPipeline pipeline = pipeline ( );<br></blockquote><blockquote type="cite">SSLEngine engine =<br></blockquote><blockquote type="cite">SslContextFactory.getServerContext ( ).createSSLEngine ( );<br></blockquote><blockquote type="cite">engine.setUseClientMode ( false );<br></blockquote><blockquote type="cite">pipeline.addLast ( "ssl", new SslHandler ( engine ) );<br></blockquote><blockquote type="cite">pipeline.addLast ( "universal", new KarmaReceiverCodecHandler (<br></blockquote><blockquote type="cite">adapter ) );<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">return pipeline;<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">RECEIVER PIPELINE Code<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public class KarmaReceiverPipelineFactory implements ChannelPipelineFactory<br></blockquote><blockquote type="cite">{<br></blockquote><blockquote type="cite">private final NettyKarmaReceiverAdapter adapter ;<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public KarmaReceiverPipelineFactory ( NettyKarmaReceiverAdapter adapter ) {<br></blockquote><blockquote type="cite">this.adapter = adapter;<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public ChannelPipeline getPipeline ( ) throws Exception {<br></blockquote><blockquote type="cite">ChannelPipeline pipeline = pipeline ( );<br></blockquote><blockquote type="cite">SSLEngine engine =<br></blockquote><blockquote type="cite">KarmaSslContextFactory.getServerContext ( ).createSSLEngine ( );<br></blockquote><blockquote type="cite">engine.setUseClientMode ( false );<br></blockquote><blockquote type="cite">pipeline.addLast ( "ssl", new SslHandler ( engine ) );<br></blockquote><blockquote type="cite">pipeline.addLast ( "universal", new KarmaReceiverCodecHandler (<br></blockquote><blockquote type="cite">adapter ) );<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">return pipeline;<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">RECEIVER CODEC HANDLER Code<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">public KarmaReceiverCodecHandler ( KarmaReceiver receiver ) {<br></blockquote><blockquote type="cite">this.receiver = receiver;<br></blockquote><blockquote type="cite">this.charsetName = Charset.defaultCharset ( ).name ( );<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">public void messageReceivedUpstream (<br></blockquote><blockquote type="cite">ChannelHandlerContext ctx, MessageEvent evt ) throws Exception {<br></blockquote><blockquote type="cite">Object originalMessage = evt.getMessage ( );<br></blockquote><blockquote type="cite">Object decodedMessage =<br></blockquote><blockquote type="cite">decode ( ctx, evt.getChannel ( ), originalMessage );<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">if ( originalMessage == decodedMessage ) {<br></blockquote><blockquote type="cite">ctx.sendUpstream ( evt );<br></blockquote><blockquote type="cite">} else {<br></blockquote><blockquote type="cite">if ( ! ( ( evt ).getMessage ( ) instanceof ChannelBuffer ) ) {<br></blockquote><blockquote type="cite">fireMessageReceived ( ctx, decodedMessage, evt.getRemoteAddress ( ) );<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">private Object decode (<br></blockquote><blockquote type="cite">ChannelHandlerContext ctx, Channel channel, Object msg )<br></blockquote><blockquote type="cite">throws Exception {<br></blockquote><blockquote type="cite">if ( ! ( msg instanceof ChannelBuffer ) ) {<br></blockquote><blockquote type="cite">return msg;<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">ChannelBuffer buffer = ( ( ChannelBuffer ) msg ).copy ( );<br></blockquote><blockquote type="cite">int readableBytes = buffer.readableBytes ( );<br></blockquote><blockquote type="cite">byte [ ] bytes = new byte [ readableBytes ];<br></blockquote><blockquote type="cite">buffer.readBytes ( bytes );<br></blockquote><blockquote type="cite">Object object = ByteObjectConverter.toObject ( bytes );<br></blockquote><blockquote type="cite">if (object instanceof KarmaMessage ) {<br></blockquote><blockquote type="cite">this.receiver.update ( ((KarmaMessage)object).message ) ;<br></blockquote><blockquote type="cite">} else if (object instanceof KarmaChunk ) {<br></blockquote><blockquote type="cite">this.receiver.update ( ((KarmaChunk)object) ) ;<br></blockquote><blockquote type="cite">}&nbsp; else if (object instanceof Serializable ) {<br></blockquote><blockquote type="cite">this.receiver.update ( ((KarmaAumlet)object) ) ; }<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">return ( ( ChannelBuffer ) msg ).toString ( charsetName );<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">netty-users mailing list<br></blockquote><blockquote type="cite"><a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br></blockquote><blockquote type="cite"><a href="https://lists.jboss.org/mailman/listinfo/netty-users">https://lists.jboss.org/mailman/listinfo/netty-users</a><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><br>_______________________________________________<br>netty-users mailing list<br><a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/netty-users<br></div></blockquote></div><br><div apple-content-edited="true"> <div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Mike McGrady</div><div>Principal Investigator AF081-028 AFRL SBIR</div><div>Senior Engineer</div><div>Topia Technology, Inc</div><div>1.253.720.3365</div><div><a href="mailto:mmcgrady@topiatechnology.com">mmcgrady@topiatechnology.com</a></div></div><div><br></div></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"></div><br class="Apple-interchange-newline"> </div><br></div></body></html>