Service Locator Problem

We have just started with the New Project & just discussing Architecture.

We want to use Service LOCATOR Pattern ..but with some modifications. We want BUSINESS DELEGATE to keep the track of all teh HOME OBJECTS ..& before actually going to SERVICE LOCATOR for teh Request , it sud look up teh Home Object in itself.

SERVICE LOCATOR pattern is working fine , but help me ..how to save to Home Object Refernce .

Thanks in Advance . Help Appreciated.

[482 byte] By [neetukumara] at [2007-9-27 9:48:51]
# 1

Looks like you need Caching of Home objects ...

here is a simple code to help you ...(if thats what you want .)

Have a class level SynchronizedMap :

ejbHomes = Collections.synchronizedMap(new HashMap());

and in the look-up method...first search for the home objects in the Map . If it is available then get it ... else create a new one and store it in the map .

EJBHome anEJBHome = (EJBHome) ejbHomes.get(homeClass);

if(anEJBHome == null)

{

anEJBHome = (EJBHome) javax.rmi.PortableRemoteObject.narrow (

ctx.lookup (homeClass.getName()), homeClass);

ejbHomes.put(homeClass, anEJBHome);

}

return anEJBHome;

Hope that helps .

Mohan

mohanNa at 2007-7-8 23:24:04 > top of Java-index,Other Topics,Patterns & OO Design...