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 <[EMAIL PROTECTED]>:
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), ...);
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6
--
致敬
向秦贤