Client disconnect

Christian Migowski chrismfwrd at gmail.com
Thu May 7 01:37:06 EDT 2009


Hello Matthias,

you maybe already solved this, but I find Frederics first suggestion
much more in line with (at least how I think) how Netty works: just
get the ChannelFuture of the last operation and wait for its
completion. You could store it away as a property in your class and
then wait everywhere for it, e.g.

ChannelFuture lastFuture = null;

public <T> void send( T object ) {
     ChannelFuture future = getChannelFuture();
     Channel channel = future.getChannel();
     if ( future.isSuccess() ) {
        lastFuture = channel.write(object);
     }
  }

and then you'll await for it in you main thread or place a listener.


greetings,
christian!


On Wed, May 6, 2009 at 4:56 PM, matthias.s.
<matthias.scudlik at pangora.com> wrote:
>
> I found out why this solution doesn't work:
>
> The "problem" is that netty does batch write operations meaning
>
> several writeRequest() calls lead to a single writeCompleted() call.
>
> The fired WriteCompleteionEvent has a Method called getWrittenAmount() which
> should do this according to the documentation:
>
>    /**
>     * Returns the amount of data written.
>     *
>     * @return the number of written bytes or messages, depending on the
>     *         type of the transport
>     */
>
> Well, I am sending Object Messages, but the value is obviously the amount of
> bytes and much bigger than the sent object count.
>
> I tried to count the bytes of the messages using a sizeOf Method like this:
>
>   private static long sizeOf( Object object ) {
>      ByteArrayOutputStream bos = null;
>      ObjectOutputStream oos = null;
>      try {
>         bos = new ByteArrayOutputStream();
>         oos = new CompactObjectOutputStream(bos);
>         oos.writeObject(object);
>         byte[] byteArray = bos.toByteArray();
>         return byteArray.length;
>      }
>      catch ( IOException e ) {
>         return 0;
>      }
>      finally {
>         if ( oos != null ) {
>            try {
>               oos.close();
>            }
>            catch ( IOException e ) {}
>         }
>         if ( bos != null ) {
>            try {
>               bos.close();
>            }
>            catch ( IOException e ) {}
>         }
>      }
>   }
>
> The CompatcObjectOutputStream is used by the ObjectEncoder, but
> unfortunately the complete/request counts don't match. The same happend
> using java.io.ObjectOutputStream
> --
> View this message in context: http://n2.nabble.com/Client-disconnect-tp2798147p2817379.html
> Sent from the Netty User Group mailing list archive at Nabble.com.
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>




More information about the netty-users mailing list