You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Jeremy Quinn <je...@media.demon.co.uk> on 2003/10/29 14:21:33 UTC

'dispose' method of component

Hi All

I am working with the 'authentication-fw' in FlowScript, having added  
an authenticator that uses Hibernate. ie. My authentication pipeline is  
now a FlowScript which calls an internal pipeline to produce the  
authentication XML for the framework.

I am finding that the 'dispose' method of my Hibernate component (based  
on Hugo Burm's HibernateFactory) never gets called, until I quit Jetty,  
which is not what I expected.

This is my authenticator script:

// this function is called internally by the auth-fw,
// to get a pipeline to return an authentication XML stream
function authenticate () {
   var username = cocoon.parameters["user"];
   var password = cocoon.parameters["pass"];
   var factory =  
cocoon.getComponent(Packages.[long.path.deleted].PersistanceFactory.ROLE 
);
   var session = factory.createSession();
   try {
     var user = Packages.[long.path.deleted].UserPeer.login(session,  
username, password, null);
     if (user != null) cocoon.log.info ("Got User : " + user.email); //  
lubbly jubbly
     cocoon.sendPage ("screen/authenticate", {user: user}); // a  
JXTemplateGenerator pipeline
   } catch (e) {
     cocoon.log.error (e.getMessage ());
   } finally {        //catch (return) not working
     cocoon.log.info ("Disposing of Factory"); // I see this message
     cocoon.releaseComponent(factory); // I do not see the log message  
from the dispose method
   }
}

public class HibernateFactory
   extends AbstractLogEnabled
   implements PersistanceFactory, Configurable, Serviceable,  
Initializable, Disposable, ThreadSafe

The dispose method looks like this:

public final void dispose()  {
   //if (getLogger().isDebugEnabled()) getLogger().debug("Hibernate  
dispose called");
   // why oh why is this logger null!!!!
   System.out.println ("Hibernate dispose called"); // I never see this
   try {
     sf.close();
   } catch ( Exception e) {
     //if (getLogger().isErrorEnabled()) getLogger().error("Hibernate:"  
+ e.getMessage());
     System.out.println ("Hibernate:" + e.getMessage());
   }  finally {
     sf = null;
   }
   this.disposed = true;
   this.manager = null;
  }

I thought cocoon.releaseComponent(factory) should call the dispose  
method .....
Is there a method it will call if I provided one?

Thanks for any suggestions.

regards Jeremy


Re: 'dispose' method of component

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On Wednesday, October 29, 2003, at 09:03 PM, Giacomo Pati wrote:

>
>
> Jeremy Quinn wrote:
>> On Wednesday, October 29, 2003, at 01:40 PM, Giacomo Pati wrote:
>>> Hi Jeremy
>>>
>>> Jeremy Quinn wrote:
>>>
>>> <snipped>
>>>
>>>> public class HibernateFactory
>>>>   extends AbstractLogEnabled
>>>>   implements PersistanceFactory, Configurable, Serviceable,  
>>>> Initializable, Disposable, ThreadSafe
>>>
>>>
>>> IIRC ThreadSafe components are disposed only when the 
>>> ComponentManager is disposed (read shutdown of jetty). The 
>>> counterpart interface of Disposable is Initializable which is called 
>>> once during the life time of the component as with the Disposable.
>> Thanks for your clarification.
>> So is it possible to have a method called on my component when :
>>     cocoon.releaseComponent (component)
>> is called on it?
>
> Not on ThreadSafe components. The only one I know is a Recyclable 
> component (which is a sub type of Poolable) but I don't think this is 
> what you want your component to be.

Thanks for your help, Giacomo.

regards Jeremy


Re: 'dispose' method of component

Posted by Giacomo Pati <gi...@apache.org>.

Jeremy Quinn wrote:
> 
> On Wednesday, October 29, 2003, at 01:40 PM, Giacomo Pati wrote:
> 
>> Hi Jeremy
>>
>> Jeremy Quinn wrote:
>>
>> <snipped>
>>
>>> public class HibernateFactory
>>>   extends AbstractLogEnabled
>>>   implements PersistanceFactory, Configurable, Serviceable,  
>>> Initializable, Disposable, ThreadSafe
>>
>>
>> IIRC ThreadSafe components are disposed only when the ComponentManager 
>> is disposed (read shutdown of jetty). The counterpart interface of 
>> Disposable is Initializable which is called once during the life time 
>> of the component as with the Disposable.
> 
> 
> Thanks for your clarification.
> 
> So is it possible to have a method called on my component when :
> 
>     cocoon.releaseComponent (component)
> 
> is called on it?

Not on ThreadSafe components. The only one I know is a Recyclable 
component (which is a sub type of Poolable) but I don't think this is 
what you want your component to be.

-- 
Giacomo Pati
Otego AG, Switzerland - http://www.otego.com
Orixo, the XML business alliance - http://www.orixo.com



Re: 'dispose' method of component

Posted by Jeremy Quinn <je...@luminas.co.uk>.
On Wednesday, October 29, 2003, at 01:40 PM, Giacomo Pati wrote:

> Hi Jeremy
>
> Jeremy Quinn wrote:
>
> <snipped>
>
>> public class HibernateFactory
>>   extends AbstractLogEnabled
>>   implements PersistanceFactory, Configurable, Serviceable,  
>> Initializable, Disposable, ThreadSafe
>
> IIRC ThreadSafe components are disposed only when the ComponentManager 
> is disposed (read shutdown of jetty). The counterpart interface of 
> Disposable is Initializable which is called once during the life time 
> of the component as with the Disposable.

Thanks for your clarification.

So is it possible to have a method called on my component when :

	cocoon.releaseComponent (component)

is called on it?

Thanks for your help

regards Jeremy


Re: 'dispose' method of component

Posted by Giacomo Pati <gi...@apache.org>.
Hi Jeremy

Jeremy Quinn wrote:

<snipped>

> public class HibernateFactory
>   extends AbstractLogEnabled
>   implements PersistanceFactory, Configurable, Serviceable,  
> Initializable, Disposable, ThreadSafe

IIRC ThreadSafe components are disposed only when the ComponentManager 
is disposed (read shutdown of jetty). The counterpart interface of 
Disposable is Initializable which is called once during the life time of 
the component as with the Disposable.

-- 
Giacomo Pati
Otego AG, Switzerland - http://www.otego.com
Orixo, the XML business alliance - http://www.orixo.com