From directory-dev-return-4094-apmail-incubator-directory-dev-archive=incubator.apache.org@incubator.apache.org Thu Feb 03 13:11:52 2005 Return-Path: Delivered-To: apmail-incubator-directory-dev-archive@www.apache.org Received: (qmail 21449 invoked from network); 3 Feb 2005 13:11:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 3 Feb 2005 13:11:52 -0000 Received: (qmail 64030 invoked by uid 500); 3 Feb 2005 13:11:52 -0000 Delivered-To: apmail-incubator-directory-dev-archive@incubator.apache.org Received: (qmail 63987 invoked by uid 500); 3 Feb 2005 13:11:52 -0000 Mailing-List: contact directory-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list directory-dev@incubator.apache.org Received: (qmail 63967 invoked by uid 99); 3 Feb 2005 13:11:51 -0000 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=FORGED_RCVD_HELO X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from mail.minq.se (HELO minq.se) (213.80.78.66) by apache.org (qpsmtpd/0.28) with ESMTP; Thu, 03 Feb 2005 05:11:49 -0800 Received: from [213.114.94.232] (account janne HELO [192.168.0.100]) by minq.se (CommuniGate Pro SMTP 4.0.5) with ESMTP id 1272713 for directory-dev@incubator.apache.org; Thu, 03 Feb 2005 14:11:44 +0100 Mime-Version: 1.0 (Apple Message framework v619.2) Content-Transfer-Encoding: 7bit Message-Id: Content-Type: text/plain; charset=US-ASCII; format=flowed To: Apache Directory Developers List From: Jan Andersson Subject: [mina] ByteBuffer allocation Date: Thu, 3 Feb 2005 14:11:43 +0100 X-Mailer: Apple Mail (2.619.2) X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N I have a working prototype of an IoHandlerFilter that uses SSL to encrypt/decrypt 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 data. Encryptinon is handled in filterWrite(IoSession session, ByteBuffer buf). 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 session.write(). 2) In filterWrite(IoSession session, ByteBuffer buf) I encrypt the provided ByteBuffer (if not doing initial handshake where provided data is already encrypted). I allocate a ByteBuffer, copies the encrypted data to this 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 larger 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 ByteBuffers... One thing that could help, might be to provide a method in org.apache.mina.common.ByteBuffers that allows me to create a org.apache.mina.common.ByteBuffer from a java.nio.ByteBuffer. 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 me). Withh the hope that this did make some sence ;) /Janne