users@grizzly.java.net

Re: DefaultProtocolChainInstanceHandler

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Mon, 11 Feb 2008 18:40:51 +0100

Hello,

IMHO to use correctly ProtocolChainInstanceHandler.offer(ProtocolChain)
- we need to add one more method to ProtocolChain API:
ProtocolChainInstanceHandler getInstanceHandler();

as at time, when ProtocolChain could be released - we don't know from
which ProtocolChainInstanceHandler the ProtocolChain was polled from.
Once method above will be added to the ProtocolChain interface - we can
easily implement ProtocolChain releasing in Controller's returnContext()
method:

    public void returnContext(Context ctx){
/ ProtocolChain protocolChain = ctx.getProtocolChain();
        protocolChain.getInstanceHandler().offer(protocolChain);
/ contexts.offer(ctx);
    }

What do you think?

Thanks.

WBR,
Alexey.


Erik Svensson wrote:
> On 2/11/08 4:16 PM, "Jeanfrancois Arcand" <Jeanfrancois.Arcand_at_Sun.COM>
> wrote:
>
>
>> Erik Svensson wrote:
>>
>>> A question here:
>>>
>>> In DefaultProtocolChainInstanceHandler
>>> the method poll looks like:
>>>
>>> public ProtocolChain poll() {
>>> ProtocolChain protocolChain = protocolChains.poll();
>>> if (protocolChain == null){
>>> protocolChain = new DefaultProtocolChain();
>>> }
>>> return protocolChain;
>>> }
>>>
>>> Should there be a 'offer(protocolChain)' here?
>>>
>>> public ProtocolChain poll() {
>>> ProtocolChain protocolChain = protocolChains.poll();
>>> if (protocolChain == null){
>>> protocolChain = new DefaultProtocolChain();
>>> // PATCH
>>> offer(protocolChain);
>>> // END PATCH
>>> }
>>> return protocolChain;
>>> }
>>>
>>> Otherwise a new protocolchain will be created everytime poll is called
>>> unless one is manually added through offer.
>>>
>> The contract here is when you do poll, you also invoke the
>> DefaultProtocolChainInstanceHandler.offer() method. But you found a bug
>> in Grizzly as the offer method is never called!!
>>
>> Originally, the offer() method was called...looks like we lost it
>> between 1.5.x and 1.7.1! Let me re-add it so your stuff can work. Now
>> Your patch will not work as two thread might ends up with the same
>> protocol chain, and since the protocol chain are stateful, we will get
>> data corruption.
>>
>
> Yes, I noticed that. I need to think out some other way to cut down the code
> needed to set things up before I can give this to my co-developers.
>
> cheers
> Erik Svensson, SIX AB
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>
>