You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hivemind.apache.org by Ovidiu Hurducas <ov...@artsoft-consult.ro> on 2006/03/20 08:31:39 UTC

Accessing registry from a servlet without recreating a new instance

Greetings,

I’m using Hivemind+Tapestry+Hibernate to build a site. I have a 
javax.servlet.Filter object where I need to do some operations with a 
Hivemind service that uses Hibernate.

To access the registry from the filter I’m using the example from the 
Hivemind documentation:

Registry registry = RegistryBuilder.constructDefaultRegistry();

MyService service = (MyService) registry.getService("com.mypackage.MyService", MyService.class);

 

However this is not good. The registry is recreated and the Hibernate 
configuration is read again.

There is a way to access an existing registry that is already 
initialized? I don’t want to recreate the registry twice.

Thank you,

Ovidiu

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


Re: Accessing registry from a servlet without recreating a new instance

Posted by Norbert Sándor <de...@erinors.com>.
Override ApplicationServlet.constructRegistry() and store the registry 
somewhere which is accessible from the filter, eg. the servletcontext.

    @Override
    protected Registry constructRegistry(ServletConfig config)
    {
        registry = super.constructRegistry(config);

        config.getServletContext().setAttribute("SomeAttributeName", 
registry);

        return registry;
    }

Regards,
Norbi


Ovidiu Hurducas wrote:
> Greetings,
>
> I’m using Hivemind+Tapestry+Hibernate to build a site. I have a 
> javax.servlet.Filter object where I need to do some operations with a 
> Hivemind service that uses Hibernate.
>
> To access the registry from the filter I’m using the example from the 
> Hivemind documentation:
>
> Registry registry = RegistryBuilder.constructDefaultRegistry();
>
> MyService service = (MyService) 
> registry.getService("com.mypackage.MyService", MyService.class);
>
>
>
> However this is not good. The registry is recreated and the Hibernate 
> configuration is read again.
>
> There is a way to access an existing registry that is already 
> initialized? I don’t want to recreate the registry twice.
>
> Thank you,
>
> Ovidiu
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
>
>
>
>
>

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


Re: Accessing registry from a servlet without recreating a new instance

Posted by Nick Faiz <ni...@q9software.com>.
The ApplicationServlet stores the created registry as an attribute in  
the servlet context.

After it's initialized you can simply ask for it back and store it  
wherever you want.


   public void init(ServletConfig config) throws ServletException {
     super.init(config);

     String name = config.getServletName();
     String registryKey = "org.apache.tapestry.Registry:" + name;

     Registry registry = (Registry) config.getServletContext 
().getAttribute(registryKey);
     HiveAccess hiveAccess = HiveAccessor.getInstance();
     hiveAccess.initialize(registry);

     log.debug("Portal initialized.");
   }

This works for Tapestry 4.0, at least. The HiveAccessor is a  
convenience singleton which holds a reference to the registry for me.

Nick



On 20/03/2006, at 6:31 PM, Ovidiu Hurducas wrote:

> Greetings,
>
> I’m using Hivemind+Tapestry+Hibernate to build a site. I have a  
> javax.servlet.Filter object where I need to do some operations with  
> a Hivemind service that uses Hibernate.
>
> To access the registry from the filter I’m using the example from  
> the Hivemind documentation:
>
> Registry registry = RegistryBuilder.constructDefaultRegistry();
>
> MyService service = (MyService) registry.getService 
> ("com.mypackage.MyService", MyService.class);
>
>
> However this is not good. The registry is recreated and the  
> Hibernate configuration is read again.
>
> There is a way to access an existing registry that is already  
> initialized? I don’t want to recreate the registry twice.
>
> Thank you,
>
> Ovidiu
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
>

Nick Faiz,
Developer
www.q9software.com



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