I want to access HiveMind services in my Tapestry application.
In my engine I put this:-
protected Object createGlobal(RequestContext context) {
Global global = (Global) super.createGlobal(context);
global.initResitry(context);
return global;
}
public UserService getUserService() {
if (userService == null) {
userService = (UserService) ((Global)
getGlobal()).getRegistry().getService(UserService.class);
}
return userService;
}
I use the engine to instantiate the Global object with the registry:-
// for services
public void initResitry(RequestContext context) {
if (registry == null) {
registry = HiveMindFilter.getRegistry(context.getRequest());
}
}
I am interested in comments on this design. How are others dealing with
their HiveMind service references in Tapestry?
My main question is about how services inside HiveMind will share a
"SessionManager" service, and can I make that service private to classes
inside HiveMind.
I have considered a SessionManager interface but at the moment simply have a
implementation like this:-
public class HibernateSessionManager {
private static final SessionFactory sessionFactory;
static {
// Create the SessionFactory
try {
sessionFactory = new
Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
// variable to hold a session object for a thread
public static final ThreadLocal session = new ThreadLocal();
// obtain the session of the current thread
public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
// close the session on the current thread
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null) s.close();
}
}
I suppose as everything is static I can just use static access, but is that
best practice as that will tie me to an implemenation class! I would rather
create an interface and be get a ref to the implementing class that is
defined in the xml configs.
Is there an example xml to show me this please?
TIA
John
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]