You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Trustin Lee <tr...@gmail.com> on 2007/07/26 16:54:54 UTC

Do we really need messageSent? (Was: Re: Small documentation on IoFilter)

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 <tr...@gmail.com> wrote:
> On 7/26/07, Germán Borbolla Flores <gb...@insys-corp.com.mx> 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), ...);
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: Do we really need messageSent? (Was: Re: Small documentation on IoFilter)

Posted by 向秦贤 <fy...@gmail.com>.
Hi,
We can check out again my ftp sample, from file upload codes, messageSent is
full necessary.
Supported there is no IoFilter, if no messageSent world would be what?
The baseframework, first own messageSent and other sessionMethods, and then
do extension to filter level. There are not same level.
We can use mina without IoFilter, But cannot use mina without sessionBase.
As to IoFilter, I not try it really, I have no talk.
Hope I get all guys means ok.

2007/7/26, Trustin Lee <tr...@gmail.com>:
>
> 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 <tr...@gmail.com> wrote:
> > On 7/26/07, Germán Borbolla Flores <gb...@insys-corp.com.mx> 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), ...);
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>



-- 
致敬
向秦贤

Re: Do we really need messageSent? (Was: Re: Small documentation on IoFilter)

Posted by Mark Webb <el...@gmail.com>.
I guess my comments was more towards the code that went:

if( message instanceof Integer ){
...
} else if( message instanceof String ){
...
} else if( message instanceof ByteBuffer ){
...
}

and so on.  Not so much towards whether or not we need messageSent.

On 7/26/07, Trustin Lee <tr...@gmail.com> wrote:
>
> On 7/27/07, Mark Webb <el...@gmail.com> wrote:
> > 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?
>
> It's about whether to support messageSent event or not.  As long as we
> support messageSent event, there's no reduced complexity.
>
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>



-- 
..Cheers
Mark

Re: Do we really need messageSent? (Was: Re: Small documentation on IoFilter)

Posted by Trustin Lee <tr...@gmail.com>.
On 7/27/07, Mark Webb <el...@gmail.com> wrote:
> 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?

It's about whether to support messageSent event or not.  As long as we
support messageSent event, there's no reduced complexity.

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: Do we really need messageSent? (Was: Re: Small documentation on IoFilter)

Posted by Mark Webb <el...@gmail.com>.
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 <gb...@insys-corp.com.mx> 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 <tr...@gmail.com> wrote:
> >> On 7/26/07, Germán Borbolla Flores <gb...@insys-corp.com.mx> 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

Re: Do we really need messageSent? (Was: Re: Small documentation on IoFilter)

Posted by Germán Borbolla Flores <gb...@insys-corp.com.mx>.
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 <tr...@gmail.com> wrote:
>> On 7/26/07, Germán Borbolla Flores <gb...@insys-corp.com.mx> 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), ...);