To integrate HiveMind and Tapestry, we use the hivemind servlet filter. It
manages all the thread and pooled type services very well.

Our web.xml has 

        <filter>
        <filter-name>HiveMindFilter</filter-name>
 
<filter-class>org.apache.hivemind.servlet.HiveMindFilter</filter-class>
        </filter>    

        <filter-mapping>
        <filter-name>HiveMindFilter</filter-name>
          <servlet-name>wo</servlet-name>
        </filter-mapping>

And our Engine has the following:

    protected Object createGlobal(RequestContext arg0) {
        Global global = (Global) super.createGlobal(arg0);
        global.setRegistry(HiveMindFilter.getRegistry(arg0.getRequest()));
        return global;
    }

And our global has a method that returns the services required by the
application. Our application only has about 8 services, so this is a
workable design for us. 

    /**
     * Return the Security service
     * @return
     */
    public Security getSecurity() {
        return (Security) getService(Security.class);
    }

    private Object getService(Class clazz) {
        return this.registry.getService(clazz.getName(), clazz);
    }

    public void setRegistry(Registry registry) {
        SC.checkstate(this.registry == null);
        SC.checknull(registry);
        this.registry = registry;
    }

As for how to access Hibernate, I would investigate Threaded services. A new
instance is created each time a thread needs it. The Hivemind filter manages
notification and throwing away Threaded services at the end of the http
request cycle. Seems to me that this is what you are looking for.

If Session is an interface, I would create a Session service. That service
would be injected with a SessionFactory service. I would make the Session
service threaded. It would implement the Discardable interface. That
interface supports a method called 'threadDidDiscardService' which is called
when the service is no longer needed by a thread. The HiveMindFilter manages
the threaded services for you in a web application. To implement such a
service, the first access to the session would have to get a session from
the factory and start a transaction. I'm not sure what the discard would
have to do, possibly commit the transaction and close the session, or you
might not want to deal with transactions in the SessionService. The way
HiveMind works, a transaction could be a separate service that is injected
with the SessionService. This could work by maybe beginning a transaction
when you get the service. At the discard time it could rollback the
transaction if it has not been committed.

Another alternative would be to check out the Spring/HiveMind integration
because I've heard that Spring does a really nice job of exposing Hibernate
in a IoC container. If you check out the HiveMind wiki, there are some
Hibernate integration ideas. If you come up with something working and cool
you might want to throw your ideas on the pile.

We don't happen to Hibernate, but we had a very similar problem with the ORM
we use.

By the way, if you really want to twist your brain and know about something
cool, check out how HiveMind proxies all the thread service and pooled
service stuff so that all threads have the same object instance, yet have
their own private executing instance of a service for the thread. It is
magic.

Richard


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to