Announcement Announcement Module
Collapse
No announcement yet.
How to pool keyed objects? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to pool keyed objects?

    Hi all,

    Actually, I'm developing an application which allows user to connect to multiple map (GIS) services, each of which having a unique service name. For instance, map service for the city A is called "MapCityA" and that for the city B is called "MapCityB". As creating connection to a map service is expensive, I think that it's worth pooling map service objects with service names as keys. Say, for the map service "MapCityB", "MapCityB" is used as the key and an idle object other than a newly created one should be retrieved from pool to serve an incoming request. But as I searched through the documention and even source codes of Spring 1.1.5, it seemed to me that only generic pooling mechanism was supported via the CommonPoolsTargetSource class. And nothing about keyed object pool was supprted. So, how could I get my problem solved in Spring? Is it good to use Spring with Jakarta Commons Pool so that I can make use of the GenericKeyedObjectPool to get the things done? Moreover, is it a right way to sovle this sort of problem with pooling?

    Regards,
    Nathan

  • #2
    My first guess would be a map of pools that you can inject in your service that needs the connections. Ideally you wouldn't want to be dealing with the KeyedObjectPool directly, would you?

    A quick and dirty solution would be to configure pools (using the PoolingTargetSource) for each of the connections and adding them to a map. This would result in the 'keyed' behavior. Tell me if you need more info or if you think this is not really a clean enough solution...

    regards,
    Alef Arendsen

    Comment


    • #3
      Hi Alef,

      Thanks for your prompt reply and your idea!

      Using Jakarta Commons Pool 1.2, I've extended the GenericKeyedObjectPoolFactory to create my own version of object factory named MapServiceKeyedObjectPoolFactory and then use it with the GenericKeyedObjectPool with success. Now, I wonder how to use these two classes in Spring. May I specify GenericKeyedObjectPool as a bean in the ApplicationContext and then inject the MapServiceKeyedObjectPoolFactory to it via constructor injection? Or may I simply treat the GenericKeyedObjectPool as a static variable in my controller, say an MultiActionController? Moreover, I would be grateful if you can say something about how to implement a clean solution in Spring?

      Thanks again for your reply and sorry for any inconveniences caused!

      Regards,
      Nathan

      Comment

      Working...
      X