You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by da...@daune-consult.com on 2005/04/21 13:17:28 UTC
Using Mina ByteBuffers
Hi,
I wonder what I have to do to use Mina ByteBuffer implementation in my
application (in ProtocolDecoder, in order to copy incoming bytes until a
complete message is received)
I especially wonder if I must acquire the buffer after calling
ByteBuffer.allocate (and then release it when work is done), or if
acquire/release is not needed.
There is some javadoc about it:
"Please note that you never need to release the allocated buffer because MINA
will release it automatically.
But, if you didn't pass it to MINA or called {@link #acquire()} by yourself, you
will have to release it manually"
But I don't understand what is meant by "pass to MINA".
Cheers,
J-F
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Re: Using Mina ByteBuffers
Posted by Trustin Lee <tr...@gmail.com>.
Hi,
2005/4/22, Julien Vermillard <jv...@archean.fr>:
<snip/>
> Damned, I never seen this so usefull CumulativeProtocolDecoder class
> before !
> That probably could help everybody migrating from Netty2.
If you're migrating from Netty2, then you could use
DumuxingProtocolCodecFactory which is similar to Netty's message
decoder/encoder. :)
Thanks,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
Re: Using Mina ByteBuffers
Posted by Julien Vermillard <jv...@archean.fr>.
Le jeudi 21 avril 2005 à 20:42 +0900, Trustin Lee a écrit :
> Hi,
>
> 2005/4/21, daune.jf@daune-consult.com <da...@daune-consult.com>:
> > Hi,
> >
> > I wonder what I have to do to use Mina ByteBuffer implementation in my
> > application (in ProtocolDecoder, in order to copy incoming bytes until a
> > complete message is received)
>
> You could just use CumulativeProtocolDecoder that does what you want.
>
> > I especially wonder if I must acquire the buffer after calling
> > ByteBuffer.allocate (and then release it when work is done), or if
> > acquire/release is not needed.
> >
> > There is some javadoc about it:
> >
> > "Please note that you never need to release the allocated buffer because MINA
> > will release it automatically.
> > But, if you didn't pass it to MINA or called {@link #acquire()} by yourself, you
> > will have to release it manually"
> >
> > But I don't understand what is meant by "pass to MINA".
>
> I updated documentation of Acquire/Release section. Please svn up and
> then you'll see more clear explanation. I'll copy and paste it here:
>
> Please note that you never need to release the allocated buffer
> because MINA will release it automatically when:
>
> * You pass the buffer by calling {@link IoSession#write(ByteBuffer,
> Object)}.</li>
> * You pass the buffer by calling {@link
> ProtocolEncoderOutput#write(ByteBuffer)}.
>
> And, you don't need to release any {@link ByteBuffer} which is passed
> as a parameter of {@link IoHandler#dataRead(IoSession, ByteBuffer)}
> method. They are released automatically when the method returns.
>
> You have to release buffers manually by calling {@link #release()} when:
>
> * You allocated a buffer, but didn't pass the buffer to any of two
> methods above.</li>
> * You called {@link #acquire()} to prevent the buffer from being released.</li>
>
> Is the documentation clearer now?
>
> Thanks,
> Trustin
Damned, I never seen this so usefull CumulativeProtocolDecoder class
before !
That probably could help everybody migrating from Netty2.
Julien
Re: Using Mina ByteBuffers
Posted by da...@daune-consult.com.
Selon Trustin Lee <tr...@gmail.com>:
> Hi,
>
> 2005/4/21, daune.jf@daune-consult.com <da...@daune-consult.com>:
> > Hi,
> >
> > I wonder what I have to do to use Mina ByteBuffer implementation in my
> > application (in ProtocolDecoder, in order to copy incoming bytes until a
> > complete message is received)
>
> You could just use CumulativeProtocolDecoder that does what you want.
>
> > I especially wonder if I must acquire the buffer after calling
> > ByteBuffer.allocate (and then release it when work is done), or if
> > acquire/release is not needed.
> >
> > There is some javadoc about it:
> >
> > "Please note that you never need to release the allocated buffer because
> MINA
> > will release it automatically.
> > But, if you didn't pass it to MINA or called {@link #acquire()} by
> yourself, you
> > will have to release it manually"
> >
> > But I don't understand what is meant by "pass to MINA".
>
> I updated documentation of Acquire/Release section. Please svn up and
> then you'll see more clear explanation. I'll copy and paste it here:
>
> Please note that you never need to release the allocated buffer
> because MINA will release it automatically when:
>
> * You pass the buffer by calling {@link IoSession#write(ByteBuffer,
> Object)}.</li>
> * You pass the buffer by calling {@link
> ProtocolEncoderOutput#write(ByteBuffer)}.
>
> And, you don't need to release any {@link ByteBuffer} which is passed
> as a parameter of {@link IoHandler#dataRead(IoSession, ByteBuffer)}
> method. They are released automatically when the method returns.
>
> You have to release buffers manually by calling {@link #release()} when:
>
> * You allocated a buffer, but didn't pass the buffer to any of two
> methods above.</li>
> * You called {@link #acquire()} to prevent the buffer from being
> released.</li>
>
> Is the documentation clearer now?
>
> Thanks,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
>
Perfect. This greatly clarifies ByteBuffer use.
And sorry for CumulativeProtocolDecoder. I underestimated MINA ;> !!!
Cheers,
J-F
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Re: Using Mina ByteBuffers
Posted by Trustin Lee <tr...@gmail.com>.
Hi,
2005/4/21, daune.jf@daune-consult.com <da...@daune-consult.com>:
> Hi,
>
> I wonder what I have to do to use Mina ByteBuffer implementation in my
> application (in ProtocolDecoder, in order to copy incoming bytes until a
> complete message is received)
You could just use CumulativeProtocolDecoder that does what you want.
> I especially wonder if I must acquire the buffer after calling
> ByteBuffer.allocate (and then release it when work is done), or if
> acquire/release is not needed.
>
> There is some javadoc about it:
>
> "Please note that you never need to release the allocated buffer because MINA
> will release it automatically.
> But, if you didn't pass it to MINA or called {@link #acquire()} by yourself, you
> will have to release it manually"
>
> But I don't understand what is meant by "pass to MINA".
I updated documentation of Acquire/Release section. Please svn up and
then you'll see more clear explanation. I'll copy and paste it here:
Please note that you never need to release the allocated buffer
because MINA will release it automatically when:
* You pass the buffer by calling {@link IoSession#write(ByteBuffer,
Object)}.</li>
* You pass the buffer by calling {@link
ProtocolEncoderOutput#write(ByteBuffer)}.
And, you don't need to release any {@link ByteBuffer} which is passed
as a parameter of {@link IoHandler#dataRead(IoSession, ByteBuffer)}
method. They are released automatically when the method returns.
You have to release buffers manually by calling {@link #release()} when:
* You allocated a buffer, but didn't pass the buffer to any of two
methods above.</li>
* You called {@link #acquire()} to prevent the buffer from being released.</li>
Is the documentation clearer now?
Thanks,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/