You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by John McNally <jm...@collab.net> on 2001/08/17 02:57:03 UTC

Contexts retaining old values in 3.0

if I have a template

$foo
#set( $foo = "bar" )

The first time I hit the template I get

$foo

as would be expected, but if I hit the template again, I get

bar

and the template always returns "bar" from that point on.


Any ideas?

john mcnally

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: Contexts retaining old values in 3.0

Posted by Jason van Zyl <jv...@apache.org>.
On 8/16/01 10:07 PM, "Jon Stevens" <jo...@latchkey.com> wrote:

> on 8/16/01 6:54 PM, "Jason van Zyl" <jv...@apache.org> wrote:
> 
>> I was only trying to preserve the behavior but it is likely that some things
>> got wanked because we no tests for behaviour because the behaviour isn't
>> defined.
> 
> Right...
> 
>> How about a clear definition of the desired behavior and than start hacking
>> around.
> 
> Simple, here are the rules for tools:
> 
> * Scopes:
> *
> *  global:     tool is instantiated once and that instance is available
> *              to all templates for all requests. Tool must be threadsafe.
> *
> *  request:    tool is instantiated once for each request (although the
> *              PoolService is used to recycle instances). Tool need not
> *              be threadsafe.
> *
> *  session:    tool is instantiated once for each user session, and is
> *              stored in the user's temporary hashtable. Tool should be
> *              threadsafe.
> *
> *  persistent: tool is instantitated once for each use session, and
> *              is stored in the user's permanent hashtable. This means
> *              for a logged in user the tool will be persisted in the
> *              user's objectdata. Tool should be threadsafe and
> *              Serializable.
> 
> For anything else placed into the context, it is on a request basis as
> defined above. Each request gets a new context with the pull tools in place
> according to the documentation above.

That's for tools. I don't use #set in templates so it's not something I've
thought about. But a valid user question may be "If I use #set in a
template, what is the scope the value?" which is not covered by the above.
You can never be too clear.
 
>> Fix what you need to if it's breaking scarab but there have never
>> been any clear pieces of documentation stating how the internals work.
> 
> It isn't just about Scarab.

It probably is right now :-) Out of alpha the is a different story.
 
> You wouldn't want every single #set() in a template (or every context.put()
> in an Action or Screen) to be carried over into the next request as it
> creates a memory leak because those objects are never disposed of...even if
> they are never used again.

I think you know me better than that, not like I'm going to leave that in
there for a release.

> I will work on this code tonight since you seem busy with other stuff.

Cool and the gang.
 
> Thanks,
> 
> -jon
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-dev-help@jakarta.apache.org

-- 

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: Contexts retaining old values in 3.0

Posted by Jon Stevens <jo...@latchkey.com>.
on 8/16/01 6:54 PM, "Jason van Zyl" <jv...@apache.org> wrote:

> I was only trying to preserve the behavior but it is likely that some things
> got wanked because we no tests for behaviour because the behaviour isn't
> defined.

Right...

> How about a clear definition of the desired behavior and than start hacking
> around.

Simple, here are the rules for tools:

 * Scopes:
 *
 *  global:     tool is instantiated once and that instance is available
 *              to all templates for all requests. Tool must be threadsafe.
 *
 *  request:    tool is instantiated once for each request (although the
 *              PoolService is used to recycle instances). Tool need not
 *              be threadsafe.
 *
 *  session:    tool is instantiated once for each user session, and is
 *              stored in the user's temporary hashtable. Tool should be
 *              threadsafe.
 *
 *  persistent: tool is instantitated once for each use session, and
 *              is stored in the user's permanent hashtable. This means
 *              for a logged in user the tool will be persisted in the
 *              user's objectdata. Tool should be threadsafe and
 *              Serializable.

For anything else placed into the context, it is on a request basis as
defined above. Each request gets a new context with the pull tools in place
according to the documentation above.

> Fix what you need to if it's breaking scarab but there have never
> been any clear pieces of documentation stating how the internals work.

It isn't just about Scarab.

You wouldn't want every single #set() in a template (or every context.put()
in an Action or Screen) to be carried over into the next request as it
creates a memory leak because those objects are never disposed of...even if
they are never used again.

I will work on this code tonight since you seem busy with other stuff.

Thanks,

-jon


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: Contexts retaining old values in 3.0

Posted by Jason van Zyl <jv...@apache.org>.
On 8/16/01 9:33 PM, "Jon Stevens" <jo...@latchkey.com> wrote:

> on 8/16/01 6:12 PM, "Jon Stevens" <jo...@latchkey.com> wrote:
> 
>> It "seems" like all of the objects which are being #set in a template are
>> being set into the Global scope context instead of the request context and
>> therefore are being kept/held across requests to the server.
> 
> Now, looking at the code, this is the case and this is bad...this isn't the
> way that it should work...I also see another area that is messed up, for
> example:
> 
>   public void preExecuteAction(RunData data)
>       throws Exception
>   {
>       TemplateContext context = Module.getTemplateContext(data);
>       data.setTemp(Turbine.CONTEXT, context);
>   }
> 
> If you look at Module.getTemplateContext(data), it already does a
> data.setTemp(...) within the method itself.
> 
> Jason, we can't put a global context into the templates like that because
> any #set references are going to be putting things into memory on the server
> across requests and that is bad.
> 
> Can you fix it or do you want me to start hacking around?

I was only trying to preserve the behavior but it is likely that some things
got wanked because we no tests for behaviour because the behaviour isn't
defined.

How about a clear definition of the desired behavior and than start hacking
around. Fix what you need to if it's breaking scarab but there have never
been any clear pieces of documentation stating how the internals work.

What john and you found is ideal material for a test.
 
> Thanks,
> 
> -jon
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-dev-help@jakarta.apache.org

-- 

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: Contexts retaining old values in 3.0

Posted by Jon Stevens <jo...@latchkey.com>.
on 8/16/01 6:12 PM, "Jon Stevens" <jo...@latchkey.com> wrote:

> It "seems" like all of the objects which are being #set in a template are
> being set into the Global scope context instead of the request context and
> therefore are being kept/held across requests to the server.

Now, looking at the code, this is the case and this is bad...this isn't the
way that it should work...I also see another area that is messed up, for
example:

    public void preExecuteAction(RunData data)
        throws Exception
    {
        TemplateContext context = Module.getTemplateContext(data);
        data.setTemp(Turbine.CONTEXT, context);
    }

If you look at Module.getTemplateContext(data), it already does a
data.setTemp(...) within the method itself.

Jason, we can't put a global context into the templates like that because
any #set references are going to be putting things into memory on the server
across requests and that is bad.

Can you fix it or do you want me to start hacking around?

Thanks,

-jon


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: Contexts retaining old values in 3.0

Posted by Jon Stevens <jo...@latchkey.com>.
on 8/16/01 7:09 PM, "Jason van Zyl" <jv...@apache.org> wrote:

> Well it's not ok, it sucks so if you can clean up the TemplateContext
> implementation to deal with chaining we will have what we did with Velocity.
> The implementation in the ContextAdapter that goes with Velocity should be
> ok because Velocity supports the idea. Not sure how easy it will be with
> other templating solutions.

Ok...i will do that then...

-jon


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: Contexts retaining old values in 3.0

Posted by Jason van Zyl <jv...@apache.org>.
On 8/16/01 10:02 PM, "Jon Stevens" <jo...@latchkey.com> wrote:

> on 8/16/01 6:56 PM, "Jason van Zyl" <jv...@apache.org> wrote:
> 
>> The context implementation is raw still, and doesn't take into account
>> chained contexts like velocity contexts. I needed a way to emulate this for
>> all template implementations but everything is going into a single context
>> right now.
> 
> Ok...for now, 

Well it's not ok, it sucks so if you can clean up the TemplateContext
implementation to deal with chaining we will have what we did with Velocity.
The implementation in the ContextAdapter that goes with Velocity should be
ok because Velocity supports the idea. Not sure how easy it will be with
other templating solutions.

> I'm going to emulate it in code...I'm going to work on this
> when I get home tonight...
> 
> -jon
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-dev-help@jakarta.apache.org

-- 

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: Contexts retaining old values in 3.0

Posted by Jon Stevens <jo...@latchkey.com>.
on 8/16/01 6:56 PM, "Jason van Zyl" <jv...@apache.org> wrote:

> The context implementation is raw still, and doesn't take into account
> chained contexts like velocity contexts. I needed a way to emulate this for
> all template implementations but everything is going into a single context
> right now.

Ok...for now, I'm going to emulate it in code...I'm going to work on this
when I get home tonight...

-jon


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: Contexts retaining old values in 3.0

Posted by Jason van Zyl <jv...@apache.org>.
On 8/16/01 9:12 PM, "Jon Stevens" <jo...@latchkey.com> wrote:

> on 8/16/01 5:57 PM, "John McNally" <jm...@collab.net> wrote:
> 
>> if I have a template
>> 
>> $foo
>> #set( $foo = "bar" )
>> 
>> The first time I hit the template I get
>> 
>> $foo
>> 
>> as would be expected, but if I hit the template again, I get
>> 
>> bar
>> 
>> and the template always returns "bar" from that point on.
>> 
>> 
>> Any ideas?
>> 
>> john mcnally
> 
> I can duplicate this as well..this is with latest turbine3 from CVS.
> 
> It "seems" like all of the objects which are being #set in a template are
> being set into the Global scope context instead of the request context and
> therefore are being kept/held across requests to the server.
> 
> Jason, can you look into this?

The context implementation is raw still, and doesn't take into account
chained contexts like velocity contexts. I needed a way to emulate this for
all template implementations but everything is going into a single context
right now.
 
> thanks,
> 
> -jon
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-dev-help@jakarta.apache.org

-- 

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: Contexts retaining old values in 3.0

Posted by Jon Stevens <jo...@latchkey.com>.
on 8/16/01 5:57 PM, "John McNally" <jm...@collab.net> wrote:

> if I have a template
> 
> $foo
> #set( $foo = "bar" )
> 
> The first time I hit the template I get
> 
> $foo
> 
> as would be expected, but if I hit the template again, I get
> 
> bar
> 
> and the template always returns "bar" from that point on.
> 
> 
> Any ideas?
> 
> john mcnally

I can duplicate this as well..this is with latest turbine3 from CVS.

It "seems" like all of the objects which are being #set in a template are
being set into the Global scope context instead of the request context and
therefore are being kept/held across requests to the server.

Jason, can you look into this?

thanks,

-jon


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org