directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Andersson <>
Subject [mina] ByteBuffer allocation
Date Thu, 03 Feb 2005 13:11:43 GMT
I have a working prototype of an IoHandlerFilter that uses SSL to 
data. The implementation uses the new SSLEngine utilities provided with 
Java  1.5.

I have a few questions regarding ByteBuffer allocation.

In dataRead(Handler nextHandler, IoSession session, ByteBuffer buf) I 
send the
ByteBuffer to my SSL Utility to decrypt the buffer. Depending on SSL 
state this
either involves initial SSL handshaking or simply decryption of the 
Encryptinon is handled in filterWrite(IoSession session, ByteBuffer 
I have 2 cases where I allocate org.apache.mina.common.ByteBuffers:

1) To write data during SSL handshake i allocate ByteBuffer(s) using
    ByteBuffer.allocate(), copies the encrypted data and write it to the 
net using

2) In filterWrite(IoSession session, ByteBuffer buf) I encrypt the 
    ByteBuffer (if not doing initial handshake where provided data is 
    encrypted). I allocate a ByteBuffer, copies the encrypted data to 
    buffer and return it

Now to my questions:

- case 1) where i call session.write(), where would be the best place to
   release allocated ByteBuffer?

- for case 2) I allocate a new buffer, since the encrypted data may be 
   that the provided ByteBuffer. Where would be the best place to 
release allocated
   ByteBuffer in this case?

I guess the best solution would be (for case 2) to make sure Mina 
allokates buffers
of a configurable size, somehough? But for case 1) I have to allocate 
and release

One thing that could help, might be to provide a method in 
that allows me to create a org.apache.mina.common.ByteBuffer from a 
This would *not* use the cache/stacks provided, but allow me to create 
a Mina-style
ByteBuffer from a java.nio.ByteBuffer (that is allocated/released by 

Withh the hope that this did make some sence ;)


View raw message