// see if it's in the cache
if (cache.containsKey(name)) {
// cache HomeHandle objects since they are maintained
// by the container
HomeHandle hh = (HomeHandle)cache.get(name);
try {
return hh.getEJBHome();
} catch(RemoteException re) {
// some kind of problem -- fall through to
// relookup below
}
}
// access to the shared context as well as modifications
// to the HashMap must be synchronized. Hopefully the
// majority of cases are handled above
synchronized(this) {
try {
Object rRef = context.lookup(name);
EJBHome eh =
(EJBHome)PortableRemoteObject.narrow(rRef, type);
cache.put(name, eh.getHomeHandle());
return eh;
} catch(Exception ex) {
throw new ServiceLocatorException("Unable to find EJB",
ex);
}
}