You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Rodrigo Madera <ro...@gmail.com> on 2007/07/23 03:28:13 UTC

Demuxing Tutorials

Hello all,

I was wondering if anyone has any introductory material on MINA's Demuxing
implementation.

On the "Tutorial on ProtocolCodecFilter" page there is a note on the bottom
that this would possibly be added.

If anyone has a pointer, please share!

Thank you,
Rodrigo

Re: Demuxing Tutorials

Posted by Rodrigo Madera <ro...@gmail.com>.
I'll keep you posted on our progress.

I think there are interesting things to learn from this approach.

Best wishes,
Rodrigo


On 7/24/07, Alex Karasulu <ak...@apache.org> wrote:
>
> Would be nice if this stuff could do ASN.1 to pack().  Perhaps that is
> something they
> may look into.
>
> Alex
>
> On 7/24/07, Mehmet D. AKIN <md...@gmail.com> wrote:
> >
> > On 7/24/07, Trustin Lee <tr...@gmail.com> wrote:
> > > Hi Rodrigo,
> > >
> > > On 7/24/07, Rodrigo Madera <ro...@gmail.com> wrote:
> > > > Please tell me this wheel is invented and ready in MINA!!
> > > >
> > > > Here is the scenario taking as an example the SumUp server (the
> > closest
> > > > thing to the case).
> > > > Let's suppose there is this project called MegaMath, which is kind
> of
> > like
> > > > SumUp but has more operations:
> > > >
> > > > public class MegaMathMessage {
> > > >     private byte opcode;
> > > >
> > > >     MegaMathMessage(opcode) {
> > > >         this.opcode = opcode;
> > > >     }
> > > >
> > > >     ...
> > > > }
> > > >
> > > > public class MultiplyMessage extends MegaMathMessage {
> > > >     private byte operand0;
> > > >
> > > >     MultiplyMessage()
> > > >     {
> > > >         super(Constants.MULTIPLY_OPCODE);
> > > >         ...
> > > >     }
> > > >
> > > >     ...
> > > > }
> > > >
> > > > public class DoSomethingReallyNiceWithThreeArguments {
> > > >     private int arg0;
> > > >     private short arg1;
> > > >     private byte arg3;
> > > >
> > > >     // ... initialize with ctor etc...
> > > > }
> > > >
> > > > Now that we have the variable parameter quantity messages, we could
> > write
> > > > the decoders and encoders, but that's not nice.
> > > >
> > > > So the part we are writing let's us do basically this:
> > > >
> > > >     NiceEngine.register(MultiplyMessage.class);
> > > >     NiceEngine.register(SingASongMessage.class);
> > > >     NiceEngine.register(DanceMessage.class);
> > > >
> > > >     MessageEncoder multiplyMessageDecoder =
> > > > NiceEngine.getDecoder("MultiplyMessage");
> > > > // classname or class can be used here.
> > > >     MessageDecoder multiplyMessageEncoder = Nice... you get the
> > point...
> > > >
> > > > Is this available?
> > >
> > > It's not available.  I think it's difficult to generalize.
> > >
> > > > The problem is that manually creating Decoders and Encoders is just
> a
> > waste
> > > > of time. This should be a machine's work, and this is what our
> design
> > is
> > > > promissing to aid us in.
> > > >
> > > > We tried using Javastruct, and even devoted three full days to
> writing
> > code
> > > > for it, but we came to the conclusion that we needed more and in a
> > more
> > > > structured manner, so we started this solution.
> > > >
> > > > If this is already implemented, please share some light on how to
> use
> > it.
> > >
> > > You could forward your feedback about JavaStruct to Mehmet so he can
> > > evolve it on and on. :)
> > >
> > > Thanks,
> > > Trustin
> > > --
> > > what we call human nature is actually human habit
> > > --
> > > http://gleamynode.net/
> > > --
> > > PGP Key ID: 0x0255ECA6
> > >
> >
> >
> > Hi,
> >
> > I agree with Rodrigo on writing protocol encoders and decoders is
> > quite tedious job. That was the reason I was thinking something like
> > JavaStruct might help on these situations. He also helped me to find
> > some bugs and had some nice insight on the architecture. Thanks a lot.
> >
> > Although Rodrigo and his team found JavaStruct is not enough to handle
> > their problems, I still have a feeling that JavaStruct can be helpful
> > on many situations. Please look at the example codes below. There are
> > two examples, an Adobe Photoshop color book binary file reader -
> > writer and a Mina example. Mina example is based on the nice protocol
> > encoder-decoder tutorial on the wiki and it is not complete yet, but
> > if you look at the code you will get the idea.
> >
> > Examples: http://javastruct.googlecode.com/svn/trunk/javastruct/samples/
> >
> > I also updated how-to documnent in the wiki. there is also usable 0.1
> > jar in the downloads section.
> >
> > IMHO, Rodrigo's approach, (If I have gueesed correctly), automatic
> > generation of encoders and decoders have good and weak sides. It
> > probably generates code with better I/O performance (since for every
> > type of message, there will be an encoder-decoder generated
> > automatically, reading and writing directly to mina byte buffers. But
> > generating code has always drawbacks, difficult to maintain and
> > implement and sometimes considered as an anti pattern. I hope they
> > achieve good results and share their results with us.
> >
> > regards
> > Mehmet
> >
>

Re: Demuxing Tutorials

Posted by Trustin Lee <tr...@gmail.com>.
On 7/24/07, Alex Karasulu <ak...@apache.org> wrote:
> Would be nice if this stuff could do ASN.1 to pack().  Perhaps that is
> something they
> may look into.

I would be nice to make it support pluggable encoding/decoding schemes
including ASN.1.  However, considering the existing proprietary
protocols that doesn't use ASN.1 but just C-style structs, I think
support for C-style structs should have higher priority IMHO.

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

Re: Demuxing Tutorials

Posted by Alex Karasulu <ak...@apache.org>.
Would be nice if this stuff could do ASN.1 to pack().  Perhaps that is
something they
may look into.

Alex

On 7/24/07, Mehmet D. AKIN <md...@gmail.com> wrote:
>
> On 7/24/07, Trustin Lee <tr...@gmail.com> wrote:
> > Hi Rodrigo,
> >
> > On 7/24/07, Rodrigo Madera <ro...@gmail.com> wrote:
> > > Please tell me this wheel is invented and ready in MINA!!
> > >
> > > Here is the scenario taking as an example the SumUp server (the
> closest
> > > thing to the case).
> > > Let's suppose there is this project called MegaMath, which is kind of
> like
> > > SumUp but has more operations:
> > >
> > > public class MegaMathMessage {
> > >     private byte opcode;
> > >
> > >     MegaMathMessage(opcode) {
> > >         this.opcode = opcode;
> > >     }
> > >
> > >     ...
> > > }
> > >
> > > public class MultiplyMessage extends MegaMathMessage {
> > >     private byte operand0;
> > >
> > >     MultiplyMessage()
> > >     {
> > >         super(Constants.MULTIPLY_OPCODE);
> > >         ...
> > >     }
> > >
> > >     ...
> > > }
> > >
> > > public class DoSomethingReallyNiceWithThreeArguments {
> > >     private int arg0;
> > >     private short arg1;
> > >     private byte arg3;
> > >
> > >     // ... initialize with ctor etc...
> > > }
> > >
> > > Now that we have the variable parameter quantity messages, we could
> write
> > > the decoders and encoders, but that's not nice.
> > >
> > > So the part we are writing let's us do basically this:
> > >
> > >     NiceEngine.register(MultiplyMessage.class);
> > >     NiceEngine.register(SingASongMessage.class);
> > >     NiceEngine.register(DanceMessage.class);
> > >
> > >     MessageEncoder multiplyMessageDecoder =
> > > NiceEngine.getDecoder("MultiplyMessage");
> > > // classname or class can be used here.
> > >     MessageDecoder multiplyMessageEncoder = Nice... you get the
> point...
> > >
> > > Is this available?
> >
> > It's not available.  I think it's difficult to generalize.
> >
> > > The problem is that manually creating Decoders and Encoders is just a
> waste
> > > of time. This should be a machine's work, and this is what our design
> is
> > > promissing to aid us in.
> > >
> > > We tried using Javastruct, and even devoted three full days to writing
> code
> > > for it, but we came to the conclusion that we needed more and in a
> more
> > > structured manner, so we started this solution.
> > >
> > > If this is already implemented, please share some light on how to use
> it.
> >
> > You could forward your feedback about JavaStruct to Mehmet so he can
> > evolve it on and on. :)
> >
> > Thanks,
> > Trustin
> > --
> > what we call human nature is actually human habit
> > --
> > http://gleamynode.net/
> > --
> > PGP Key ID: 0x0255ECA6
> >
>
>
> Hi,
>
> I agree with Rodrigo on writing protocol encoders and decoders is
> quite tedious job. That was the reason I was thinking something like
> JavaStruct might help on these situations. He also helped me to find
> some bugs and had some nice insight on the architecture. Thanks a lot.
>
> Although Rodrigo and his team found JavaStruct is not enough to handle
> their problems, I still have a feeling that JavaStruct can be helpful
> on many situations. Please look at the example codes below. There are
> two examples, an Adobe Photoshop color book binary file reader -
> writer and a Mina example. Mina example is based on the nice protocol
> encoder-decoder tutorial on the wiki and it is not complete yet, but
> if you look at the code you will get the idea.
>
> Examples: http://javastruct.googlecode.com/svn/trunk/javastruct/samples/
>
> I also updated how-to documnent in the wiki. there is also usable 0.1
> jar in the downloads section.
>
> IMHO, Rodrigo's approach, (If I have gueesed correctly), automatic
> generation of encoders and decoders have good and weak sides. It
> probably generates code with better I/O performance (since for every
> type of message, there will be an encoder-decoder generated
> automatically, reading and writing directly to mina byte buffers. But
> generating code has always drawbacks, difficult to maintain and
> implement and sometimes considered as an anti pattern. I hope they
> achieve good results and share their results with us.
>
> regards
> Mehmet
>

Re: Demuxing Tutorials

Posted by "Mehmet D. AKIN" <md...@gmail.com>.
On 7/24/07, Trustin Lee <tr...@gmail.com> wrote:
> Hi Rodrigo,
>
> On 7/24/07, Rodrigo Madera <ro...@gmail.com> wrote:
> > Please tell me this wheel is invented and ready in MINA!!
> >
> > Here is the scenario taking as an example the SumUp server (the closest
> > thing to the case).
> > Let's suppose there is this project called MegaMath, which is kind of like
> > SumUp but has more operations:
> >
> > public class MegaMathMessage {
> >     private byte opcode;
> >
> >     MegaMathMessage(opcode) {
> >         this.opcode = opcode;
> >     }
> >
> >     ...
> > }
> >
> > public class MultiplyMessage extends MegaMathMessage {
> >     private byte operand0;
> >
> >     MultiplyMessage()
> >     {
> >         super(Constants.MULTIPLY_OPCODE);
> >         ...
> >     }
> >
> >     ...
> > }
> >
> > public class DoSomethingReallyNiceWithThreeArguments {
> >     private int arg0;
> >     private short arg1;
> >     private byte arg3;
> >
> >     // ... initialize with ctor etc...
> > }
> >
> > Now that we have the variable parameter quantity messages, we could write
> > the decoders and encoders, but that's not nice.
> >
> > So the part we are writing let's us do basically this:
> >
> >     NiceEngine.register(MultiplyMessage.class);
> >     NiceEngine.register(SingASongMessage.class);
> >     NiceEngine.register(DanceMessage.class);
> >
> >     MessageEncoder multiplyMessageDecoder =
> > NiceEngine.getDecoder("MultiplyMessage");
> > // classname or class can be used here.
> >     MessageDecoder multiplyMessageEncoder = Nice... you get the point...
> >
> > Is this available?
>
> It's not available.  I think it's difficult to generalize.
>
> > The problem is that manually creating Decoders and Encoders is just a waste
> > of time. This should be a machine's work, and this is what our design is
> > promissing to aid us in.
> >
> > We tried using Javastruct, and even devoted three full days to writing code
> > for it, but we came to the conclusion that we needed more and in a more
> > structured manner, so we started this solution.
> >
> > If this is already implemented, please share some light on how to use it.
>
> You could forward your feedback about JavaStruct to Mehmet so he can
> evolve it on and on. :)
>
> Thanks,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>


Hi,

I agree with Rodrigo on writing protocol encoders and decoders is
quite tedious job. That was the reason I was thinking something like
JavaStruct might help on these situations. He also helped me to find
some bugs and had some nice insight on the architecture. Thanks a lot.

Although Rodrigo and his team found JavaStruct is not enough to handle
their problems, I still have a feeling that JavaStruct can be helpful
on many situations. Please look at the example codes below. There are
two examples, an Adobe Photoshop color book binary file reader -
writer and a Mina example. Mina example is based on the nice protocol
encoder-decoder tutorial on the wiki and it is not complete yet, but
if you look at the code you will get the idea.

Examples: http://javastruct.googlecode.com/svn/trunk/javastruct/samples/

I also updated how-to documnent in the wiki. there is also usable 0.1
jar in the downloads section.

IMHO, Rodrigo's approach, (If I have gueesed correctly), automatic
generation of encoders and decoders have good and weak sides. It
probably generates code with better I/O performance (since for every
type of message, there will be an encoder-decoder generated
automatically, reading and writing directly to mina byte buffers. But
generating code has always drawbacks, difficult to maintain and
implement and sometimes considered as an anti pattern. I hope they
achieve good results and share their results with us.

regards
Mehmet

Re: Demuxing Tutorials

Posted by Trustin Lee <tr...@gmail.com>.
Hi Rodrigo,

On 7/24/07, Rodrigo Madera <ro...@gmail.com> wrote:
> Please tell me this wheel is invented and ready in MINA!!
>
> Here is the scenario taking as an example the SumUp server (the closest
> thing to the case).
> Let's suppose there is this project called MegaMath, which is kind of like
> SumUp but has more operations:
>
> public class MegaMathMessage {
>     private byte opcode;
>
>     MegaMathMessage(opcode) {
>         this.opcode = opcode;
>     }
>
>     ...
> }
>
> public class MultiplyMessage extends MegaMathMessage {
>     private byte operand0;
>
>     MultiplyMessage()
>     {
>         super(Constants.MULTIPLY_OPCODE);
>         ...
>     }
>
>     ...
> }
>
> public class DoSomethingReallyNiceWithThreeArguments {
>     private int arg0;
>     private short arg1;
>     private byte arg3;
>
>     // ... initialize with ctor etc...
> }
>
> Now that we have the variable parameter quantity messages, we could write
> the decoders and encoders, but that's not nice.
>
> So the part we are writing let's us do basically this:
>
>     NiceEngine.register(MultiplyMessage.class);
>     NiceEngine.register(SingASongMessage.class);
>     NiceEngine.register(DanceMessage.class);
>
>     MessageEncoder multiplyMessageDecoder =
> NiceEngine.getDecoder("MultiplyMessage");
> // classname or class can be used here.
>     MessageDecoder multiplyMessageEncoder = Nice... you get the point...
>
> Is this available?

It's not available.  I think it's difficult to generalize.

> The problem is that manually creating Decoders and Encoders is just a waste
> of time. This should be a machine's work, and this is what our design is
> promissing to aid us in.
>
> We tried using Javastruct, and even devoted three full days to writing code
> for it, but we came to the conclusion that we needed more and in a more
> structured manner, so we started this solution.
>
> If this is already implemented, please share some light on how to use it.

You could forward your feedback about JavaStruct to Mehmet so he can
evolve it on and on. :)

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

Re: Demuxing Tutorials

Posted by Rodrigo Madera <ro...@gmail.com>.
Please tell me this wheel is invented and ready in MINA!!

Here is the scenario taking as an example the SumUp server (the closest
thing to the case).
Let's suppose there is this project called MegaMath, which is kind of like
SumUp but has more operations:

public class MegaMathMessage {
    private byte opcode;

    MegaMathMessage(opcode) {
        this.opcode = opcode;
    }

    ...
}

public class MultiplyMessage extends MegaMathMessage {
    private byte operand0;

    MultiplyMessage()
    {
        super(Constants.MULTIPLY_OPCODE);
        ...
    }

    ...
}

public class DoSomethingReallyNiceWithThreeArguments {
    private int arg0;
    private short arg1;
    private byte arg3;

    // ... initialize with ctor etc...
}

Now that we have the variable parameter quantity messages, we could write
the decoders and encoders, but that's not nice.

So the part we are writing let's us do basically this:

    NiceEngine.register(MultiplyMessage.class);
    NiceEngine.register(SingASongMessage.class);
    NiceEngine.register(DanceMessage.class);

    MessageEncoder multiplyMessageDecoder =
NiceEngine.getDecoder("MultiplyMessage");
// classname or class can be used here.
    MessageDecoder multiplyMessageEncoder = Nice... you get the point...

Is this available?

The problem is that manually creating Decoders and Encoders is just a waste
of time. This should be a machine's work, and this is what our design is
promissing to aid us in.

We tried using Javastruct, and even devoted three full days to writing code
for it, but we came to the conclusion that we needed more and in a more
structured manner, so we started this solution.

If this is already implemented, please share some light on how to use it.

Thanks,
Rodrigo


On 7/23/07, Trustin Lee <tr...@gmail.com> wrote:
>
> On 7/23/07, Rodrigo Madera <ro...@gmail.com> wrote:
> > Hello Maarten,
> >
> > I'm familiar with it, thanks.
> >
> > The thing is that I'm in the middle of implementing some engines, and I
> > don't realize the full power of the demuxer yet.
> >
> > I was hoping to see more info on it so I don't happen to reinvent the
> wheel.
>
> What wheel are you going to invent?  We could tell you how to
> implement a certain protocol message using
> DemuxingProtocolCodecFactory if you can give us the specific use case.
>
> HTH,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>

Re: Demuxing Tutorials

Posted by Trustin Lee <tr...@gmail.com>.
On 7/23/07, Rodrigo Madera <ro...@gmail.com> wrote:
> Hello Maarten,
>
> I'm familiar with it, thanks.
>
> The thing is that I'm in the middle of implementing some engines, and I
> don't realize the full power of the demuxer yet.
>
> I was hoping to see more info on it so I don't happen to reinvent the wheel.

What wheel are you going to invent?  We could tell you how to
implement a certain protocol message using
DemuxingProtocolCodecFactory if you can give us the specific use case.

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

Re: Demuxing Tutorials

Posted by Rodrigo Madera <ro...@gmail.com>.
Hello Maarten,

I'm familiar with it, thanks.

The thing is that I'm in the middle of implementing some engines, and I
don't realize the full power of the demuxer yet.

I was hoping to see more info on it so I don't happen to reinvent the wheel.

Thanks for your input though.

Rodrigo

On 7/23/07, Maarten Bosteels <mb...@gmail.com> wrote:
>
> Hi Rodrigo,
>
> The note on the bottom is from me, but I haven't found the time yet to add
> the Demuxing tutorial.
>
> You could take a look at the SumUp example:
>
> http://svn.apache.org/viewvc/mina/branches/1.0/example/src/main/java/org/apache/mina/example/sumup/
>
> Maarten
>
> On 7/23/07, Rodrigo Madera <ro...@gmail.com> wrote:
> >
> > Hello all,
> >
> > I was wondering if anyone has any introductory material on MINA's
> Demuxing
> > implementation.
> >
> > On the "Tutorial on ProtocolCodecFilter" page there is a note on the
> > bottom
> > that this would possibly be added.
> >
> > If anyone has a pointer, please share!
> >
> > Thank you,
> > Rodrigo
> >
>

Re: Demuxing Tutorials

Posted by Maarten Bosteels <mb...@gmail.com>.
Hi Rodrigo,

The note on the bottom is from me, but I haven't found the time yet to add
the Demuxing tutorial.

You could take a look at the SumUp example:
http://svn.apache.org/viewvc/mina/branches/1.0/example/src/main/java/org/apache/mina/example/sumup/

Maarten

On 7/23/07, Rodrigo Madera <ro...@gmail.com> wrote:
>
> Hello all,
>
> I was wondering if anyone has any introductory material on MINA's Demuxing
> implementation.
>
> On the "Tutorial on ProtocolCodecFilter" page there is a note on the
> bottom
> that this would possibly be added.
>
> If anyone has a pointer, please share!
>
> Thank you,
> Rodrigo
>