commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rodney Waldhoff <rwaldh...@apache.org>
Subject [pool] Re: a commons.pool question
Date Thu, 02 Jan 2003 20:21:21 GMT
Like most commons projects, pool uses commons-dev and commons-user for
development and user discussions, respectively.

A simple implementation of KeyedObjectPool as a "map of pools" might look
like this:

class MapOfPools extends BaseKeyedObjectPool implements KeyedObjectPool {
  private Map map = new HashMap();

  public void setPool(Object key, ObjectPool pool) {
    map.put(key,pool);
  }

  public Object borrowObject(Object key) {
    ObjectPool pool = map.get(key);
    if(null == pool) {
      return null;
    } else {
      return pool.borrowObject();
    }
  }

  public void returnObject(Object key, Object value) {
    ObjectPool pool = map.get(key);
    if(null == pool) {
      throw new IllegalStateException();
    } else {
      pool.returnObject(value);
    }
  }
}

You can then create/configure the individual pools however you want, and
use setPool to "register" them with the KeyedObjectPool.

On Thu, 2 Jan 2003, Lirian Ostrovica wrote:

> Hello Rodney,
>
> Wondering if there is any mailing list for the commons.pool project, I
> wanted to ask you a quick question.
>
> In the documentation of interface KeyedObjectPool  I read the following:
>
> "KeyedObjectPool implementations may choose to store at most one
> instance per key value, or may choose to maintain a pool of instances
> for each key (essentially creating a Map of pools). "
>
> I am interested in a "Map of pools" implementation where I could be able
> to make individual configurations for each of those pools. I did not
> spent much time with the package, but it seams that even the interface
> itself does not allow this.
>
> I would really appreciate your opinion about this.
> thank you
>
> Lirian Ostrovica
>
>
>


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message