Isn't this related to a discussion a few months back where there was talk of
making the IoFilter and/or IoHandler java generics 'aware'?  If that is the
case, should we try that route?


On 7/26/07, Germán Borbolla Flores <[EMAIL PROTECTED]> wrote:

Hi,

By no means I'm an expert (I've just started working with mina a month
ago), but I haven't found any use for messageSent so I'll agree to
remove it from trunk.

Germán

Trustin Lee wrote:
> Hi folks,
>
> I found implementing message transformation in IoFilter becomes
> extremely complicated because of messageSent event, like the following
> Q&A.
>
> We already have WriteFuture, so adding an IoFutureListener will simply
> replace messageSent event handler.
>
> Is there any real use case that messageSent event is useful?  If not,
> shall we get rid of it from trunk?  I know it's a radical change, but
> I believe it worths a lot in that it simplifies the architecture
> without sacrificing features.
>
> Trustin
>
> On 7/26/07, Trustin Lee <[EMAIL PROTECTED]> wrote:
>> On 7/26/07, Germán Borbolla Flores <[EMAIL PROTECTED]> wrote:
>> > 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.
>>
>> You will have to create a new ByteBuffer subtype:
>>
>> private static class MyByteBuffer extends ByteBufferProxy {
>>    private final Object value;
>>    private ByteByteBuffer(Object value, ByteBuffer encodedValue) {
>>        super(encodedValue);
>>    }
>>    public Object getValue() { return value; }
>> }
>>
>> now in your messageSent implementation:
>>
>> public void messageSent(NextFilter nextFilter, IoSession session,
>> Object msg) {
>>    if (msg instanceof MyByteBuffer) {
>>        nextFilter.messageSent(session, ((MyByteBuffer)
msg).getValue());
>>    } else {
>>        nextFilter.messageSent(session, msg);
>>    }
>> }
>>
>> You also need to pass a new MyByteBuffer in filterWrite:
>>
>> nextFilter.filterWrite(session, new WriteRequest(new MyBuffer(message,
>> outBuffer), ...);




--
..Cheers
Mark

Reply via email to