You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Ashish <pa...@gmail.com> on 2009/11/26 11:25:57 UTC

[MINA 3.0] Initial thoughts on FilterChain

Have started looking into the FilterChain implementation and here are
some initial thoughts

1. Rename IoFilterChain as IoChannel - it gives a more clear picture
and is easy to understand like imagine as a Channel with multiple
stages aka IoFilters.
This came while I was drawing on paper to design something.

2. Have captured a couple of API's that are core to IoChannel

              IoSession getSession();

              IoFilter getHead();

              IoFilter getNextFilter(IoFilter currentFilter);

              List<IoFilter> getAll();

              void addFilter(String name, IoFilter filter);

              void addAfter(String baseName, String filterName,
IoFilter filter);

              void removeFilter(String filterName);

There are a lot more API's in current implementation. I am not sure if
we need replace API or not.
Also do we need the Generics version of these API's or its fine without them?

This is just the initial list. Will checkin the files once the name
change is OK with everyone.

-- 
thanks
ashish

Blog: http://www.ashishpaliwal.com/blog
My Photo Galleries: http://www.pbase.com/ashishpaliwal

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Julien Vermillard <jv...@archean.fr>.
Le Thu, 26 Nov 2009 16:01:32 +0100,
Norman Maurer <no...@googlemail.com> a écrit :

> Well I'm not a MINA committer but I would keep the "Filter" naming.
> Like Emanuell said, its a well known "pattern".
> 
> Bye,
> Norman

Hey :) If some opinion matter on methods and class name, it's the
users one more than the committers one.

Thanks for the feedback.

Julien

> 
> 2009/11/26 Julien Vermillard <jv...@archean.fr>:
> > Le Thu, 26 Nov 2009 15:55:57 +0530,
> > Ashish <pa...@gmail.com> a écrit :
> >
> >> Have started looking into the FilterChain implementation and here
> >> are some initial thoughts
> >>
> >> 1. Rename IoFilterChain as IoChannel - it gives a more clear
> >> picture and is easy to understand like imagine as a Channel with
> >> multiple stages aka IoFilters.
> >> This came while I was drawing on paper to design something.
> >
> >
> > I propose IoPipe/IoPipeline, because for me a bunch of filter
> > stacked on each other is a Pipe in the Unix meaning.
> >
> >
> >>
> >> 2. Have captured a couple of API's that are core to IoChannel
> >>
> >>               IoSession getSession();
> >>
> >>               IoFilter getHead();
> >>
> >>               IoFilter getNextFilter(IoFilter currentFilter);
> >>
> >>               List<IoFilter> getAll();
> >>
> >>               void addFilter(String name, IoFilter filter);
> >>
> >>               void addAfter(String baseName, String filterName,
> >> IoFilter filter);
> >>
> >>               void removeFilter(String filterName);
> >>
> >> There are a lot more API's in current implementation. I am not
> >> sure if we need replace API or not.
> >> Also do we need the Generics version of these API's or its fine
> >> without them?
> >>
> >> This is just the initial list. Will checkin the files once the name
> >> change is OK with everyone.
> >>
> >

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Nov 27, 2009, at 12:39 AM, Ashish wrote:

>> they are not recent). Here they are.
>>
>> First, let's start with what we really need :
>> o A chain has a start
>
> Yup, very much needed
>
>> o A chain has an end
>
> Very logical. Do we need a marker end of chain or if we don't get next
> filter, we assume its the end?

I would be very much against  markers as they clutter up the API.  I'm  
relatively new here, what purpose would they serve?

>> o Both start and end are Filter instances
>
> Very much true. Again to point to bullet 2. Do we need these start and
> end to be marker Filters and we add them explicitly in the chain.
>
> From the discussion on MINA 3.0 design page, it seems we want to get
> rid of Head and Tail filter.



>> o We have as many filters as we need in the chain
>> o Filters can be added or removed dynamically
>
> Hmm.. here I would like to add, that if the chain is modifiable
>
>> o A chain is instanciated for each session (if we have 10K  
>> sessions, we have
>> 10K instances of chain)
>
> Agreed. But is there a possibility to have it only for mutable chains.
> Say if a Chain is static (User's choice), we may choose not to create
> so many instances. Although we need to see how much complexity it adds
> to our implementation.
>
>> o A filter can be activated (enabled) or disabled, dynamically
>
> So its a convenience for User, rather than removing and adding
> filter's, temporarily change the state.
>
>
>> That being said, we have many ways to implement such a mechanism.  
>> let's
>> consider we are in a Filter, and we want to call the next filter.  
>> We have
>> three options here :
>> * The NextFilter is already computed, and is a part of the Filter's  
>> data.
>> This resolves to a direct call :
>>  ...
>>  nextFilter.<action>( params );
>>  ...
>>
>> * The NextFilter is computed dynamically :
>>  ...
>>  nextFilter = computeNext( params );
>>  nextFilter.<action>( params );
>>  ...
>>
>> * The nextFilter is computed by the caller, and is a parameter :
>>
>> public void <action>( Filter nextFilter, <other params>... ) {
>>  ...
>>  nextFilter.<action>( params );
>>  ...
>>
>> The current version (2.0) implements the third form. From the  
>> debugging PoV,
>> it's a nightmare, as you have to step through many intermediate  
>> calls (in
>> fact, an other call for each filter). The StackTrace is heavy. The  
>> next
>> filter is not known when you are in a Filter, as it's computed  
>> outside of
>> the current method.
>>
>> The first approach is way simpler, as is the second one.
>>
>> Let's go a bit deeper : if there is an executor in the chain,  
>> suddenly
>> things get a bit muddy. The "one session = one chain instance" is  
>> still
>> correct, but we may have two (or more) messages being processed on  
>> one
>> session on the same chain. If the chain is dynamically modified,  
>> then it may
>> be ok for the thread modifying the chain, but not for the other  
>> threads.
>> Here is a picture describing this mechanism :
>>
>>
>> Thread1                                                  /--->
>> [Filter3]--->[tail]
>> Thread2 [head]---> [filter1]--->[filter2]--->[executor]-*---->
>> [Filter3]--->[tail]
>> Thread3                                                  \--->
>> [Filter3]--->[tail]
>>
>> Now, if the Thread 2 modify the chain to add a Filter4, then there  
>> is no
>> guarantee that Thread1 will call it. That means we must protect the  
>> chain
>> against concurrent modifications.
>>
>> Another drawback of the first approach is that you must declare an  
>> instance
>> of a Filter for your chain, as it carries some information specific  
>> to your
>> session. We would rather have a stateless Filter...
>>
>> The second approach require an external system to give you the next  
>> filter.
>> It can be the session, which is passed as a parameter for each filter
>> call.In this case, if the external system is protected against  
>> concurrent
>> modifications, then we are safe (except if we want each thread to  
>> define its
>> own chain in the previous example... In this case, the executor  
>> must be
>> responsible for the chain duplication, and probably store it in a
>> ThreadLocal variable )
>>
>> Not that simple...
>>
>> Thoughts ?
>
> I am still kinda looking at 2nd approach. Though I am not very much
> sure about the whole design as of now.
>
> There is one more thing, related to stateful filters. How do we take
> care of them.

IoFilters could get passed an invocation context which would allow  
them to store their state.  This context would also have the IoSession  
that's currently being processed.  But now that I think about it, if  
these things are stateless, in that they store their values in the  
session, they why not have them be POJOs whose values are injected in  
when something needs to be processed.


public class Foo implements IoFilter
{
     private IoSession ioSession;
     private String bar;

     public void setIoSession(IoSession ioSession)
     {
         this.ioSession = ioSession;
     }

     public void setBar(String bar)
     {
         this.bar = bar;
     }

     void messageReceived(Object message)
     {
     }

     public String getBar()
     {
         return bar;
     }
}

Here, since there's a getter, the system would now to store "bar" into  
the IoSession for Foo, or other filters, to subsequently use.



Regards,
Alan


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Ashish <pa...@gmail.com>.
>>> o We have as many filters as we need in the chain
>>> o Filters can be added or removed dynamically
>>
>> Hmm.. here I would like to add, that if the chain is modifiable
>
> Seems like you started a sentence, but were disturbed and never finished it ;)

Oh its covered below, was just punching in that for static chains, we
need not copy them :)
Well I thought I had a solution and later realized that its not going
to be a walk in the Park :-)

>>> o A chain is instanciated for each session (if we have 10K sessions, we have
>>> 10K instances of chain)
>>
>> Agreed. But is there a possibility to have it only for mutable chains.
>> Say if a Chain is static (User's choice), we may choose not to create
>> so many instances. Although we need to see how much complexity it adds
>> to our implementation.
>
> Yeah, exactly. I forgot to mention that.
>
>
>> There is one more thing, related to stateful filters. How do we take
>> care of them.
>
> Good question...
>
> The problem is how do we handle state selection. The previous
> discussion exposed the transition mechanism, not the selection.
> Obvioulsy, depending on the approach (1 2 or 3), the way we handle the
> next filter selection will not be implemented the same way. To me,
> approach 2 is the more versatile...

Agreed. Let me scratch my head a bit more.

-- 
thanks
ashish

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Emmanuel Lecharny <el...@apache.org>.
On Fri, Nov 27, 2009 at 9:39 AM, Ashish <pa...@gmail.com> wrote:
>> they are not recent). Here they are.
>>
>> First, let's start with what we really need :
>> o A chain has a start
>
> Yup, very much needed
>
>> o A chain has an end
>
> Very logical. Do we need a marker end of chain or if we don't get next
> filter, we assume its the end?

IMO, The IoHanlder (which inherit from IoFilter) is the end. The
underlying question is : should we get rid of the Head and Tail filter
we are currently use, as they are most certainly useless.

>
>> o Both start and end are Filter instances
>
> Very much true. Again to point to bullet 2. Do we need these start and
> end to be marker Filters and we add them explicitly in the chain.

se above


> From the discussion on MINA 3.0 design page, it seems we want to get
> rid of Head and Tail filter.

Yes.


>> o We have as many filters as we need in the chain
>> o Filters can be added or removed dynamically
>
> Hmm.. here I would like to add, that if the chain is modifiable

Seems like you started a sentence, but were disturbed and never finished it ;)


>> o A chain is instanciated for each session (if we have 10K sessions, we have
>> 10K instances of chain)
>
> Agreed. But is there a possibility to have it only for mutable chains.
> Say if a Chain is static (User's choice), we may choose not to create
> so many instances. Although we need to see how much complexity it adds
> to our implementation.

Yeah, exactly. I forgot to mention that.


> There is one more thing, related to stateful filters. How do we take
> care of them.

Good question...

The problem is how do we handle state selection. The previous
discussion exposed the transition mechanism, not the selection.
Obvioulsy, depending on the approach (1 2 or 3), the way we handle the
next filter selection will not be implemented the same way. To me,
approach 2 is the more versatile...


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Ashish <pa...@gmail.com>.
> they are not recent). Here they are.
>
> First, let's start with what we really need :
> o A chain has a start

Yup, very much needed

> o A chain has an end

Very logical. Do we need a marker end of chain or if we don't get next
filter, we assume its the end?

> o Both start and end are Filter instances

Very much true. Again to point to bullet 2. Do we need these start and
end to be marker Filters and we add them explicitly in the chain.

>From the discussion on MINA 3.0 design page, it seems we want to get
rid of Head and Tail filter.

> o We have as many filters as we need in the chain
> o Filters can be added or removed dynamically

Hmm.. here I would like to add, that if the chain is modifiable

> o A chain is instanciated for each session (if we have 10K sessions, we have
> 10K instances of chain)

Agreed. But is there a possibility to have it only for mutable chains.
Say if a Chain is static (User's choice), we may choose not to create
so many instances. Although we need to see how much complexity it adds
to our implementation.

> o A filter can be activated (enabled) or disabled, dynamically

So its a convenience for User, rather than removing and adding
filter's, temporarily change the state.


> That being said, we have many ways to implement such a mechanism. let's
> consider we are in a Filter, and we want to call the next filter. We have
> three options here :
> * The NextFilter is already computed, and is a part of the Filter's data.
> This resolves to a direct call :
>  ...
>  nextFilter.<action>( params );
>  ...
>
> * The NextFilter is computed dynamically :
>  ...
>  nextFilter = computeNext( params );
>  nextFilter.<action>( params );
>  ...
>
> * The nextFilter is computed by the caller, and is a parameter :
>
> public void <action>( Filter nextFilter, <other params>... ) {
>  ...
>  nextFilter.<action>( params );
>  ...
>
> The current version (2.0) implements the third form. From the debugging PoV,
> it's a nightmare, as you have to step through many intermediate calls (in
> fact, an other call for each filter). The StackTrace is heavy. The next
> filter is not known when you are in a Filter, as it's computed outside of
> the current method.
>
> The first approach is way simpler, as is the second one.
>
> Let's go a bit deeper : if there is an executor in the chain, suddenly
> things get a bit muddy. The "one session = one chain instance" is still
> correct, but we may have two (or more) messages being processed on one
> session on the same chain. If the chain is dynamically modified, then it may
> be ok for the thread modifying the chain, but not for the other threads.
> Here is a picture describing this mechanism :
>
>
> Thread1                                                  /--->
> [Filter3]--->[tail]
> Thread2 [head]---> [filter1]--->[filter2]--->[executor]-*---->
> [Filter3]--->[tail]
> Thread3                                                  \--->
> [Filter3]--->[tail]
>
> Now, if the Thread 2 modify the chain to add a Filter4, then there is no
> guarantee that Thread1 will call it. That means we must protect the chain
> against concurrent modifications.
>
> Another drawback of the first approach is that you must declare an instance
> of a Filter for your chain, as it carries some information specific to your
> session. We would rather have a stateless Filter...
>
> The second approach require an external system to give you the next filter.
> It can be the session, which is passed as a parameter for each filter
> call.In this case, if the external system is protected against concurrent
> modifications, then we are safe (except if we want each thread to define its
> own chain in the previous example... In this case, the executor must be
> responsible for the chain duplication, and probably store it in a
> ThreadLocal variable )
>
> Not that simple...
>
> Thoughts ?

I am still kinda looking at 2nd approach. Though I am not very much
sure about the whole design as of now.

There is one more thing, related to stateful filters. How do we take
care of them.

Seems I am back to where I started :-)

Time to get back to white board.

-- 
thanks
ashish

Blog: http://www.ashishpaliwal.com/blog
My Photo Galleries: http://www.pbase.com/ashishpaliwal

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Nov 27, 2009, at 9:26 AM, Emmanuel Lecharny wrote:

> On Fri, Nov 27, 2009 at 5:28 PM, Alan D. Cabrera  
> <li...@toolazydogs.com> wrote:
>>
>> On Nov 26, 2009, at 7:51 AM, Emmanuel Lecharny wrote:
>>
>>> About the Filters and the Chain, I also have some initial thoughts  
>>> (even
>>> if they are not recent). Here they are.
>>>
>>> First, let's start with what we really need :
>>> o A chain has a start
>>> o A chain has an end
>>> o Both start and end are Filter instances
>>> o We have as many filters as we need in the chain
>>> o Filters can be added or removed dynamically
>>> o A chain is instanciated for each session (if we have 10K  
>>> sessions, we
>>> have 10K instances of chain)
>>> o A filter can be activated (enabled) or disabled, dynamically
>>>
>>> That being said, we have many ways to implement such a mechanism.  
>>> let's
>>> consider we are in a Filter, and we want to call the next filter.  
>>> We have
>>> three options here :
>>> * The NextFilter is already computed, and is a part of the  
>>> Filter's data.
>>> This resolves to a direct call :
>>> ...
>>> nextFilter.<action>( params );
>>> ...
>>>
>>> * The NextFilter is computed dynamically :
>>> ...
>>> nextFilter = computeNext( params );
>>> nextFilter.<action>( params );
>>> ...
>>>
>>> * The nextFilter is computed by the caller, and is a parameter :
>>>
>>> public void <action>( Filter nextFilter, <other params>... ) {
>>> ...
>>> nextFilter.<action>( params );
>>> ...
>>>
>>> The current version (2.0) implements the third form. From the  
>>> debugging
>>> PoV, it's a nightmare, as you have to step through many  
>>> intermediate calls
>>> (in fact, an other call for each filter). The StackTrace is heavy.  
>>> The next
>>> filter is not known when you are in a Filter, as it's computed  
>>> outside of
>>> the current method.
>>>
>>> The first approach is way simpler, as is the second one.
>>>
>>> Let's go a bit deeper : if there is an executor in the chain,  
>>> suddenly
>>> things get a bit muddy. The "one session = one chain instance" is  
>>> still
>>> correct, but we may have two (or more) messages being processed on  
>>> one
>>> session on the same chain. If the chain is dynamically modified,  
>>> then it may
>>> be ok for the thread modifying the chain, but not for the other  
>>> threads.
>>> Here is a picture describing this mechanism :
>>>
>>>
>>> Thread1                                                  /--->
>>> [Filter3]--->[tail]
>>> Thread2 [head]---> [filter1]--->[filter2]--->[executor]-*---->
>>> [Filter3]--->[tail]
>>> Thread3                                                  \--->
>>> [Filter3]--->[tail]
>>
>> Whoa.  Look at that ascii art.  No wonder your Dell had an  
>> aneurism.  ;)
>>
>>> Now, if the Thread 2 modify the chain to add a Filter4, then there  
>>> is no
>>> guarantee that Thread1 will call it. That means we must protect  
>>> the chain
>>> against concurrent modifications.
>>>
>>> Another drawback of the first approach is that you must declare an
>>> instance of a Filter for your chain, as it carries some  
>>> information specific
>>> to your session. We would rather have a stateless Filter...
>>>
>>> The second approach require an external system to give you the next
>>> filter. It can be the session, which is passed as a parameter for  
>>> each
>>> filter call.In this case, if the external system is protected  
>>> against
>>> concurrent modifications, then we are safe (except if we want each  
>>> thread to
>>> define its own chain in the previous example... In this case, the  
>>> executor
>>> must be responsible for the chain duplication, and probably store  
>>> it in a
>>> ThreadLocal variable )
>>
>> In the second approach, won't we end up with the same problems as  
>> Mina 2.0,
>> "From the debugging PoV, it's a nightmare, as you have to step  
>> through many
>> intermediate calls (in fact, an other call for each filter). The  
>> StackTrace
>> is heavy. The next filter is not known when you are in a Filter, as  
>> it's
>> computed outside of the current method"?
>
> No : the next is computed inside the method :
>
> ...
> nextFilter = computeNext( params );
> nextFilter.<action>( params );
> ...
>
> so you can immediately know which is the next filter (as it's stored
> in the nextFilter variable) and you don't have one more call in the
> stack, as once you get the nextFilter, you are done. This was not the
> case in MINA 2.0, because the computation was delegated to an
> intermediate object.
>
>
>> To make things clear in my mind, where would we need such a feature?
>
> If you get a message that can be decoded in many different ways, for
> instance, depending on the first byte (just an exemple). The
> computeNext method can take some parameter, and returns the next
> filter, depending on the context. Ok, at the end of the day, it's a
> state machine :)
>
>>  Couldn't we just load all the filters in the chain and they decide  
>> whether
>> or not to do anything?
>
> Yes, of course, and we should probably implement most of the protocols
> this way. The idea is to keep the full stuff simple, but allow a user
> to go a bit further if needed. At this point, we may want to offer
> differnt kind of Chain implementation ...


Maybe we could align the design more closely w/ a state machine then  
and make it crazy easy to implement one.

Let IoSession be the state machine.  We could have filters belong to  
various states.  Filter chains would be assembled depending on the  
state of the IoSession.  Any filter can decide the change the state of  
the IoSession for the next message coming down the pipeline.



Regards,
Alan




Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Ashish <pa...@gmail.com>.
>>
>>>> Not necessarily, for three reasons :
>>>> 1) if the chain is fixed at startup, you can't anymore inject a
>>>> LoggingFilter when the server is running. You can only activate or
>>>> desactivate it. Not that it's realy a big issue, but it may help in some
>>>> case (that also mean we have a way to control the execution. JMX ?)
>>>
>>> One normally doesn't turn on and off things like that on a per message
>>> basis.  What I mean by that is that each filter decides to do what it needs
>>> to do.  That includes logging.  Constantly injecting logging filters on an
>>> ad hoc basis is a very, very, poor practice.
>>
>> A very, very rare practice, hopefully :) Here, i'm not sure it worth it
>> anyway. I really think it's better to enable the filter instead of injecting
>> it dynamically. In any case, I'm ready to lose this "feature"...
>
> Agreed, not a very compelling use case.

+1. Enable/Disable a Filter is way better than injecting filter's on
ad-hoc basis.



>>>> 2) Most important, if we don't have a clue about which is the next
>>>> filter in the chain, that leads to problem when debugging, as you can't know
>>>> which filter will be called. Ennoying
>>>
>>> Sure you do.  The chains are fixed.  If you know what filter you are and
>>> what state you're in you know what filter gets called next from the
>>> perspective of the framework.  From the perspective of the filter you
>>> shouldn't care what's next, if you do then you've introduce a brittle
>>> dependency.  For me that;s usually a red flag that I haven't thought through
>>> a design and it needs to be revisited.
>>
>> Let me clarify my mind : when stepping through filters while debugging, I
>> want to be able to jump directly to the next filter. In order to do that,
>> code like :
>>
>> Filter nextFilter = computeNext( session );
>> nextFilter.call( session );
>>
>> is mandatory. I don't want to experiment the same pain as with Spring,
>> when I have to open two editors, one for my java code, and another one to
>> see what is supposed to be my SM. I went through this pain so many times in
>> the past with MINA that I don't want to suffer such a pain again...
>
> Yeah, nothing is more frustrating than stepping though layers of container
> code.  That's why I configure my debugger to skip those chunks of code so it
> lands directly in my POJOs.  Anyway, since the chains are fixed the filter
> dispatching code is quite simple:
>
> Filter current = filterChain[state, i++];
> current.call(session);
>
>
>>>> 3) Last, not least, we want to be able to call the next filter in the
>>>> middle of a processing :
>>>>
>>>> messageReceived() {
>>>> do blah();
>>>> if ( condition ) {
>>>> do anotherBlah();
>>>> call Next filter();
>>>> } else {
>>>> do yetAnotherBlah();
>>>> call nextFilter();
>>>> }
>>>> do endingBlah();
>>>> }
>>>
>>> That just tells me that you have mixed up two states into one and that
>>> you need to expend a little more effort into your state machine design.
>>
>> From the user POV, it's way more easy to write code this way than to
>> create two (or more) states. The idea is to combine the state machine vision
>> with the chain vision. You can express everything with a SM, and implement
>> it in a simpler way...
>
> Easy, yes, initially and if you're the only developer but not so much more
> easier that your point is self evident.  But remember, we all agreed that
> the developer is doing this to create a state machine.  The above code is
> brittle and lacks the explicit states.  I would argue that it's an
> anti-pattern.
>
>>>> Not sure this is possible in another way than with those computed
>>>> nextFilter() inside the filters.
>>>
>>> I agree but it's my contention that it's a bad practice that supports an
>>> ill thought out protocol.
>>
>> The biggest advantage is that it eases the implementor work most of the
>> cases.
>
> IMO, it's sloppy and error prone and obfuscates code.  If no one else agrees
> then I'm happy to drop my point.

Have a request here. Can you help us here with a small POC.
We can compare and have User communities opinion on this.
But let's not just drop it :-)


>> Now, it does not preclude that we should not allow someone to implement
>> his protocol using a complete state machine. May be we should provide both
>> mechanisms :
>> - one which is driven by the code (ie, the code 'pull' the next step),
>> - one which is driven by the state machine (your way).
>
> I would argue against this.  Mina is afflicted w/ bloat.  One the goals
> should be to get rid of as many useless "helpful" classes and methods as we
> can.  Either we all agree that adding filters in an ad hoc manner is a best
> practice for network protocol state machines and we loose the state machine
> or we agree that it's an anti-pattern that should be avoided.  If the
> community thinks that ad hoc filters are a best practice I'm happy to drop
> my point.

-1 for ad-hoc filter addition feature.
We have FtpServer, SSHD, Asyncweb and I believe other's (like Red5)
are hooked to dev list.

We are interested in your voices :-)

-- 
thanks
ashish

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Dec 14, 2009, at 1:19 AM, Emmanuel Lecharny wrote:

> Ashish a écrit :
>>> Agreed, the SM approach should cover all cases; even the logging  
>>> case in
>>> your subsequent post.
>>>
>>> So with that said, would it not make sense to have a set of fixed  
>>> filter
>>> chains w/ each chain representing a state rather than a bucket of  
>>> filters
>>> with each filter deciding the next filter to execute?
>>>
>>
>> Sorry , but I am confused :-(
>> can you help me understand how the Filter chains as a state would  
>> work?
>>
>> Here is a simple Chain. The one with * can be dynamically
>> added/removed. Logging filter could be added at multiple places
>>
>> Acceptor -> BlackList Filter -> Logging Filter* -> Throughput Filter*
>> -> Executor Filter -> Codec -> Logging Filter *
>> ->IoHandler
>>
>> Now how would the suggested approach work??
>>
> If I understand Alan, the idea is that the transitions are managed  
> by the SM handler. As state are static, transitions just depend on  
> th context, so an external engine can call the next state  
> considering the current context. In this case, states don't have to  
> know which is the next state, because it's computed in the SM engine.
>
> It's a typical SM approach, but I'm not sure that it's convenient  
> for us (see my other reply).

Thanks Emmanuel, I think this accurately reflects my thinking.  I  
think that the crux of our discussion lies on the point of whether  
filters need to be injected in an ad hoc fashion.  If so then SM is  
probably not the way to go.

Regards,
Alan


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Emmanuel Lecharny <el...@gmail.com>.
Ashish a écrit :
>> Agreed, the SM approach should cover all cases; even the logging case in
>> your subsequent post.
>>
>> So with that said, would it not make sense to have a set of fixed filter
>> chains w/ each chain representing a state rather than a bucket of filters
>> with each filter deciding the next filter to execute?
>>     
>
> Sorry , but I am confused :-(
> can you help me understand how the Filter chains as a state would work?
>
> Here is a simple Chain. The one with * can be dynamically
> added/removed. Logging filter could be added at multiple places
>
> Acceptor -> BlackList Filter -> Logging Filter* -> Throughput Filter*
> -> Executor Filter -> Codec -> Logging Filter *
> ->IoHandler
>
> Now how would the suggested approach work??
>   
If I understand Alan, the idea is that the transitions are managed by 
the SM handler. As state are static, transitions just depend on th 
context, so an external engine can call the next state considering the 
current context. In this case, states don't have to know which is the 
next state, because it's computed in the SM engine.

It's a typical SM approach, but I'm not sure that it's convenient for us 
(see my other reply).


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com



Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Ashish <pa...@gmail.com>.
On Mon, Dec 14, 2009 at 10:01 PM, Alan D. Cabrera <li...@toolazydogs.com> wrote:
>
> On Dec 13, 2009, at 8:22 PM, Ashish wrote:
>
>>> Agreed, the SM approach should cover all cases; even the logging case in
>>> your subsequent post.
>>>
>>> So with that said, would it not make sense to have a set of fixed filter
>>> chains w/ each chain representing a state rather than a bucket of filters
>>> with each filter deciding the next filter to execute?
>>
>> Sorry , but I am confused :-(
>> can you help me understand how the Filter chains as a state would work?
>>
>> Here is a simple Chain. The one with * can be dynamically
>> added/removed. Logging filter could be added at multiple places
>>
>> Acceptor -> BlackList Filter -> Logging Filter* -> Throughput Filter*
>> -> Executor Filter -> Codec -> Logging Filter *
>> ->IoHandler
>>
>> Now how would the suggested approach work??
>>
>
> By previous posts we agreed that there is no need to dynamically add and
> remove filters in an ad hoc manner; it was merely a mechanism to simulate a
> state machine.   Earlier in this thread we discussed how the state machine
> would fit into the Mina architecture:
>
> It's my opinion that new filters get created to simulate state machine
> changes and any other use is an ad hoc mechanism that can be more cleanly
> refactored into a state machine mechanism.  With that said aa session w/  N
> fixed chains where each chain represents a state would fit the bill.  The
> number of states is fixed.  The composition of the state machine can be
> changed until the acceptor/connector have established the connection.
>
> Acceptor -> ChainMachine -> IoHandler
>
> inside the chain machine:
>
> S1: IOF1 -> IOF2 -> IOF3  -> IOF5 -> IOF4
> S2: IOF1 -> IOF3 -> IOF5 -> IOF4
> S3: IOF1 -> IOF2 -> IOF3 -> IOF4
>
> From a user's perspective things are quite easy to grok and most cases the
> chain machine degenerates into a single state chain.
>
>
> The above state machine supported your example of changing state chains:
>
>             /  IOF->IOF2->IOF3->IOF5->IOF4->IoHandler
> Acceptor->IOF1->X->IOF3->IOF5->IOF4->IoHandler
>             \ IOF1->IOF2->IOF3->X->IOF4->IoHandler
>

Thanks ! Its clear now :-)


-- 
thanks
ashish

Blog: http://www.ashishpaliwal.com/blog
My Photo Galleries: http://www.pbase.com/ashishpaliwal

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Dec 13, 2009, at 8:22 PM, Ashish wrote:

>> Agreed, the SM approach should cover all cases; even the logging  
>> case in
>> your subsequent post.
>>
>> So with that said, would it not make sense to have a set of fixed  
>> filter
>> chains w/ each chain representing a state rather than a bucket of  
>> filters
>> with each filter deciding the next filter to execute?
>
> Sorry , but I am confused :-(
> can you help me understand how the Filter chains as a state would  
> work?
>
> Here is a simple Chain. The one with * can be dynamically
> added/removed. Logging filter could be added at multiple places
>
> Acceptor -> BlackList Filter -> Logging Filter* -> Throughput Filter*
> -> Executor Filter -> Codec -> Logging Filter *
> ->IoHandler
>
> Now how would the suggested approach work??
>

By previous posts we agreed that there is no need to dynamically add  
and remove filters in an ad hoc manner; it was merely a mechanism to  
simulate a state machine.   Earlier in this thread we discussed how  
the state machine would fit into the Mina architecture:

It's my opinion that new filters get created to simulate state machine  
changes and any other use is an ad hoc mechanism that can be more  
cleanly refactored into a state machine mechanism.  With that said aa  
session w/  N fixed chains where each chain represents a state would  
fit the bill.  The number of states is fixed.  The composition of the  
state machine can be changed until the acceptor/connector have  
established the connection.

Acceptor -> ChainMachine -> IoHandler

inside the chain machine:

S1: IOF1 -> IOF2 -> IOF3  -> IOF5 -> IOF4
S2: IOF1 -> IOF3 -> IOF5 -> IOF4
S3: IOF1 -> IOF2 -> IOF3 -> IOF4

 From a user's perspective things are quite easy to grok and most  
cases the chain machine degenerates into a single state chain.


The above state machine supported your example of changing state chains:

              /  IOF->IOF2->IOF3->IOF5->IOF4->IoHandler
Acceptor->IOF1->X->IOF3->IOF5->IOF4->IoHandler
              \ IOF1->IOF2->IOF3->X->IOF4->IoHandler

Regards,
Alan



Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Ashish <pa...@gmail.com>.
> Agreed, the SM approach should cover all cases; even the logging case in
> your subsequent post.
>
> So with that said, would it not make sense to have a set of fixed filter
> chains w/ each chain representing a state rather than a bucket of filters
> with each filter deciding the next filter to execute?

Sorry , but I am confused :-(
can you help me understand how the Filter chains as a state would work?

Here is a simple Chain. The one with * can be dynamically
added/removed. Logging filter could be added at multiple places

Acceptor -> BlackList Filter -> Logging Filter* -> Throughput Filter*
-> Executor Filter -> Codec -> Logging Filter *
->IoHandler

Now how would the suggested approach work??

-- 
thanks
ashish

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Emmanuel LŽcharny <el...@gmail.com>.
To add something to my previous reply, there is one case where the 
'chain' can be dynamically modified : when adding the LoggingFilter for 
debugging purposes. I guess we can think about some other user czses, by 
IMO, they are not so frequent.  MINAOP ? ;)


Alan D. Cabrera a écrit :
>
> On Dec 3, 2009, at 5:28 PM, Ashish wrote:
>
>>>>> What about the assertion that new filters only get created to 
>>>>> simulate a
>>>>> state machine?
>>>>
>>>> Finally, managed to check-in some of the initial thoughts.
>>>> The transition handler or the computeNext function is still to be 
>>>> out in.
>>>
>>> Sorry. Not sure how that answers my question other than to detail what
>>> you've done and what you're about to do.
>>>
>>
>> OOPS! :-(  I think I am getting old
>>
>> After a discussion we thought that we shall make it possible for
>> user's to choose the way we want Filter transitions
>> That's what the transition handler is :-) Default implementation shall
>> be of next Filter in the chain.
>> User's can plugin their implementations for transition say like a
>> State Machine implementation.
>>
>> Since I couldn't take it to logical conclusion, still working on it :)
>> Also my experience with State machines is limited, so will need a
>> helping hand here (or may be some references :-) )
>
> The key thing about state machines is that the states and the 
> transitions are known and fixed ahead of time.  If this our state of 
> affairs, and I think that it is, then things are much more simple and 
> mentally tractable, i.e. there's no ad hoc filter creation during 
> protocol processing and much of the threading issues in past entries 
> on this thread disappear.
>
>
> Regards,
> Alan
>
>
>


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Julien Vermillard <jv...@gmail.com>.
On Fri, Jul 1, 2011 at 5:58 PM, Alan D. Cabrera <li...@toolazydogs.com> wrote:
>
> On Jul 1, 2011, at 8:52 AM, Emmanuel Lecharny wrote:
>
>> On 7/1/11 5:47 PM, Alan D. Cabrera wrote:
>>> On Jul 1, 2011, at 8:04 AM, Emmanuel Lecharny wrote:
>>>> But all in all, in this case, the chain of filters will *be* a state machine.
>>> And here is my point.  They all are really state machines.  Having network protocols "randomly" choosing chain paths is an anti-pattern.  State machines should be known and fixed at the time of protocol initiation.
>>
>> Don't get me wrong... I'm not sure anyone here had in mind an implementation which picks the next filter randomly... Although, that could be funny :)
>
> To everyone but the person who has to debug what's going on.  ;)
>
> With that said, why would we want our API make that possible?  Would we not be doing our user base a service by switching the Mina API to a bona fide state machine with fixed state chains?
>
>
> Regards,
> Alan
>

Hi,
I think it's possible to make FilterChain a simple List of Filters
called by the chain and not-chained as we do.
For special usage where the Filter decide which filter to call, the
filter could be called from the "demuxing" filter :
http://s.apache.org/A9W

The chain could be stored in the IoService and copied to the session
only if it specifically was modified for this session (Copy on write).
It could save some memory.
Now the *REAL QUESTION* is how we implement SEDA/ExecutorFilter with
this kind of list of filter ?
Julien

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Jul 1, 2011, at 8:52 AM, Emmanuel Lecharny wrote:

> On 7/1/11 5:47 PM, Alan D. Cabrera wrote:
>> On Jul 1, 2011, at 8:04 AM, Emmanuel Lecharny wrote:
>>> But all in all, in this case, the chain of filters will *be* a state machine.
>> And here is my point.  They all are really state machines.  Having network protocols "randomly" choosing chain paths is an anti-pattern.  State machines should be known and fixed at the time of protocol initiation.
> 
> Don't get me wrong... I'm not sure anyone here had in mind an implementation which picks the next filter randomly... Although, that could be funny :)

To everyone but the person who has to debug what's going on.  ;)

With that said, why would we want our API make that possible?  Would we not be doing our user base a service by switching the Mina API to a bona fide state machine with fixed state chains?


Regards,
Alan



Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Emmanuel Lecharny <el...@gmail.com>.
On 7/1/11 5:47 PM, Alan D. Cabrera wrote:
> On Jul 1, 2011, at 8:04 AM, Emmanuel Lecharny wrote:
>> But all in all, in this case, the chain of filters will *be* a state machine.
> And here is my point.  They all are really state machines.  Having network protocols "randomly" choosing chain paths is an anti-pattern.  State machines should be known and fixed at the time of protocol initiation.

Don't get me wrong... I'm not sure anyone here had in mind an 
implementation which picks the next filter randomly... Although, that 
could be funny :)
>> I have some ideas (and I even have created some branch years ago: http://svn.apache.org/viewvc/mina/branches/mina-new-chain/ and http://svn.apache.org/viewvc/mina/branches/mina-new-chain2/) to play around this idea.
> I'll take a peek at these.  Thanks!

frankly, those branches are mostly errands at this point. Don't expect 
too much...


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Jul 1, 2011, at 8:04 AM, Emmanuel Lecharny wrote:

> On 7/1/11 4:59 PM, Alan D. Cabrera wrote:
>> On Jun 30, 2011, at 4:13 PM, Emmanuel Lecharny wrote:
>> 
>>> On 6/30/11 9:52 PM, Alan D. Cabrera wrote:
>>>> On Jun 30, 2011, at 2:42 AM, Ashish wrote:
>>>> 
>>>>> <snip/>
>>>>> This does meet some of our requirements, but not all. We can have something
>>>>> similar to this and instead of returning true/false
>>>>> from Filters, we can return the next step to be executed. Something like
>>>>> this
>>>>> 
>>>>> IoFilter messageReceived(IoSession session, Object message) {
>>>>>    // process
>>>>> 
>>>>>   // see if just to flow with Filter Chain
>>>>>   return null; // or something better
>>>>> 
>>>>>   // or
>>>>>   // a diff message detected, calculate next filter based on some app
>>>>> specific state
>>>>>   return calculateNextFilter(state);
>>>>> }
>>>>> 
>>>>> command is passed back to the chain and it can take care of executing the
>>>>> next filter.
>>>>> 
>>>>> Shall try something similar in sandbox and lets see how it goes :)
>>>> I'm not so sure that filters should be in charge of deciding who should be called next.  I don't think that how the filter stack is assembled should be leaked into the filters themselves.  The filter should be solely concerned with its task and not have to decide who gets called next.
>>> Not sure, Alan. There are some cases where it's mandatory that a filter select the next filter to execute : for instance, if your codec produces more than one message, and the following processing may depend on the message type. Of course, you can use a demux protocol filter (I don't exactly remember the name of it, so it's from the top of my head, but we use such a mechanism in ADS), but it's just one option.
>> 
>> I'm hearing a state machine that's implicitly defined via what gets returned by that method.  If this is the case would it not be better to have an explicitly defined state machine?
> 
> Not necessarily. We can think about a multiple layer decoder which works the very same way.

I'm hearing possibility not necessity.

> But all in all, in this case, the chain of filters will *be* a state machine.

And here is my point.  They all are really state machines.  Having network protocols "randomly" choosing chain paths is an anti-pattern.  State machines should be known and fixed at the time of protocol initiation.

> I have some ideas (and I even have created some branch years ago: http://svn.apache.org/viewvc/mina/branches/mina-new-chain/ and http://svn.apache.org/viewvc/mina/branches/mina-new-chain2/) to play around this idea.

I'll take a peek at these.  Thanks!


Regards,
Alan


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Emmanuel Lecharny <el...@gmail.com>.
On 7/1/11 4:59 PM, Alan D. Cabrera wrote:
> On Jun 30, 2011, at 4:13 PM, Emmanuel Lecharny wrote:
>
>> On 6/30/11 9:52 PM, Alan D. Cabrera wrote:
>>> On Jun 30, 2011, at 2:42 AM, Ashish wrote:
>>>
>>>> <snip/>
>>>> This does meet some of our requirements, but not all. We can have something
>>>> similar to this and instead of returning true/false
>>>> from Filters, we can return the next step to be executed. Something like
>>>> this
>>>>
>>>> IoFilter messageReceived(IoSession session, Object message) {
>>>>     // process
>>>>
>>>>    // see if just to flow with Filter Chain
>>>>    return null; // or something better
>>>>
>>>>    // or
>>>>    // a diff message detected, calculate next filter based on some app
>>>> specific state
>>>>    return calculateNextFilter(state);
>>>> }
>>>>
>>>> command is passed back to the chain and it can take care of executing the
>>>> next filter.
>>>>
>>>> Shall try something similar in sandbox and lets see how it goes :)
>>> I'm not so sure that filters should be in charge of deciding who should be called next.  I don't think that how the filter stack is assembled should be leaked into the filters themselves.  The filter should be solely concerned with its task and not have to decide who gets called next.
>> Not sure, Alan. There are some cases where it's mandatory that a filter select the next filter to execute : for instance, if your codec produces more than one message, and the following processing may depend on the message type. Of course, you can use a demux protocol filter (I don't exactly remember the name of it, so it's from the top of my head, but we use such a mechanism in ADS), but it's just one option.
>
> I'm hearing a state machine that's implicitly defined via what gets returned by that method.  If this is the case would it not be better to have an explicitly defined state machine?

Not necessarily. We can think about a multiple layer decoder which works 
the very same way.

But all in all, in this case, the chain of filters will *be* a state 
machine.

I have some ideas (and I even have created some branch years ago: 
http://svn.apache.org/viewvc/mina/branches/mina-new-chain/ and 
http://svn.apache.org/viewvc/mina/branches/mina-new-chain2/) to play 
around this idea.

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Alex Karasulu <ak...@apache.org>.
On Fri, Jul 1, 2011 at 5:59 PM, Alan D. Cabrera <li...@toolazydogs.com> wrote:
>
> On Jun 30, 2011, at 4:13 PM, Emmanuel Lecharny wrote:
>
>> On 6/30/11 9:52 PM, Alan D. Cabrera wrote:
>>> On Jun 30, 2011, at 2:42 AM, Ashish wrote:
>>>
>>>> <snip/>
>>
>>>> This does meet some of our requirements, but not all. We can have something
>>>> similar to this and instead of returning true/false
>>>> from Filters, we can return the next step to be executed. Something like
>>>> this
>>>>
>>>> IoFilter messageReceived(IoSession session, Object message) {
>>>>    // process
>>>>
>>>>   // see if just to flow with Filter Chain
>>>>   return null; // or something better
>>>>
>>>>   // or
>>>>   // a diff message detected, calculate next filter based on some app
>>>> specific state
>>>>   return calculateNextFilter(state);
>>>> }
>>>>
>>>> command is passed back to the chain and it can take care of executing the
>>>> next filter.
>>>>
>>>> Shall try something similar in sandbox and lets see how it goes :)
>>> I'm not so sure that filters should be in charge of deciding who should be called next.  I don't think that how the filter stack is assembled should be leaked into the filters themselves.  The filter should be solely concerned with its task and not have to decide who gets called next.
>>
>> Not sure, Alan. There are some cases where it's mandatory that a filter select the next filter to execute : for instance, if your codec produces more than one message, and the following processing may depend on the message type. Of course, you can use a demux protocol filter (I don't exactly remember the name of it, so it's from the top of my head, but we use such a mechanism in ADS), but it's just one option.
>
>
> I'm hearing a state machine that's implicitly defined via what gets returned by that method.  If this is the case would it not be better to have an explicitly defined state machine?

For simple cases this might "seem" like overkill but IMHO I think it's
better always to be explicit. It's clear what is happening. Surprise
Emmanuel that you did not jump for this you are Mr. State Machine :-).

Regards,
Alex

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Jun 30, 2011, at 4:13 PM, Emmanuel Lecharny wrote:

> On 6/30/11 9:52 PM, Alan D. Cabrera wrote:
>> On Jun 30, 2011, at 2:42 AM, Ashish wrote:
>> 
>>> <snip/>
> 
>>> This does meet some of our requirements, but not all. We can have something
>>> similar to this and instead of returning true/false
>>> from Filters, we can return the next step to be executed. Something like
>>> this
>>> 
>>> IoFilter messageReceived(IoSession session, Object message) {
>>>    // process
>>> 
>>>   // see if just to flow with Filter Chain
>>>   return null; // or something better
>>> 
>>>   // or
>>>   // a diff message detected, calculate next filter based on some app
>>> specific state
>>>   return calculateNextFilter(state);
>>> }
>>> 
>>> command is passed back to the chain and it can take care of executing the
>>> next filter.
>>> 
>>> Shall try something similar in sandbox and lets see how it goes :)
>> I'm not so sure that filters should be in charge of deciding who should be called next.  I don't think that how the filter stack is assembled should be leaked into the filters themselves.  The filter should be solely concerned with its task and not have to decide who gets called next.
> 
> Not sure, Alan. There are some cases where it's mandatory that a filter select the next filter to execute : for instance, if your codec produces more than one message, and the following processing may depend on the message type. Of course, you can use a demux protocol filter (I don't exactly remember the name of it, so it's from the top of my head, but we use such a mechanism in ADS), but it's just one option.


I'm hearing a state machine that's implicitly defined via what gets returned by that method.  If this is the case would it not be better to have an explicitly defined state machine?


Regards,
Alan



Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Emmanuel Lecharny <el...@gmail.com>.
On 6/30/11 9:52 PM, Alan D. Cabrera wrote:
> On Jun 30, 2011, at 2:42 AM, Ashish wrote:
>
>> <snip/>

>> This does meet some of our requirements, but not all. We can have something
>> similar to this and instead of returning true/false
>> from Filters, we can return the next step to be executed. Something like
>> this
>>
>> IoFilter messageReceived(IoSession session, Object message) {
>>     // process
>>
>>    // see if just to flow with Filter Chain
>>    return null; // or something better
>>
>>    // or
>>    // a diff message detected, calculate next filter based on some app
>> specific state
>>    return calculateNextFilter(state);
>> }
>>
>> command is passed back to the chain and it can take care of executing the
>> next filter.
>>
>> Shall try something similar in sandbox and lets see how it goes :)
> I'm not so sure that filters should be in charge of deciding who should be called next.  I don't think that how the filter stack is assembled should be leaked into the filters themselves.  The filter should be solely concerned with its task and not have to decide who gets called next.

Not sure, Alan. There are some cases where it's mandatory that a filter 
select the next filter to execute : for instance, if your codec produces 
more than one message, and the following processing may depend on the 
message type. Of course, you can use a demux protocol filter (I don't 
exactly remember the name of it, so it's from the top of my head, but we 
use such a mechanism in ADS), but it's just one option.


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Jun 30, 2011, at 2:42 AM, Ashish wrote:

> Fortunately was able to find this mail chain in inbox :)
> 
> reigniting the discussion again.
> 
> Was looking for something that meets our needs and landed with Commons Chain
> (http://commons.apache.org/chain/)
> 
> This does meet some of our requirements, but not all. We can have something
> similar to this and instead of returning true/false
> from Filters, we can return the next step to be executed. Something like
> this
> 
> IoFilter messageReceived(IoSession session, Object message) {
>    // process
> 
>   // see if just to flow with Filter Chain
>   return null; // or something better
> 
>   // or
>   // a diff message detected, calculate next filter based on some app
> specific state
>   return calculateNextFilter(state);
> }
> 
> command is passed back to the chain and it can take care of executing the
> next filter.
> 
> Shall try something similar in sandbox and lets see how it goes :)

I'm not so sure that filters should be in charge of deciding who should be called next.  I don't think that how the filter stack is assembled should be leaked into the filters themselves.  The filter should be solely concerned with its task and not have to decide who gets called next.


Regards,
Alan

> 
> thanks
> ashish
> 
> On Tue, Dec 15, 2009 at 9:13 PM, Alan D. Cabrera <li...@toolazydogs.com>wrote:
> 
>> 
>> On Dec 15, 2009, at 4:30 AM, Emmanuel LŽcharny wrote:
>> 
>> Hi,
>>> 
>>> there is another approach if we switch to a SM : actions don't need to
>>> know about the next action, as it's computed by the SM. We can end with
>>> methods like :
>>> 
>>> messageReceived() {
>>> blah
>>> }
>>> 
>> 
>> Yes, this is along the lines of what I was thinking.
>> 
>> 
>> and when the method returns, the SM decide which filter to call next. This
>>> end up with something like :
>>> 
>>> while ( not Done ) {
>>> nextFilter = computeNext(session);
>>> nextFilter.messageReceived(**session);
>>> }
>>> 
>> 
>> This is not much better than what we had before.  The chains should be
>> fixed.
>> 
>> while (!session.closed())
>> {
>>   List<IoFilter> filters = session.getChain(session.**getState());
>>   for (IoFilter filter : filters) filter.messageReceived(**session);
>> 
>> }
>> 
>> 
>>> The only constraints being that we don't have code like :
>>> 
>>> messageReceived(session) {
>>> blah();
>>> call next filter; // Not necessary anymore...
>>> post_blah(); /// Wrong !!!
>>> }
>>> 
>> 
>> Yay!
>> 
>> 
>> Now, why did we used Filters at the origin ? It's important to know that
>>> when Alex thought about what should be MINA 6 years ago, and before Trustin
>>> joined the project, the idea was to implement a SEDA based framework.
>>> 
>>> What does it imply in real world ? Many things. First, transition between
>>> one filter and another should allow the use of a queue, so interactions are
>>> asynchronous. Another aspect is that we may have more than one thread
>>> running on one session (some decoding can occur while a new message is being
>>> received). Another consequence is that we may have unordered messages : if
>>> two threads are being processed for the same session, one can be faster to
>>> decode than the second one, and the second one can perfectly well hit the
>>> Handler before the first one. We have some mchanism to protect the user from
>>> such a problem.
>>> 
>>> Ig we have to keep this SEDA approach, then we must be careful and be sure
>>> that we can process each filter separately. looking at the loop I exposed
>>> above, we will have a problem because the loop is executed sequencially by
>>> one single thread, so we can't anymore implement any SEDA mechanism.
>>> 
>>> If the filter is responsible for the call of the next filter, then it's a
>>> totally different story.
>>> 
>>> We have to think about this before drafting some implementation, and
>>> decide if we want to stick to SEDA.
>>> 
>> 
>> Agreed.  This is something we should support.  I think that the original
>> complexity came from mixing concerns.
>> 
>> What if we had channels that could contain things like queues, state
>> machines, etc.?  Channels would be bidirectional, i.e. messages would move
>> up and down in a single channel.  We would then compose channels in fixed
>> DAGs.
>> 
>> 
>> Now, some comment in line about Alan's last mail
>>> 
>>> Alan D. Cabrera a écrit :
>>> 
>>>> 
>>>> <Snip/>
>>>> 
>>>>> Not sure this is possible in another way than with those computed
>>>>>>> nextFilter() inside the filters.
>>>>>>> 
>>>>>> 
>>>>>> I agree but it's my contention that it's a bad practice that supports
>>>>>> an ill thought out protocol.
>>>>>> 
>>>>> 
>>>>> The biggest advantage is that it eases the implementor work most of the
>>>>> cases.
>>>>> 
>>>> 
>>>> IMO, it's sloppy and error prone and obfuscates code.  If no one else
>>>> agrees then I'm happy to drop my point.
>>>> 
>>> You are probably right. If you look at the existing filters, there is no
>>> reason we should not be able to avoid such code.
>>> 
>>> 
>>>> Now, it does not preclude that we should not allow someone to implement
>>>>> his protocol using a complete state machine. May be we should provide both
>>>>> mechanisms :
>>>>> - one which is driven by the code (ie, the code 'pull' the next step),
>>>>> - one which is driven by the state machine (your way).
>>>>> 
>>>> 
>>>> I would argue against this.  Mina is afflicted w/ bloat.
>>>> 
>>> I can't agree more :)
>>> 
>>> One the goals should be to get rid of as many useless "helpful" classes
>>>> and methods as we can.
>>>> 
>>> +1
>>> 
>>>  Either we all agree that adding filters in an ad hoc manner is a best
>>>> practice for network protocol state machines and we loose the state machine
>>>> or we agree that it's an anti-pattern that should be avoided.  If the
>>>> community thinks that ad hoc filters are a best practice I'm happy to drop
>>>> my point.
>>>> 
>>> I would like to keep the SM approach, but as explained above (SEDA thing),
>>> I think we should be driven by the code.
>>> 
>>> <snip/>
>>>> 
>>>> I totally agree with this approach to deciding on the API and am happy to
>>>> help out w/ some protocols, e.g. HTTP and SSL.
>>>> 
>>>> I am curious, what project feels that it needs to do an "implicit" state
>>>> machine?  I would love to take a peek at the code.
>>>> 
>>> What do you mean by "implicit" state machine ?
>>> 
>> 
>> In the "ad hoc" state transition approach the state transitions are
>> implicit in the code rather than explicit and fixed in a set of data
>> structures.  To understand the implicit state machine one must carefully
>> read all the code to understand what's going on.
>> 
>> 
>> Regards,
>> Alan
>> 
>> 
>> 
> 
> 
> -- 
> thanks
> ashish
> 
> Blog: http://www.ashishpaliwal.com/blog
> My Photo Galleries: http://www.pbase.com/ashishpaliwal


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Ashish <pa...@gmail.com>.
Fortunately was able to find this mail chain in inbox :)

reigniting the discussion again.

Was looking for something that meets our needs and landed with Commons Chain
(http://commons.apache.org/chain/)

This does meet some of our requirements, but not all. We can have something
similar to this and instead of returning true/false
from Filters, we can return the next step to be executed. Something like
this

IoFilter messageReceived(IoSession session, Object message) {
    // process

   // see if just to flow with Filter Chain
   return null; // or something better

   // or
   // a diff message detected, calculate next filter based on some app
specific state
   return calculateNextFilter(state);
}

command is passed back to the chain and it can take care of executing the
next filter.

Shall try something similar in sandbox and lets see how it goes :)

thanks
ashish

On Tue, Dec 15, 2009 at 9:13 PM, Alan D. Cabrera <li...@toolazydogs.com>wrote:

>
> On Dec 15, 2009, at 4:30 AM, Emmanuel LŽcharny wrote:
>
>  Hi,
>>
>> there is another approach if we switch to a SM : actions don't need to
>> know about the next action, as it's computed by the SM. We can end with
>> methods like :
>>
>> messageReceived() {
>> blah
>> }
>>
>
> Yes, this is along the lines of what I was thinking.
>
>
>  and when the method returns, the SM decide which filter to call next. This
>> end up with something like :
>>
>> while ( not Done ) {
>> nextFilter = computeNext(session);
>> nextFilter.messageReceived(**session);
>> }
>>
>
> This is not much better than what we had before.  The chains should be
> fixed.
>
> while (!session.closed())
> {
>    List<IoFilter> filters = session.getChain(session.**getState());
>    for (IoFilter filter : filters) filter.messageReceived(**session);
>
> }
>
>
>> The only constraints being that we don't have code like :
>>
>> messageReceived(session) {
>> blah();
>> call next filter; // Not necessary anymore...
>> post_blah(); /// Wrong !!!
>> }
>>
>
> Yay!
>
>
>  Now, why did we used Filters at the origin ? It's important to know that
>> when Alex thought about what should be MINA 6 years ago, and before Trustin
>> joined the project, the idea was to implement a SEDA based framework.
>>
>> What does it imply in real world ? Many things. First, transition between
>> one filter and another should allow the use of a queue, so interactions are
>> asynchronous. Another aspect is that we may have more than one thread
>> running on one session (some decoding can occur while a new message is being
>> received). Another consequence is that we may have unordered messages : if
>> two threads are being processed for the same session, one can be faster to
>> decode than the second one, and the second one can perfectly well hit the
>> Handler before the first one. We have some mchanism to protect the user from
>> such a problem.
>>
>> Ig we have to keep this SEDA approach, then we must be careful and be sure
>> that we can process each filter separately. looking at the loop I exposed
>> above, we will have a problem because the loop is executed sequencially by
>> one single thread, so we can't anymore implement any SEDA mechanism.
>>
>> If the filter is responsible for the call of the next filter, then it's a
>> totally different story.
>>
>> We have to think about this before drafting some implementation, and
>> decide if we want to stick to SEDA.
>>
>
> Agreed.  This is something we should support.  I think that the original
> complexity came from mixing concerns.
>
> What if we had channels that could contain things like queues, state
> machines, etc.?  Channels would be bidirectional, i.e. messages would move
> up and down in a single channel.  We would then compose channels in fixed
> DAGs.
>
>
>  Now, some comment in line about Alan's last mail
>>
>> Alan D. Cabrera a écrit :
>>
>>>
>>> <Snip/>
>>>
>>>> Not sure this is possible in another way than with those computed
>>>>>> nextFilter() inside the filters.
>>>>>>
>>>>>
>>>>> I agree but it's my contention that it's a bad practice that supports
>>>>> an ill thought out protocol.
>>>>>
>>>>
>>>> The biggest advantage is that it eases the implementor work most of the
>>>> cases.
>>>>
>>>
>>> IMO, it's sloppy and error prone and obfuscates code.  If no one else
>>> agrees then I'm happy to drop my point.
>>>
>> You are probably right. If you look at the existing filters, there is no
>> reason we should not be able to avoid such code.
>>
>>
>>>  Now, it does not preclude that we should not allow someone to implement
>>>> his protocol using a complete state machine. May be we should provide both
>>>> mechanisms :
>>>> - one which is driven by the code (ie, the code 'pull' the next step),
>>>> - one which is driven by the state machine (your way).
>>>>
>>>
>>> I would argue against this.  Mina is afflicted w/ bloat.
>>>
>> I can't agree more :)
>>
>>  One the goals should be to get rid of as many useless "helpful" classes
>>> and methods as we can.
>>>
>> +1
>>
>>   Either we all agree that adding filters in an ad hoc manner is a best
>>> practice for network protocol state machines and we loose the state machine
>>> or we agree that it's an anti-pattern that should be avoided.  If the
>>> community thinks that ad hoc filters are a best practice I'm happy to drop
>>> my point.
>>>
>> I would like to keep the SM approach, but as explained above (SEDA thing),
>> I think we should be driven by the code.
>>
>>  <snip/>
>>>
>>> I totally agree with this approach to deciding on the API and am happy to
>>> help out w/ some protocols, e.g. HTTP and SSL.
>>>
>>> I am curious, what project feels that it needs to do an "implicit" state
>>> machine?  I would love to take a peek at the code.
>>>
>> What do you mean by "implicit" state machine ?
>>
>
> In the "ad hoc" state transition approach the state transitions are
> implicit in the code rather than explicit and fixed in a set of data
> structures.  To understand the implicit state machine one must carefully
> read all the code to understand what's going on.
>
>
> Regards,
> Alan
>
>
>


-- 
thanks
ashish

Blog: http://www.ashishpaliwal.com/blog
My Photo Galleries: http://www.pbase.com/ashishpaliwal

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Dec 15, 2009, at 4:30 AM, Emmanuel LŽcharny wrote:

> Hi,
>
> there is another approach if we switch to a SM : actions don't need  
> to know about the next action, as it's computed by the SM. We can  
> end with methods like :
>
> messageReceived() {
> blah
> }

Yes, this is along the lines of what I was thinking.

> and when the method returns, the SM decide which filter to call  
> next. This end up with something like :
>
> while ( not Done ) {
> nextFilter = computeNext(session);
> nextFilter.messageReceived(session);
> }

This is not much better than what we had before.  The chains should be  
fixed.

while (!session.closed())
{
     List<IoFilter> filters = session.getChain(session.getState());
     for (IoFilter filter : filters) filter.messageReceived(session);
}

>
> The only constraints being that we don't have code like :
>
> messageReceived(session) {
> blah();
> call next filter; // Not necessary anymore...
> post_blah(); /// Wrong !!!
> }

Yay!

> Now, why did we used Filters at the origin ? It's important to know  
> that when Alex thought about what should be MINA 6 years ago, and  
> before Trustin joined the project, the idea was to implement a SEDA  
> based framework.
>
> What does it imply in real world ? Many things. First, transition  
> between one filter and another should allow the use of a queue, so  
> interactions are asynchronous. Another aspect is that we may have  
> more than one thread running on one session (some decoding can occur  
> while a new message is being received). Another consequence is that  
> we may have unordered messages : if two threads are being processed  
> for the same session, one can be faster to decode than the second  
> one, and the second one can perfectly well hit the Handler before  
> the first one. We have some mchanism to protect the user from such a  
> problem.
>
> Ig we have to keep this SEDA approach, then we must be careful and  
> be sure that we can process each filter separately. looking at the  
> loop I exposed above, we will have a problem because the loop is  
> executed sequencially by one single thread, so we can't anymore  
> implement any SEDA mechanism.
>
> If the filter is responsible for the call of the next filter, then  
> it's a totally different story.
>
> We have to think about this before drafting some implementation, and  
> decide if we want to stick to SEDA.

Agreed.  This is something we should support.  I think that the  
original complexity came from mixing concerns.

What if we had channels that could contain things like queues, state  
machines, etc.?  Channels would be bidirectional, i.e. messages would  
move up and down in a single channel.  We would then compose channels  
in fixed DAGs.

> Now, some comment in line about Alan's last mail
>
> Alan D. Cabrera a écrit :
>>
>> <Snip/>
>>>>> Not sure this is possible in another way than with those  
>>>>> computed nextFilter() inside the filters.
>>>>
>>>> I agree but it's my contention that it's a bad practice that  
>>>> supports an ill thought out protocol.
>>>
>>> The biggest advantage is that it eases the implementor work most  
>>> of the cases.
>>
>> IMO, it's sloppy and error prone and obfuscates code.  If no one  
>> else agrees then I'm happy to drop my point.
> You are probably right. If you look at the existing filters, there  
> is no reason we should not be able to avoid such code.
>
>>
>>> Now, it does not preclude that we should not allow someone to  
>>> implement his protocol using a complete state machine. May be we  
>>> should provide both mechanisms :
>>> - one which is driven by the code (ie, the code 'pull' the next  
>>> step),
>>> - one which is driven by the state machine (your way).
>>
>> I would argue against this.  Mina is afflicted w/ bloat.
> I can't agree more :)
>
>> One the goals should be to get rid of as many useless "helpful"  
>> classes and methods as we can.
> +1
>
>>  Either we all agree that adding filters in an ad hoc manner is a  
>> best practice for network protocol state machines and we loose the  
>> state machine or we agree that it's an anti-pattern that should be  
>> avoided.  If the community thinks that ad hoc filters are a best  
>> practice I'm happy to drop my point.
> I would like to keep the SM approach, but as explained above (SEDA  
> thing), I think we should be driven by the code.
>
>> <snip/>
>>
>> I totally agree with this approach to deciding on the API and am  
>> happy to help out w/ some protocols, e.g. HTTP and SSL.
>>
>> I am curious, what project feels that it needs to do an "implicit"  
>> state machine?  I would love to take a peek at the code.
> What do you mean by "implicit" state machine ?

In the "ad hoc" state transition approach the state transitions are  
implicit in the code rather than explicit and fixed in a set of data  
structures.  To understand the implicit state machine one must  
carefully read all the code to understand what's going on.


Regards,
Alan



Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Emmanuel LŽcharny <el...@gmail.com>.
Hi,

there is another approach if we switch to a SM : actions don't need to 
know about the next action, as it's computed by the SM. We can end with 
methods like :

messageReceived() {
  blah
}

and when the method returns, the SM decide which filter to call next. 
This end up with something like :

while ( not Done ) {
  nextFilter = computeNext(session);
  nextFilter.messageReceived(session);
}

The only constraints being that we don't have code like :

messageReceived(session) {
  blah();
  call next filter; // Not necessary anymore...
  post_blah(); /// Wrong !!!
}

Now, why did we used Filters at the origin ? It's important to know that 
when Alex thought about what should be MINA 6 years ago, and before 
Trustin joined the project, the idea was to implement a SEDA based 
framework.

What does it imply in real world ? Many things. First, transition 
between one filter and another should allow the use of a queue, so 
interactions are asynchronous. Another aspect is that we may have more 
than one thread running on one session (some decoding can occur while a 
new message is being received). Another consequence is that we may have 
unordered messages : if two threads are being processed for the same 
session, one can be faster to decode than the second one, and the second 
one can perfectly well hit the Handler before the first one. We have 
some mchanism to protect the user from such a problem.

Ig we have to keep this SEDA approach, then we must be careful and be 
sure that we can process each filter separately. looking at the loop I 
exposed above, we will have a problem because the loop is executed 
sequencially by one single thread, so we can't anymore implement any 
SEDA mechanism.

If the filter is responsible for the call of the next filter, then it's 
a totally different story.

We have to think about this before drafting some implementation, and 
decide if we want to stick to SEDA.

Now, some comment in line about Alan's last mail

Alan D. Cabrera a écrit :
>
> <Snip/>
>>>> Not sure this is possible in another way than with those computed 
>>>> nextFilter() inside the filters.
>>>
>>> I agree but it's my contention that it's a bad practice that 
>>> supports an ill thought out protocol.
>>
>> The biggest advantage is that it eases the implementor work most of 
>> the cases.
>
> IMO, it's sloppy and error prone and obfuscates code.  If no one else 
> agrees then I'm happy to drop my point.
You are probably right. If you look at the existing filters, there is no 
reason we should not be able to avoid such code.

>
>> Now, it does not preclude that we should not allow someone to 
>> implement his protocol using a complete state machine. May be we 
>> should provide both mechanisms :
>> - one which is driven by the code (ie, the code 'pull' the next step),
>> - one which is driven by the state machine (your way).
>
> I would argue against this.  Mina is afflicted w/ bloat.  
I can't agree more :)

> One the goals should be to get rid of as many useless "helpful" 
> classes and methods as we can.
+1

>   Either we all agree that adding filters in an ad hoc manner is a 
> best practice for network protocol state machines and we loose the 
> state machine or we agree that it's an anti-pattern that should be 
> avoided.  If the community thinks that ad hoc filters are a best 
> practice I'm happy to drop my point.
I would like to keep the SM approach, but as explained above (SEDA 
thing), I think we should be driven by the code.

> <snip/>
>
> I totally agree with this approach to deciding on the API and am happy 
> to help out w/ some protocols, e.g. HTTP and SSL.
>
> I am curious, what project feels that it needs to do an "implicit" 
> state machine?  I would love to take a peek at the code.
What do you mean by "implicit" state machine ?


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Dec 14, 2009, at 8:56 AM, Emmanuel LŽcharny wrote:

>
>>> Not necessarily, for three reasons :
>>> 1) if the chain is fixed at startup, you can't anymore inject a  
>>> LoggingFilter when the server is running. You can only activate or  
>>> desactivate it. Not that it's realy a big issue, but it may help  
>>> in some case (that also mean we have a way to control the  
>>> execution. JMX ?)
>>
>> One normally doesn't turn on and off things like that on a per  
>> message basis.  What I mean by that is that each filter decides to  
>> do what it needs to do.  That includes logging.  Constantly  
>> injecting logging filters on an ad hoc basis is a very, very, poor  
>> practice.
>
> A very, very rare practice, hopefully :) Here, i'm not sure it worth  
> it anyway. I really think it's better to enable the filter instead  
> of injecting it dynamically. In any case, I'm ready to lose this  
> "feature"...

Agreed, not a very compelling use case.

>>> 2) Most important, if we don't have a clue about which is the next  
>>> filter in the chain, that leads to problem when debugging, as you  
>>> can't know which filter will be called. Ennoying
>>
>> Sure you do.  The chains are fixed.  If you know what filter you  
>> are and what state you're in you know what filter gets called next  
>> from the perspective of the framework.  From the perspective of the  
>> filter you shouldn't care what's next, if you do then you've  
>> introduce a brittle dependency.  For me that;s usually a red flag  
>> that I haven't thought through a design and it needs to be revisited.
> Let me clarify my mind : when stepping through filters while  
> debugging, I want to be able to jump directly to the next filter. In  
> order to do that, code like :
>
> Filter nextFilter = computeNext( session );
> nextFilter.call( session );
>
> is mandatory. I don't want to experiment the same pain as with  
> Spring, when I have to open two editors, one for my java code, and  
> another one to see what is supposed to be my SM. I went through this  
> pain so many times in the past with MINA that I don't want to suffer  
> such a pain again...

Yeah, nothing is more frustrating than stepping though layers of  
container code.  That's why I configure my debugger to skip those  
chunks of code so it lands directly in my POJOs.  Anyway, since the  
chains are fixed the filter dispatching code is quite simple:

Filter current = filterChain[state, i++];
current.call(session);


>>> 3) Last, not least, we want to be able to call the next filter in  
>>> the middle of a processing :
>>>
>>> messageReceived() {
>>> do blah();
>>> if ( condition ) {
>>> do anotherBlah();
>>> call Next filter();
>>> } else {
>>> do yetAnotherBlah();
>>> call nextFilter();
>>> }
>>> do endingBlah();
>>> }
>>
>> That just tells me that you have mixed up two states into one and  
>> that you need to expend a little more effort into your state  
>> machine design.
>
> From the user POV, it's way more easy to write code this way than to  
> create two (or more) states. The idea is to combine the state  
> machine vision with the chain vision. You can express everything  
> with a SM, and implement it in a simpler way...

Easy, yes, initially and if you're the only developer but not so much  
more easier that your point is self evident.  But remember, we all  
agreed that the developer is doing this to create a state machine.   
The above code is brittle and lacks the explicit states.  I would  
argue that it's an anti-pattern.

>>> Not sure this is possible in another way than with those computed  
>>> nextFilter() inside the filters.
>>
>> I agree but it's my contention that it's a bad practice that  
>> supports an ill thought out protocol.
>
> The biggest advantage is that it eases the implementor work most of  
> the cases.

IMO, it's sloppy and error prone and obfuscates code.  If no one else  
agrees then I'm happy to drop my point.

> Now, it does not preclude that we should not allow someone to  
> implement his protocol using a complete state machine. May be we  
> should provide both mechanisms :
> - one which is driven by the code (ie, the code 'pull' the next step),
> - one which is driven by the state machine (your way).

I would argue against this.  Mina is afflicted w/ bloat.  One the  
goals should be to get rid of as many useless "helpful" classes and  
methods as we can.  Either we all agree that adding filters in an ad  
hoc manner is a best practice for network protocol state machines and  
we loose the state machine or we agree that it's an anti-pattern that  
should be avoided.  If the community thinks that ad hoc filters are a  
best practice I'm happy to drop my point.

>>> (well, t's always possible to express this with more transitions  
>>> and states, but t would be more complicated to write filters  
>>> then...)
>>
>> I'm looking at your messageReceived() method and am thinking that  
>> you have provided me with a perfect example for state programming.   
>> Only the original author of that method would know what's going on.
> Most certainly :) However, this was a complex example, usually, it's  
> way more simple.

I don't think it's complex.  The point I was trying to make is that  
it's a brittle and obfuscated implementation of a state machine by its  
very nature.

> I don't say that you are plain wrong, in fact, I share most of your  
> vision, but I'm just wondering if this would not render the protocol  
> implementors way more complex.
>
> I may try to see what would be the impact of the plain SM approach  
> when applied on the current implemented protocols.


I totally agree with this approach to deciding on the API and am happy  
to help out w/ some protocols, e.g. HTTP and SSL.

I am curious, what project feels that it needs to do an "implicit"  
state machine?  I would love to take a peek at the code.


Regards,
Alan



Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Emmanuel LŽcharny <el...@gmail.com>.
>> Not necessarily, for three reasons :
>> 1) if the chain is fixed at startup, you can't anymore inject a 
>> LoggingFilter when the server is running. You can only activate or 
>> desactivate it. Not that it's realy a big issue, but it may help in 
>> some case (that also mean we have a way to control the execution. JMX ?)
>
> One normally doesn't turn on and off things like that on a per message 
> basis.  What I mean by that is that each filter decides to do what it 
> needs to do.  That includes logging.  Constantly injecting logging 
> filters on an ad hoc basis is a very, very, poor practice.

A very, very rare practice, hopefully :) Here, i'm not sure it worth it 
anyway. I really think it's better to enable the filter instead of 
injecting it dynamically. In any case, I'm ready to lose this "feature"...

>
>> 2) Most important, if we don't have a clue about which is the next 
>> filter in the chain, that leads to problem when debugging, as you 
>> can't know which filter will be called. Ennoying
>
> Sure you do.  The chains are fixed.  If you know what filter you are 
> and what state you're in you know what filter gets called next from 
> the perspective of the framework.  From the perspective of the filter 
> you shouldn't care what's next, if you do then you've introduce a 
> brittle dependency.  For me that;s usually a red flag that I haven't 
> thought through a design and it needs to be revisited.
Let me clarify my mind : when stepping through filters while debugging, 
I want to be able to jump directly to the next filter. In order to do 
that, code like :

Filter nextFilter = computeNext( session );
nextFilter.call( session );

is mandatory. I don't want to experiment the same pain as with Spring, 
when I have to open two editors, one for my java code, and another one 
to see what is supposed to be my SM. I went through this pain so many 
times in the past with MINA that I don't want to suffer such a pain again...
>
>> 3) Last, not least, we want to be able to call the next filter in the 
>> middle of a processing :
>>
>> messageReceived() {
>> do blah();
>> if ( condition ) {
>> do anotherBlah();
>> call Next filter();
>> } else {
>> do yetAnotherBlah();
>> call nextFilter();
>> }
>> do endingBlah();
>> }
>
> That just tells me that you have mixed up two states into one and that 
> you need to expend a little more effort into your state machine design.

 From the user POV, it's way more easy to write code this way than to 
create two (or more) states. The idea is to combine the state machine 
vision with the chain vision. You can express everything with a SM, and 
implement it in a simpler way...
>
>>
>> Not sure this is possible in another way than with those computed 
>> nextFilter() inside the filters.
>
> I agree but it's my contention that it's a bad practice that supports 
> an ill thought out protocol.

The biggest advantage is that it eases the implementor work most of the 
cases. Now, it does not preclude that we should not allow someone to 
implement his protocol using a complete state machine. May be we should 
provide both mechanisms :
- one which is driven by the code (ie, the code 'pull' the next step),
- one which is driven by the state machine (your way).

>
>> (well, t's always possible to express this with more transitions and 
>> states, but t would be more complicated to write filters then...)
>
> I'm looking at your messageReceived() method and am thinking that you 
> have provided me with a perfect example for state programming.  Only 
> the original author of that method would know what's going on.
Most certainly :) However, this was a complex example, usually, it's way 
more simple.

I don't say that you are plain wrong, in fact, I share most of your 
vision, but I'm just wondering if this would not render the protocol 
implementors way more complex.

I may try to see what would be the impact of the plain SM approach when 
applied on the current implemented protocols.

Thanks !

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Dec 14, 2009, at 1:16 AM, Emmanuel Lecharny wrote:

> Alan D. Cabrera a écrit :
>>
>> On Dec 13, 2009, at 2:42 AM, Emmanuel LŽcharny wrote:
>> <snip/>
>>>> The key thing about state machines is that the states and the  
>>>> transitions are known and fixed ahead of time. If this our state  
>>>> of affairs, and I think that it is, then things are much more  
>>>> simple and mentally tractable, i.e. there's no ad hoc filter  
>>>> creation during protocol processing and much of the threading  
>>>> issues in past entries on this thread disappear.
>>> Generally speaking, when implementing a protocol, states and  
>>> transitions are very well known and static, so the SM approach  
>>> seems adequate.
>>>
>>
>> Agreed, the SM approach should cover all cases; even the logging  
>> case in your subsequent post.
>>
>> So with that said, would it not make sense to have a set of fixed  
>> filter chains w/ each chain representing a state rather than a  
>> bucket of filters with each filter deciding the next filter to  
>> execute?
>
> Not necessarily, for three reasons :
> 1) if the chain is fixed at startup, you can't anymore inject a  
> LoggingFilter when the server is running. You can only activate or  
> desactivate it. Not that it's realy a big issue, but it may help in  
> some case (that also mean we have a way to control the execution.  
> JMX ?)

One normally doesn't turn on and off things like that on a per message  
basis.  What I mean by that is that each filter decides to do what it  
needs to do.  That includes logging.  Constantly injecting logging  
filters on an ad hoc basis is a very, very, poor practice.

> 2) Most important, if we don't have a clue about which is the next  
> filter in the chain, that leads to problem when debugging, as you  
> can't know which filter will be called. Ennoying

Sure you do.  The chains are fixed.  If you know what filter you are  
and what state you're in you know what filter gets called next from  
the perspective of the framework.  From the perspective of the filter  
you shouldn't care what's next, if you do then you've introduce a  
brittle dependency.  For me that;s usually a red flag that I haven't  
thought through a design and it needs to be revisited.

> 3) Last, not least, we want to be able to call the next filter in  
> the middle of a processing :
>
> messageReceived() {
> do blah();
> if ( condition ) {
> do anotherBlah();
> call Next filter();
> } else {
> do yetAnotherBlah();
> call nextFilter();
> }
> do endingBlah();
> }

That just tells me that you have mixed up two states into one and that  
you need to expend a little more effort into your state machine design.

>
> Not sure this is possible in another way than with those computed  
> nextFilter() inside the filters.

I agree but it's my contention that it's a bad practice that supports  
an ill thought out protocol.

> (well, t's always possible to express this with more transitions and  
> states, but t would be more complicated to write filters then...)

I'm looking at your messageReceived() method and am thinking that you  
have provided me with a perfect example for state programming.  Only  
the original author of that method would know what's going on.


Regards,
Alan



Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Emmanuel Lecharny <el...@gmail.com>.
Alan D. Cabrera a écrit :
>
> On Dec 13, 2009, at 2:42 AM, Emmanuel LŽcharny wrote:
> <snip/>
>>> The key thing about state machines is that the states and the 
>>> transitions are known and fixed ahead of time. If this our state of 
>>> affairs, and I think that it is, then things are much more simple 
>>> and mentally tractable, i.e. there's no ad hoc filter creation 
>>> during protocol processing and much of the threading issues in past 
>>> entries on this thread disappear.
>> Generally speaking, when implementing a protocol, states and 
>> transitions are very well known and static, so the SM approach seems 
>> adequate.
>>
>
> Agreed, the SM approach should cover all cases; even the logging case 
> in your subsequent post.
>
> So with that said, would it not make sense to have a set of fixed 
> filter chains w/ each chain representing a state rather than a bucket 
> of filters with each filter deciding the next filter to execute?

Not necessarily, for three reasons :
1) if the chain is fixed at startup, you can't anymore inject a 
LoggingFilter when the server is running. You can only activate or 
desactivate it. Not that it's realy a big issue, but it may help in some 
case (that also mean we have a way to control the execution. JMX ?)
2) Most important, if we don't have a clue about which is the next 
filter in the chain, that leads to problem when debugging, as you can't 
know which filter will be called. Ennoying
3) Last, not least, we want to be able to call the next filter in the 
middle of a processing :

messageReceived() {
do blah();
if ( condition ) {
do anotherBlah();
call Next filter();
} else {
do yetAnotherBlah();
call nextFilter();
}
do endingBlah();
}

Not sure this is possible in another way than with those computed 
nextFilter() inside the filters.

(well, t's always possible to express this with more transitions and 
states, but t would be more complicated to write filters then...)


>
>
> Regards,
> Alan
>
>


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com



Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Dec 13, 2009, at 2:42 AM, Emmanuel LŽcharny wrote:

> Alan D. Cabrera a écrit :
>>
>> On Dec 3, 2009, at 5:28 PM, Ashish wrote:
>>
>>>>>> What about the assertion that new filters only get created to  
>>>>>> simulate a
>>>>>> state machine?
>>>>>
>>>>> Finally, managed to check-in some of the initial thoughts.
>>>>> The transition handler or the computeNext function is still to  
>>>>> be out in.
>>>>
>>>> Sorry. Not sure how that answers my question other than to detail  
>>>> what
>>>> you've done and what you're about to do.
>>>>
>>>
>>> OOPS! :-(  I think I am getting old
>>>
>>> After a discussion we thought that we shall make it possible for
>>> user's to choose the way we want Filter transitions
>>> That's what the transition handler is :-) Default implementation  
>>> shall
>>> be of next Filter in the chain.
>>> User's can plugin their implementations for transition say like a
>>> State Machine implementation.
>>>
>>> Since I couldn't take it to logical conclusion, still working on  
>>> it :)
>>> Also my experience with State machines is limited, so will need a
>>> helping hand here (or may be some references :-) )
>>
>> The key thing about state machines is that the states and the  
>> transitions are known and fixed ahead of time.  If this our state  
>> of affairs, and I think that it is, then things are much more  
>> simple and mentally tractable, i.e. there's no ad hoc filter  
>> creation during protocol processing and much of the threading  
>> issues in past entries on this thread disappear.
> Generally speaking, when implementing a protocol, states and  
> transitions are very well known and static, so the SM approach seems  
> adequate.
>

Agreed, the SM approach should cover all cases; even the logging case  
in your subsequent post.

So with that said, would it not make sense to have a set of fixed  
filter chains w/ each chain representing a state rather than a bucket  
of filters with each filter deciding the next filter to execute?


Regards,
Alan


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Emmanuel LŽcharny <el...@gmail.com>.
Alan D. Cabrera a écrit :
>
> On Dec 3, 2009, at 5:28 PM, Ashish wrote:
>
>>>>> What about the assertion that new filters only get created to 
>>>>> simulate a
>>>>> state machine?
>>>>
>>>> Finally, managed to check-in some of the initial thoughts.
>>>> The transition handler or the computeNext function is still to be 
>>>> out in.
>>>
>>> Sorry. Not sure how that answers my question other than to detail what
>>> you've done and what you're about to do.
>>>
>>
>> OOPS! :-(  I think I am getting old
>>
>> After a discussion we thought that we shall make it possible for
>> user's to choose the way we want Filter transitions
>> That's what the transition handler is :-) Default implementation shall
>> be of next Filter in the chain.
>> User's can plugin their implementations for transition say like a
>> State Machine implementation.
>>
>> Since I couldn't take it to logical conclusion, still working on it :)
>> Also my experience with State machines is limited, so will need a
>> helping hand here (or may be some references :-) )
>
> The key thing about state machines is that the states and the 
> transitions are known and fixed ahead of time.  If this our state of 
> affairs, and I think that it is, then things are much more simple and 
> mentally tractable, i.e. there's no ad hoc filter creation during 
> protocol processing and much of the threading issues in past entries 
> on this thread disappear.
Generally speaking, when implementing a protocol, states and transitions 
are very well known and static, so the SM approach seems adequate.


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Dec 3, 2009, at 5:28 PM, Ashish wrote:

>>>> What about the assertion that new filters only get created to  
>>>> simulate a
>>>> state machine?
>>>
>>> Finally, managed to check-in some of the initial thoughts.
>>> The transition handler or the computeNext function is still to be  
>>> out in.
>>
>> Sorry. Not sure how that answers my question other than to detail  
>> what
>> you've done and what you're about to do.
>>
>
> OOPS! :-(  I think I am getting old
>
> After a discussion we thought that we shall make it possible for
> user's to choose the way we want Filter transitions
> That's what the transition handler is :-) Default implementation shall
> be of next Filter in the chain.
> User's can plugin their implementations for transition say like a
> State Machine implementation.
>
> Since I couldn't take it to logical conclusion, still working on it :)
> Also my experience with State machines is limited, so will need a
> helping hand here (or may be some references :-) )

The key thing about state machines is that the states and the  
transitions are known and fixed ahead of time.  If this our state of  
affairs, and I think that it is, then things are much more simple and  
mentally tractable, i.e. there's no ad hoc filter creation during  
protocol processing and much of the threading issues in past entries  
on this thread disappear.


Regards,
Alan



Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Ashish <pa...@gmail.com>.
>>> What about the assertion that new filters only get created to simulate a
>>> state machine?
>>
>> Finally, managed to check-in some of the initial thoughts.
>> The transition handler or the computeNext function is still to be out in.
>
> Sorry. Not sure how that answers my question other than to detail what
> you've done and what you're about to do.
>

OOPS! :-(  I think I am getting old

After a discussion we thought that we shall make it possible for
user's to choose the way we want Filter transitions
That's what the transition handler is :-) Default implementation shall
be of next Filter in the chain.
User's can plugin their implementations for transition say like a
State Machine implementation.

Since I couldn't take it to logical conclusion, still working on it :)
Also my experience with State machines is limited, so will need a
helping hand here (or may be some references :-) )

-- 
thanks
ashish

Blog: http://www.ashishpaliwal.com/blog
My Photo Galleries: http://www.pbase.com/ashishpaliwal

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Dec 3, 2009, at 3:08 AM, Ashish wrote:

>> What about the assertion that new filters only get created to  
>> simulate a
>> state machine?
>
> Finally, managed to check-in some of the initial thoughts.
> The transition handler or the computeNext function is still to be  
> out in.

Sorry. Not sure how that answers my question other than to detail what  
you've done and what you're about to do.


Regards,
Alan


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Ashish <pa...@gmail.com>.
> What about the assertion that new filters only get created to simulate a
> state machine?

Finally, managed to check-in some of the initial thoughts.
The transition handler or the computeNext function is still to be out in.

-- 
thanks
ashish

Blog: http://www.ashishpaliwal.com/blog
My Photo Galleries: http://www.pbase.com/ashishpaliwal

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Nov 28, 2009, at 6:03 PM, Ashish wrote:

>> What about the assertion that new filters only get created to  
>> simulate a
>> state machine?
>>
>>> So what's the best way proceed forward, now that we had a quite a  
>>> good
>>> discussion :-)
>>
>> CODE IT UP!  :)
>>
>> Actually, when ever I make an API, I usually drive the API design  
>> by actual
>> coding examples.  Take for example how I drove the design of the  
>> HTTP client
>> by implementing the Amazon S3/EC2 clients.  My mantra is that if  
>> the client
>> use case doesn't use it then it doesn't go into the API.  Also, I  
>> design
>> against interfaces so that implementation details don't clutter my  
>> API
>> thinking.
>>
>> I can do to mock implementations for async HTTP and for an ASN1  
>> codec.
>
> Yup. Had a quick chat with Emm yesterday :-)
> Will check in some initial thoughts and then we can slice and dice it
> up to make it a beauty :-)))

Cool!

What about the assertion that new filters only get created to simulate  
a state machine?


Regards,
Alan


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Ashish <pa...@gmail.com>.
> What about the assertion that new filters only get created to simulate a
> state machine?
>
>> So what's the best way proceed forward, now that we had a quite a good
>> discussion :-)
>
> CODE IT UP!  :)
>
> Actually, when ever I make an API, I usually drive the API design by actual
> coding examples.  Take for example how I drove the design of the HTTP client
> by implementing the Amazon S3/EC2 clients.  My mantra is that if the client
> use case doesn't use it then it doesn't go into the API.  Also, I design
> against interfaces so that implementation details don't clutter my API
> thinking.
>
> I can do to mock implementations for async HTTP and for an ASN1 codec.

Yup. Had a quick chat with Emm yesterday :-)
Will check in some initial thoughts and then we can slice and dice it
up to make it a beauty :-)))

-- 
thanks
ashish

Blog: http://www.ashishpaliwal.com/blog
My Photo Galleries: http://www.pbase.com/ashishpaliwal

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Nov 28, 2009, at 2:32 AM, Ashish wrote:

>>> Well, choosing a suitable Data Structure to support all this will
>>> again be interesting. Current implementation uses something  
>>> similar to
>>> LinkedHashtable. Have to see if something simpler can be implemented
>>> or out of the box API :-)
>>
>>
>> It's my opinion that new filters get created to simulate state  
>> machine
>> changes and any other use is an ad hoc mechanism that can be more  
>> cleanly
>> refactored into a state machine mechanism.  With that said aa  
>> session w/  N
>> fixed chains where each chain represents a state would fit the  
>> bill.  The
>> number of states is fixed.  The composition of the state machine  
>> can be
>> changed until the acceptor/connector have established the connection.
>>
>> Acceptor -> ChainMachine -> IoHandler
>>
>> inside the chain machine:
>>
>> S1: IOF1 -> IOF2 -> IOF3  -> IOF5 -> IOF4
>> S2: IOF1 -> IOF3 -> IOF5 -> IOF4
>> S3: IOF1 -> IOF2 -> IOF3 -> IOF4
>>
>> From a user's perspective things are quite easy to grok and most  
>> cases the
>> chain machine degenerates into a single state chain.
>
> Agree on point that we have to keep additional noise away :-)

What about the assertion that new filters only get created to simulate  
a state machine?

> So what's the best way proceed forward, now that we had a quite a good
> discussion :-)

CODE IT UP!  :)

Actually, when ever I make an API, I usually drive the API design by  
actual coding examples.  Take for example how I drove the design of  
the HTTP client by implementing the Amazon S3/EC2 clients.  My mantra  
is that if the client use case doesn't use it then it doesn't go into  
the API.  Also, I design against interfaces so that implementation  
details don't clutter my API thinking.

I can do to mock implementations for async HTTP and for an ASN1 codec.



Regards,
Alan




Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Ashish <pa...@gmail.com>.
>> Well, choosing a suitable Data Structure to support all this will
>> again be interesting. Current implementation uses something similar to
>> LinkedHashtable. Have to see if something simpler can be implemented
>> or out of the box API :-)
>
>
> It's my opinion that new filters get created to simulate state machine
> changes and any other use is an ad hoc mechanism that can be more cleanly
> refactored into a state machine mechanism.  With that said aa session w/  N
> fixed chains where each chain represents a state would fit the bill.  The
> number of states is fixed.  The composition of the state machine can be
> changed until the acceptor/connector have established the connection.
>
> Acceptor -> ChainMachine -> IoHandler
>
> inside the chain machine:
>
> S1: IOF1 -> IOF2 -> IOF3  -> IOF5 -> IOF4
> S2: IOF1 -> IOF3 -> IOF5 -> IOF4
> S3: IOF1 -> IOF2 -> IOF3 -> IOF4
>
> From a user's perspective things are quite easy to grok and most cases the
> chain machine degenerates into a single state chain.

Agree on point that we have to keep additional noise away :-)

So what's the best way proceed forward, now that we had a quite a good
discussion :-)

-- 
thanks
ashish

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Nov 27, 2009, at 8:23 PM, Ashish wrote:

>>>
>>> In the second approach, won't we end up with the same problems as  
>>> Mina 2.0,
>>> "From the debugging PoV, it's a nightmare, as you have to step  
>>> through many
>>> intermediate calls (in fact, an other call for each filter). The  
>>> StackTrace
>>> is heavy. The next filter is not known when you are in a Filter,  
>>> as it's
>>> computed outside of the current method"?
>>
>> No : the next is computed inside the method :
>>
>> ...
>> nextFilter = computeNext( params );
>> nextFilter.<action>( params );
>> ...
>>
>> so you can immediately know which is the next filter (as it's stored
>> in the nextFilter variable) and you don't have one more call in the
>> stack, as once you get the nextFilter, you are done. This was not the
>> case in MINA 2.0, because the computation was delegated to an
>> intermediate object.
>>
>>
>>> To make things clear in my mind, where would we need such a feature?
>>
>> If you get a message that can be decoded in many different ways, for
>> instance, depending on the first byte (just an exemple). The
>> computeNext method can take some parameter, and returns the next
>> filter, depending on the context. Ok, at the end of the day, it's a
>> state machine :)
>>
>>>  Couldn't we just load all the filters in the chain and they  
>>> decide whether
>>> or not to do anything?
>
>> Yes, of course, and we should probably implement most of the  
>> protocols
>> this way. The idea is to keep the full stuff simple, but allow a user
>> to go a bit further if needed. At this point, we may want to offer
>> differnt kind of Chain implementation ...
>
> I am still kinda not very comfortable with the computation part. The
> only reason why I need the next filter to be got dynamically is to
> handle dynamic chain.
>
> Wearing a User's hat :-)
>
> Acceptor --> IoFilter1--> IoFilter2 --> IoFilter3 -->IoFilter4 -->  
> IoHandler
>
> If I see from POV, this is what I need in my implementation. To add to
> this, I may choose to modify the chain at runtime, say disable/remove
> IoFilter3, giving me this new chain
>
> Acceptor --> IoFilter1--> IoFilter2 --> IoFilter4 --> IoHandler
>
> or adding a new Filter between 3 and 4
>
> Acceptor --> IoFilter1--> IoFilter2 --> IoFilter3 -->IoFilter5
> -->IoFilter4 --> IoHandler
>
> So, compute function shall always return me the next filter in chain
> from somewhere (based on our implementation)
> This is pretty much that I need from the chain.
>
> Now lets see if based on identifier we choose that we need to decide
> which is the next filter, then we get something like this
>
> X - means skipped (Artwork inspired by Emm's Art work :-) )
>
>              /    IoFilter1--> IoFilter2 --> IoFilter3 -->IoFilter5
> -->IoFilter4 --> IoHandler
> Acceptor --> IoFilter1-->      X      --> IoFilter3 -->IoFilter5
> -->IoFilter4 --> IoHandler
>              \    IoFilter1--> IoFilter2 --> IoFilter3 -->      X
> -->IoFilter4 --> IoHandler
>
>
> so how it could be a possibility that we allow to override the
> computeFilter() to get the desired functionality. We provide default
> functionality to support static and dynamic chains For any custom
> functionality we leave scope improvement. If this is what everyone is
> thinking my doubt on computeFilter() is a little clear :-)
>
> Well, choosing a suitable Data Structure to support all this will
> again be interesting. Current implementation uses something similar to
> LinkedHashtable. Have to see if something simpler can be implemented
> or out of the box API :-)


It's my opinion that new filters get created to simulate state machine  
changes and any other use is an ad hoc mechanism that can be more  
cleanly refactored into a state machine mechanism.  With that said aa  
session w/  N fixed chains where each chain represents a state would  
fit the bill.  The number of states is fixed.  The composition of the  
state machine can be changed until the acceptor/connector have  
established the connection.

Acceptor -> ChainMachine -> IoHandler

inside the chain machine:

S1: IOF1 -> IOF2 -> IOF3  -> IOF5 -> IOF4
S2: IOF1 -> IOF3 -> IOF5 -> IOF4
S3: IOF1 -> IOF2 -> IOF3 -> IOF4

 From a user's perspective things are quite easy to grok and most  
cases the chain machine degenerates into a single state chain.


Regards,
Alan



Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Ashish <pa...@gmail.com>.
>>
>> In the second approach, won't we end up with the same problems as Mina 2.0,
>> "From the debugging PoV, it's a nightmare, as you have to step through many
>> intermediate calls (in fact, an other call for each filter). The StackTrace
>> is heavy. The next filter is not known when you are in a Filter, as it's
>> computed outside of the current method"?
>
> No : the next is computed inside the method :
>
> ...
> nextFilter = computeNext( params );
> nextFilter.<action>( params );
> ...
>
> so you can immediately know which is the next filter (as it's stored
> in the nextFilter variable) and you don't have one more call in the
> stack, as once you get the nextFilter, you are done. This was not the
> case in MINA 2.0, because the computation was delegated to an
> intermediate object.
>
>
>> To make things clear in my mind, where would we need such a feature?
>
> If you get a message that can be decoded in many different ways, for
> instance, depending on the first byte (just an exemple). The
> computeNext method can take some parameter, and returns the next
> filter, depending on the context. Ok, at the end of the day, it's a
> state machine :)
>
>>  Couldn't we just load all the filters in the chain and they decide whether
>> or not to do anything?

> Yes, of course, and we should probably implement most of the protocols
> this way. The idea is to keep the full stuff simple, but allow a user
> to go a bit further if needed. At this point, we may want to offer
> differnt kind of Chain implementation ...

I am still kinda not very comfortable with the computation part. The
only reason why I need the next filter to be got dynamically is to
handle dynamic chain.

Wearing a User's hat :-)

Acceptor --> IoFilter1--> IoFilter2 --> IoFilter3 -->IoFilter4 --> IoHandler

If I see from POV, this is what I need in my implementation. To add to
this, I may choose to modify the chain at runtime, say disable/remove
IoFilter3, giving me this new chain

Acceptor --> IoFilter1--> IoFilter2 --> IoFilter4 --> IoHandler

or adding a new Filter between 3 and 4

Acceptor --> IoFilter1--> IoFilter2 --> IoFilter3 -->IoFilter5
-->IoFilter4 --> IoHandler

So, compute function shall always return me the next filter in chain
from somewhere (based on our implementation)
This is pretty much that I need from the chain.

Now lets see if based on identifier we choose that we need to decide
which is the next filter, then we get something like this

X - means skipped (Artwork inspired by Emm's Art work :-) )

              /    IoFilter1--> IoFilter2 --> IoFilter3 -->IoFilter5
-->IoFilter4 --> IoHandler
Acceptor --> IoFilter1-->      X      --> IoFilter3 -->IoFilter5
-->IoFilter4 --> IoHandler
              \    IoFilter1--> IoFilter2 --> IoFilter3 -->      X
-->IoFilter4 --> IoHandler


so how it could be a possibility that we allow to override the
computeFilter() to get the desired functionality. We provide default
functionality to support static and dynamic chains For any custom
functionality we leave scope improvement. If this is what everyone is
thinking my doubt on computeFilter() is a little clear :-)

Well, choosing a suitable Data Structure to support all this will
again be interesting. Current implementation uses something similar to
LinkedHashtable. Have to see if something simpler can be implemented
or out of the box API :-)

-- 
thanks
ashish

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Emmanuel Lecharny <el...@apache.org>.
On Fri, Nov 27, 2009 at 5:28 PM, Alan D. Cabrera <li...@toolazydogs.com> wrote:
>
> On Nov 26, 2009, at 7:51 AM, Emmanuel Lecharny wrote:
>
>> About the Filters and the Chain, I also have some initial thoughts (even
>> if they are not recent). Here they are.
>>
>> First, let's start with what we really need :
>> o A chain has a start
>> o A chain has an end
>> o Both start and end are Filter instances
>> o We have as many filters as we need in the chain
>> o Filters can be added or removed dynamically
>> o A chain is instanciated for each session (if we have 10K sessions, we
>> have 10K instances of chain)
>> o A filter can be activated (enabled) or disabled, dynamically
>>
>> That being said, we have many ways to implement such a mechanism. let's
>> consider we are in a Filter, and we want to call the next filter. We have
>> three options here :
>> * The NextFilter is already computed, and is a part of the Filter's data.
>> This resolves to a direct call :
>> ...
>> nextFilter.<action>( params );
>> ...
>>
>> * The NextFilter is computed dynamically :
>> ...
>> nextFilter = computeNext( params );
>> nextFilter.<action>( params );
>> ...
>>
>> * The nextFilter is computed by the caller, and is a parameter :
>>
>> public void <action>( Filter nextFilter, <other params>... ) {
>> ...
>> nextFilter.<action>( params );
>> ...
>>
>> The current version (2.0) implements the third form. From the debugging
>> PoV, it's a nightmare, as you have to step through many intermediate calls
>> (in fact, an other call for each filter). The StackTrace is heavy. The next
>> filter is not known when you are in a Filter, as it's computed outside of
>> the current method.
>>
>> The first approach is way simpler, as is the second one.
>>
>> Let's go a bit deeper : if there is an executor in the chain, suddenly
>> things get a bit muddy. The "one session = one chain instance" is still
>> correct, but we may have two (or more) messages being processed on one
>> session on the same chain. If the chain is dynamically modified, then it may
>> be ok for the thread modifying the chain, but not for the other threads.
>> Here is a picture describing this mechanism :
>>
>>
>> Thread1                                                  /--->
>> [Filter3]--->[tail]
>> Thread2 [head]---> [filter1]--->[filter2]--->[executor]-*---->
>> [Filter3]--->[tail]
>> Thread3                                                  \--->
>> [Filter3]--->[tail]
>
> Whoa.  Look at that ascii art.  No wonder your Dell had an aneurism.  ;)
>
>> Now, if the Thread 2 modify the chain to add a Filter4, then there is no
>> guarantee that Thread1 will call it. That means we must protect the chain
>> against concurrent modifications.
>>
>> Another drawback of the first approach is that you must declare an
>> instance of a Filter for your chain, as it carries some information specific
>> to your session. We would rather have a stateless Filter...
>>
>> The second approach require an external system to give you the next
>> filter. It can be the session, which is passed as a parameter for each
>> filter call.In this case, if the external system is protected against
>> concurrent modifications, then we are safe (except if we want each thread to
>> define its own chain in the previous example... In this case, the executor
>> must be responsible for the chain duplication, and probably store it in a
>> ThreadLocal variable )
>
> In the second approach, won't we end up with the same problems as Mina 2.0,
> "From the debugging PoV, it's a nightmare, as you have to step through many
> intermediate calls (in fact, an other call for each filter). The StackTrace
> is heavy. The next filter is not known when you are in a Filter, as it's
> computed outside of the current method"?

No : the next is computed inside the method :

...
nextFilter = computeNext( params );
nextFilter.<action>( params );
...

so you can immediately know which is the next filter (as it's stored
in the nextFilter variable) and you don't have one more call in the
stack, as once you get the nextFilter, you are done. This was not the
case in MINA 2.0, because the computation was delegated to an
intermediate object.


> To make things clear in my mind, where would we need such a feature?

If you get a message that can be decoded in many different ways, for
instance, depending on the first byte (just an exemple). The
computeNext method can take some parameter, and returns the next
filter, depending on the context. Ok, at the end of the day, it's a
state machine :)

>  Couldn't we just load all the filters in the chain and they decide whether
> or not to do anything?

Yes, of course, and we should probably implement most of the protocols
this way. The idea is to keep the full stuff simple, but allow a user
to go a bit further if needed. At this point, we may want to offer
differnt kind of Chain implementation ...




-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Nov 26, 2009, at 7:51 AM, Emmanuel Lecharny wrote:

> About the Filters and the Chain, I also have some initial thoughts  
> (even if they are not recent). Here they are.
>
> First, let's start with what we really need :
> o A chain has a start
> o A chain has an end
> o Both start and end are Filter instances
> o We have as many filters as we need in the chain
> o Filters can be added or removed dynamically
> o A chain is instanciated for each session (if we have 10K sessions,  
> we have 10K instances of chain)
> o A filter can be activated (enabled) or disabled, dynamically
>
> That being said, we have many ways to implement such a mechanism.  
> let's consider we are in a Filter, and we want to call the next  
> filter. We have three options here :
> * The NextFilter is already computed, and is a part of the Filter's  
> data. This resolves to a direct call :
> ...
> nextFilter.<action>( params );
> ...
>
> * The NextFilter is computed dynamically :
> ...
> nextFilter = computeNext( params );
> nextFilter.<action>( params );
> ...
>
> * The nextFilter is computed by the caller, and is a parameter :
>
> public void <action>( Filter nextFilter, <other params>... ) {
> ...
> nextFilter.<action>( params );
> ...
>
> The current version (2.0) implements the third form. From the  
> debugging PoV, it's a nightmare, as you have to step through many  
> intermediate calls (in fact, an other call for each filter). The  
> StackTrace is heavy. The next filter is not known when you are in a  
> Filter, as it's computed outside of the current method.
>
> The first approach is way simpler, as is the second one.
>
> Let's go a bit deeper : if there is an executor in the chain,  
> suddenly things get a bit muddy. The "one session = one chain  
> instance" is still correct, but we may have two (or more) messages  
> being processed on one session on the same chain. If the chain is  
> dynamically modified, then it may be ok for the thread modifying the  
> chain, but not for the other threads. Here is a picture describing  
> this mechanism :
>
>
> Thread1                                                  /--->  
> [Filter3]--->[tail]
> Thread2 [head]---> [filter1]--->[filter2]--->[executor]-*---->  
> [Filter3]--->[tail]
> Thread3                                                  \--->  
> [Filter3]--->[tail]

Whoa.  Look at that ascii art.  No wonder your Dell had an aneurism.  ;)

> Now, if the Thread 2 modify the chain to add a Filter4, then there  
> is no guarantee that Thread1 will call it. That means we must  
> protect the chain against concurrent modifications.
>
> Another drawback of the first approach is that you must declare an  
> instance of a Filter for your chain, as it carries some information  
> specific to your session. We would rather have a stateless Filter...
>
> The second approach require an external system to give you the next  
> filter. It can be the session, which is passed as a parameter for  
> each filter call.In this case, if the external system is protected  
> against concurrent modifications, then we are safe (except if we  
> want each thread to define its own chain in the previous example...  
> In this case, the executor must be responsible for the chain  
> duplication, and probably store it in a ThreadLocal variable )

In the second approach, won't we end up with the same problems as Mina  
2.0, "From the debugging PoV, it's a nightmare, as you have to step  
through many intermediate calls (in fact, an other call for each  
filter). The StackTrace is heavy. The next filter is not known when  
you are in a Filter, as it's computed outside of the current method"?

To make things clear in my mind, where would we need such a feature?   
Couldn't we just load all the filters in the chain and they decide  
whether or not to do anything?


Regards,
Alan


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Emmanuel Lecharny <el...@apache.org>.
About the Filters and the Chain, I also have some initial thoughts (even 
if they are not recent). Here they are.

First, let's start with what we really need :
o A chain has a start
o A chain has an end
o Both start and end are Filter instances
o We have as many filters as we need in the chain
o Filters can be added or removed dynamically
o A chain is instanciated for each session (if we have 10K sessions, we 
have 10K instances of chain)
o A filter can be activated (enabled) or disabled, dynamically

That being said, we have many ways to implement such a mechanism. let's 
consider we are in a Filter, and we want to call the next filter. We 
have three options here :
* The NextFilter is already computed, and is a part of the Filter's 
data. This resolves to a direct call :
  ...
  nextFilter.<action>( params );
  ...

* The NextFilter is computed dynamically :
  ...
  nextFilter = computeNext( params );
  nextFilter.<action>( params );
  ...

* The nextFilter is computed by the caller, and is a parameter :

public void <action>( Filter nextFilter, <other params>... ) {
  ...
  nextFilter.<action>( params );
  ...

The current version (2.0) implements the third form. From the debugging 
PoV, it's a nightmare, as you have to step through many intermediate 
calls (in fact, an other call for each filter). The StackTrace is heavy. 
The next filter is not known when you are in a Filter, as it's computed 
outside of the current method.

The first approach is way simpler, as is the second one.

Let's go a bit deeper : if there is an executor in the chain, suddenly 
things get a bit muddy. The "one session = one chain instance" is still 
correct, but we may have two (or more) messages being processed on one 
session on the same chain. If the chain is dynamically modified, then it 
may be ok for the thread modifying the chain, but not for the other 
threads. Here is a picture describing this mechanism :


Thread1                                                  /---> 
[Filter3]--->[tail]
Thread2 [head]---> [filter1]--->[filter2]--->[executor]-*----> 
[Filter3]--->[tail]
Thread3                                                  \---> 
[Filter3]--->[tail]

Now, if the Thread 2 modify the chain to add a Filter4, then there is no 
guarantee that Thread1 will call it. That means we must protect the 
chain against concurrent modifications.

Another drawback of the first approach is that you must declare an 
instance of a Filter for your chain, as it carries some information 
specific to your session. We would rather have a stateless Filter...

The second approach require an external system to give you the next 
filter. It can be the session, which is passed as a parameter for each 
filter call.In this case, if the external system is protected against 
concurrent modifications, then we are safe (except if we want each 
thread to define its own chain in the previous example... In this case, 
the executor must be responsible for the chain duplication, and probably 
store it in a ThreadLocal variable )

Not that simple...

Thoughts ?


Norman Maurer wrote:
> Well I'm not a MINA committer but I would keep the "Filter" naming.
> Like Emanuell said, its a well known "pattern".
>
> Bye,
> Norman
>
> 2009/11/26 Julien Vermillard <jv...@archean.fr>:
>> Le Thu, 26 Nov 2009 15:55:57 +0530,
>> Ashish <pa...@gmail.com> a écrit :
>>
>>> Have started looking into the FilterChain implementation and here are
>>> some initial thoughts
>>>
>>> 1. Rename IoFilterChain as IoChannel - it gives a more clear picture
>>> and is easy to understand like imagine as a Channel with multiple
>>> stages aka IoFilters.
>>> This came while I was drawing on paper to design something.
>>
>> I propose IoPipe/IoPipeline, because for me a bunch of filter stacked on
>> each other is a Pipe in the Unix meaning.
>>
>>
>>> 2. Have captured a couple of API's that are core to IoChannel
>>>
>>>               IoSession getSession();
>>>
>>>               IoFilter getHead();
>>>
>>>               IoFilter getNextFilter(IoFilter currentFilter);
>>>
>>>               List<IoFilter> getAll();
>>>
>>>               void addFilter(String name, IoFilter filter);
>>>
>>>               void addAfter(String baseName, String filterName,
>>> IoFilter filter);
>>>
>>>               void removeFilter(String filterName);
>>>
>>> There are a lot more API's in current implementation. I am not sure if
>>> we need replace API or not.
>>> Also do we need the Generics version of these API's or its fine
>>> without them?
>>>
>>> This is just the initial list. Will checkin the files once the name
>>> change is OK with everyone.
>>>
>


-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org



Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Norman Maurer <no...@googlemail.com>.
Well I'm not a MINA committer but I would keep the "Filter" naming.
Like Emanuell said, its a well known "pattern".

Bye,
Norman

2009/11/26 Julien Vermillard <jv...@archean.fr>:
> Le Thu, 26 Nov 2009 15:55:57 +0530,
> Ashish <pa...@gmail.com> a écrit :
>
>> Have started looking into the FilterChain implementation and here are
>> some initial thoughts
>>
>> 1. Rename IoFilterChain as IoChannel - it gives a more clear picture
>> and is easy to understand like imagine as a Channel with multiple
>> stages aka IoFilters.
>> This came while I was drawing on paper to design something.
>
>
> I propose IoPipe/IoPipeline, because for me a bunch of filter stacked on
> each other is a Pipe in the Unix meaning.
>
>
>>
>> 2. Have captured a couple of API's that are core to IoChannel
>>
>>               IoSession getSession();
>>
>>               IoFilter getHead();
>>
>>               IoFilter getNextFilter(IoFilter currentFilter);
>>
>>               List<IoFilter> getAll();
>>
>>               void addFilter(String name, IoFilter filter);
>>
>>               void addAfter(String baseName, String filterName,
>> IoFilter filter);
>>
>>               void removeFilter(String filterName);
>>
>> There are a lot more API's in current implementation. I am not sure if
>> we need replace API or not.
>> Also do we need the Generics version of these API's or its fine
>> without them?
>>
>> This is just the initial list. Will checkin the files once the name
>> change is OK with everyone.
>>
>

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Julien Vermillard <jv...@archean.fr>.
Le Thu, 26 Nov 2009 15:55:57 +0530,
Ashish <pa...@gmail.com> a écrit :

> Have started looking into the FilterChain implementation and here are
> some initial thoughts
> 
> 1. Rename IoFilterChain as IoChannel - it gives a more clear picture
> and is easy to understand like imagine as a Channel with multiple
> stages aka IoFilters.
> This came while I was drawing on paper to design something.


I propose IoPipe/IoPipeline, because for me a bunch of filter stacked on
each other is a Pipe in the Unix meaning.


> 
> 2. Have captured a couple of API's that are core to IoChannel
> 
>               IoSession getSession();
> 
>               IoFilter getHead();
> 
>               IoFilter getNextFilter(IoFilter currentFilter);
> 
>               List<IoFilter> getAll();
> 
>               void addFilter(String name, IoFilter filter);
> 
>               void addAfter(String baseName, String filterName,
> IoFilter filter);
> 
>               void removeFilter(String filterName);
> 
> There are a lot more API's in current implementation. I am not sure if
> we need replace API or not.
> Also do we need the Generics version of these API's or its fine
> without them?
> 
> This is just the initial list. Will checkin the files once the name
> change is OK with everyone.
> 

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Nov 27, 2009, at 7:59 PM, Ashish wrote:

>>
>>> Have started looking into the FilterChain implementation and here  
>>> are
>>> some initial thoughts
>>>
>>> 1. Rename IoFilterChain as IoChannel - it gives a more clear picture
>>> and is easy to understand like imagine as a Channel with multiple
>>> stages aka IoFilters.
>>> This came while I was drawing on paper to design something.
>>>
>>> 2. Have captured a couple of API's that are core to IoChannel
>>>
>>>             IoSession getSession();
>>>
>>>             IoFilter getHead();
>>>
>>>             IoFilter getNextFilter(IoFilter currentFilter);
>>>
>>>             List<IoFilter> getAll();
>>>
>>>             void addFilter(String name, IoFilter filter);
>>>
>>>             void addAfter(String baseName, String filterName,
>>> IoFilter filter);
>>>
>>>             void removeFilter(String filterName);
>>
>> My Mina is a bit rusty so my comments may be a bit off base.  I would
>> simplify this to
>>
>> List<IoFilter> getChain()
>>
>> Where one can re/move items in the chain.
>>
>> I would remove the filter name parameter since this is an aspect of  
>> the
>> filter and not its role in the chain.
>
> This thought did crossed my mind :-)
>
>> What we end up with is nice and clean and we leverage the well  
>> known class
>> List and its iterators.  As a matter of fact, I might toss out the  
>> chain
>> class all together and just have
>>
>> interface IoSession {
>>    List<IoFilter> getChain();
>> }
>>
>
> Hmm.. but we create a chain for an Acceptor or Connector, so very much
> doubt that chain class will be gone altogether. Once the app goes in
> action, we can modify it at runtime, as it gets associated with a
> Session

I think that the above paragraph does not support the the need for a  
chain class; though there may be something implied that I am not aware  
of.

I guess the point that I'm trying to make is that all these  
convenience classes and methods add noise. It makes it difficult to  
grasp the API when we write our own classes when perfectly good base  
classes already exist, e.g. Future<> and LinkedList<>.


Regards,
Alan


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Ashish <pa...@gmail.com>.
>
>> Have started looking into the FilterChain implementation and here are
>> some initial thoughts
>>
>> 1. Rename IoFilterChain as IoChannel - it gives a more clear picture
>> and is easy to understand like imagine as a Channel with multiple
>> stages aka IoFilters.
>> This came while I was drawing on paper to design something.
>>
>> 2. Have captured a couple of API's that are core to IoChannel
>>
>>             IoSession getSession();
>>
>>             IoFilter getHead();
>>
>>             IoFilter getNextFilter(IoFilter currentFilter);
>>
>>             List<IoFilter> getAll();
>>
>>             void addFilter(String name, IoFilter filter);
>>
>>             void addAfter(String baseName, String filterName,
>> IoFilter filter);
>>
>>             void removeFilter(String filterName);
>
> My Mina is a bit rusty so my comments may be a bit off base.  I would
> simplify this to
>
> List<IoFilter> getChain()
>
> Where one can re/move items in the chain.
>
> I would remove the filter name parameter since this is an aspect of the
> filter and not its role in the chain.

This thought did crossed my mind :-)

> What we end up with is nice and clean and we leverage the well known class
> List and its iterators.  As a matter of fact, I might toss out the chain
> class all together and just have
>
> interface IoSession {
>    List<IoFilter> getChain();
> }
>

Hmm.. but we create a chain for an Acceptor or Connector, so very much
doubt that chain class will be gone altogether. Once the app goes in
action, we can modify it at runtime, as it gets associated with a
Session

> Here we just got rid of one class and six methods for the same exact
> functionality while leveraging well known classes, i.e. LIst<>.

-- 
thanks
ashish

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Nov 26, 2009, at 2:25 AM, Ashish wrote:

> Have started looking into the FilterChain implementation and here are
> some initial thoughts
>
> 1. Rename IoFilterChain as IoChannel - it gives a more clear picture
> and is easy to understand like imagine as a Channel with multiple
> stages aka IoFilters.
> This came while I was drawing on paper to design something.
>
> 2. Have captured a couple of API's that are core to IoChannel
>
>              IoSession getSession();
>
>              IoFilter getHead();
>
>              IoFilter getNextFilter(IoFilter currentFilter);
>
>              List<IoFilter> getAll();
>
>              void addFilter(String name, IoFilter filter);
>
>              void addAfter(String baseName, String filterName,
> IoFilter filter);
>
>              void removeFilter(String filterName);

My Mina is a bit rusty so my comments may be a bit off base.  I would  
simplify this to

List<IoFilter> getChain()

Where one can re/move items in the chain.

I would remove the filter name parameter since this is an aspect of  
the filter and not its role in the chain.

What we end up with is nice and clean and we leverage the well known  
class List and its iterators.  As a matter of fact, I might toss out  
the chain class all together and just have

interface IoSession {
     List<IoFilter> getChain();
}


Here we just got rid of one class and six methods for the same exact  
functionality while leveraging well known classes, i.e. LIst<>.


Regards,
Alan





Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
On Nov 26, 2009, at 2:48 AM, Emmanuel Lecharny wrote:

> Ashish wrote:
>> Have started looking into the FilterChain implementation and here are
>> some initial thoughts
>>
>> 1. Rename IoFilterChain as IoChannel - it gives a more clear picture
>> and is easy to understand like imagine as a Channel with multiple
>> stages aka IoFilters.
>> This came while I was drawing on paper to design something.
>>
> Well, I would rather keep the current name. The 'filter' terminology  
> is quite commonly accepted for such a pattern. Servlet uses it (http://java.sun.com/blueprints/patterns/InterceptingFilter.html 
> ), and it also refers to the CoR pattern (http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern 
> ).

Also, one should avoid overlap w/ NIO channels, imo.


Regards,
Alan


Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Ashish <pa...@gmail.com>.
>>
>> Have started looking into the FilterChain implementation and here are
>> some initial thoughts
>>
>> 1. Rename IoFilterChain as IoChannel - it gives a more clear picture
>> and is easy to understand like imagine as a Channel with multiple
>> stages aka IoFilters.
>> This came while I was drawing on paper to design something.
>>
>
> Well, I would rather keep the current name. The 'filter' terminology is
> quite commonly accepted for such a pattern. Servlet uses it
> (http://java.sun.com/blueprints/patterns/InterceptingFilter.html), and it
> also refers to the CoR pattern
> (http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern).

Got it :-)

>> 2. Have captured a couple of API's that are core to IoChannel
>>
>>              IoSession getSession();
>>
>>              IoFilter getHead();
>>
>>              IoFilter getNextFilter(IoFilter currentFilter);
>>
>>              List<IoFilter> getAll();
>>
>>              void addFilter(String name, IoFilter filter);
>>
>>              void addAfter(String baseName, String filterName,
>> IoFilter filter);
>>
>>              void removeFilter(String filterName);
>>
>> There are a lot more API's in current implementation. I am not sure if
>> we need replace API or not.
>>
>
> There is something that need to be done in any case : check the current API,
> keep what is necessary, remove what is useless.

This what I did and brought out important things out. These were based
on the use cases for each API that I could think.
It will definitely evolve over time.


>> Also do we need the Generics version of these API's or its fine without
>> them?
>>
>
> The problem is that we are transferring Objects from one filter to the
> other, and it's a bit too generic. As already stated, it would be much
> better if we can pass a stream of "something", this something could
> perfectly be generic.
>
> Now, a question has been raised about the use of Stream : what about the
> semantic of this element, assuming that we will need a non-blocking stream ?

Will think in this direction :-)

>>
>> This is just the initial list. Will checkin the files once the name
>>
>
> Ok, thanks !

-- 
thanks
ashish

Blog: http://www.ashishpaliwal.com/blog
My Photo Galleries: http://www.pbase.com/ashishpaliwal

Re: [MINA 3.0] Initial thoughts on FilterChain

Posted by Emmanuel Lecharny <el...@apache.org>.
Ashish wrote:
> Have started looking into the FilterChain implementation and here are
> some initial thoughts
>
> 1. Rename IoFilterChain as IoChannel - it gives a more clear picture
> and is easy to understand like imagine as a Channel with multiple
> stages aka IoFilters.
> This came while I was drawing on paper to design something.
>   
Well, I would rather keep the current name. The 'filter' terminology is 
quite commonly accepted for such a pattern. Servlet uses it 
(http://java.sun.com/blueprints/patterns/InterceptingFilter.html), and 
it also refers to the CoR pattern 
(http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern).
> 2. Have captured a couple of API's that are core to IoChannel
>
>               IoSession getSession();
>
>               IoFilter getHead();
>
>               IoFilter getNextFilter(IoFilter currentFilter);
>
>               List<IoFilter> getAll();
>
>               void addFilter(String name, IoFilter filter);
>
>               void addAfter(String baseName, String filterName,
> IoFilter filter);
>
>               void removeFilter(String filterName);
>
> There are a lot more API's in current implementation. I am not sure if
> we need replace API or not.
>   
There is something that need to be done in any case : check the current 
API, keep what is necessary, remove what is useless.

> Also do we need the Generics version of these API's or its fine without them?
>   
The problem is that we are transferring Objects from one filter to the 
other, and it's a bit too generic. As already stated, it would be much 
better if we can pass a stream of "something", this something could 
perfectly be generic.

Now, a question has been raised about the use of Stream : what about the 
semantic of this element, assuming that we will need a non-blocking stream ?
> This is just the initial list. Will checkin the files once the name
>   
Ok, thanks !

-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org