mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Germán Borbolla Flores <gborbo...@insys-corp.com.mx>
Subject Re: Small documentation on IoFilter
Date Thu, 26 Jul 2007 14:20:02 GMT
Hi Trustin,

I've just read the tutorial and I don't understand how to correctly 
transform a Write request.

I have the following filterWrite implementation:

    public void filterWrite(NextFilter nextFilter, IoSession session, 
WriteRequest writeRequest) throws Exception
    {
        Object message = writeRequest.getMessage();
        if (message instanceof ByteBuffer)
        {
            nextFilter.filterWrite(session, writeRequest);
        }
        else
        {
            if (message instanceof Byte)
            {
                ByteBuffer outBuffer = ByteBuffer.allocate(1);
                outBuffer.put((Byte)message);
                outBuffer.flip();
                nextFilter.filterWrite(session, new 
WriteRequest(outBuffer, writeRequest.getFuture(), 
writeRequest.getDestination()));
            }
            else if (message instanceof Integer)
            {
                ByteBuffer outBuffer = ByteBuffer.allocate(4);
                outBuffer.putInt((Integer)message);
                outBuffer.flip();
                nextFilter.filterWrite(session, new 
WriteRequest(outBuffer, writeRequest.getFuture(), 
writeRequest.getDestination()));
            }
            else if (message instanceof Long)
            {
                ByteBuffer outBuffer = ByteBuffer.allocate(8);
                outBuffer.putLong((Long)message);
                outBuffer.flip();
                nextFilter.filterWrite(session, new 
WriteRequest(outBuffer, writeRequest.getFuture(), 
writeRequest.getDestination()));
            }
            else if (message instanceof byte[])
            {
                byte[] byteArray = (byte[])message;
                ByteBuffer outBuffer = ByteBuffer.allocate(4 + 
byteArray.length);
                outBuffer.putInt(byteArray.length);
                outBuffer.put(byteArray);
                outBuffer.flip();
                nextFilter.filterWrite(session, new 
WriteRequest(outBuffer, writeRequest.getFuture(), 
writeRequest.getDestination()));
            }
        }
    }   

Can you give me some pointers of how the messageSent should look like.

Thanks in advance.

Trustin Lee wrote:
> Hi folks,
>
> I wrote a small tutorial about implementing an IoFilter:
>
> http://cwiki.apache.org/MINA/iofilter.html
>
> Please feel free to give some feed back or edit directly.
>
> HTH,
> Trustin

Mime
View raw message