This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Accessing remote services using dynamic hostnames

Oct 30th, 2005, 06:19 AM

I'm in the process of converting my application to use Spring DI, and hopefully eventually other portions of Spring. Spring makes a lot of sense, and works great for many areas of our system (with a bit of tweaking) but there is one need that I'm not yet sure of the best solution.

We have a very distributed system in a tree-like model. The root system has to talk to 500+ different systems all of which have identical (EJB) services, and each of those systems has to talk between 2 and 30 different systems, each of which has a different set of identical (RMI) services. Having static configuration for all these hosts is simply not practical. Especially, as the system can have new systems added at any time.

Today, we use a ServiceFactory that takes (essentially) the hostname and service required to get a remote service for each of theses hosts. I'm writing a new ServiceFactory that is Spring-aware. I've had two people (including Keith Donald at the NFJS Atlanta conference) suggest two different solutions to this problem, but with virtually no Spring knowledge at the time, they went right over my head.

So, what is the best way to get a remote service proxy for a dynamic host?

Comment

You could consider using a JndiObjectTargetSource or a possible subclass. You would set this on your EJB or RMI proxy, and for each call to getTarget() you would do your dynamic host assignment. Possibly caching each JNDI object by hostname.

Comment

You could consider using a JndiObjectTargetSource or a possible subclass. You would set this on your EJB or RMI proxy, and for each call to getTarget() you would do your dynamic host assignment. Possibly caching each JNDI object by hostname.

I'm not sure I truly understand, "set this on your proxy". To me, the proxy only has methods for business interface methods, and by the time I have a proxy object isn't it already "connected"?

Comment

Basically you need to have your EJB proxy lookup the EJB each time, using some algorithm to choose the host. Underneath you'd probably want to create some sort of cache of all the various home interfaces, one for each server. I'd suggest creating a subclass of SimpleRemoteStatelessSessionProxyFactoryBean that managed this. Each item in the cache would probably contain a copy of the looked up home, and probably its own JndiTemplate with the parameters needed to relookup the home if the home is lost. Take a look at the source code for SimpleRemoteStatelessSessionProxyFactoryBean and its subclasses to see where to override.