Although I'm not sure if this will be directly applicable to your problem, 
I've taken the following layered approach to getting access to the Hivemind 
Registry singleton from various portions of my application.

First, I created a derivded servlet class that extends ApplicationServlet, 
where the Hivemind Registry is initialized, and which makes available through 
a static getter a reference to that Registry singleton.

It obtains the reference to the Registry by overridding the init() method, 
calling super.init(), the grabbing the Registry reference out of the servlet 
context where ApplicationServlet stashes it:

public class AltosServlet extends ApplicationServlet {
    private static Registry sRegistry;
    private static final String REGISTRY_KEY = 
"org.apache.tapestry.Registry:altos";

    public void init( ServletConfig config ) throws ServletException {
        super.init( config ); 
        Registry r = (Registry) 
getServletContext().getAttribute( REGISTRY_KEY );
        sRegistry = r;
    }

    public static Registry getRegistry() {
        return sRegistry;
    }
}

Using that reference, you could then do:

ISessionOwner mySO = (ISessionOwner)  
AltosServlet.getRegistry().getService(ISessionOwner.class);

From anywhere in your application. Also keep in mind that if your 
ISessionOwner implementation also implements the Discardable interface, you 
can then use that hook to be notified when the request thread is about to be 
cleaned up:

    public void threadDidDiscardService() {
        if ( mSession != null ) {
            mSession.close();
            mSession = null;
        }
    }

This is all well documented in Kent's eBook ;)

Regards,
jason


On Thursday 20 October 2005 08:47, Ron Piterman wrote:
> Hi all,
> I need to do some session cleanup, calling a hivemind service - how do I
> reference hivemind from my SessionListener object?
> Cheers,
> Ron
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

-- 
Jason L. Buberel -- [EMAIL PROTECTED] -- www.buberel.org
+1.650.483.1989  -- jabber:[EMAIL PROTECTED]

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

Reply via email to