commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Carman" <ja...@carmanconsulting.com>
Subject RE: [Pool] force client to return the borrowed object to the pool
Date Fri, 24 Jun 2005 11:02:18 GMT
If the objects in the pool implement some sort of interface which your
client uses, you could make them return themselves to the pool.  All you
would have to do is wrap them with a proxy (as suggested below) which
implements the "client interface", but make the proxy timeout after a bit of
time, returning the wrapped object to the pool for others to use (if it
hasn't been returned already).  If the client tries to use the proxy object
after it has timed out, a RuntimeException could be thrown.  Though, the
current architecture doesn't allow you to wrap the actual pooled object.  It
returns the pooled object as-is.  But, you would need to be able to create a
new proxy each time an object is borrowed.  That might be a neat addition to
the framework.  
 
-----Original Message-----
From: Dirk Verbeeck [mailto:dirk.verbeeck@pandora.be] 
Sent: Friday, June 24, 2005 1:51 AM
To: Jakarta Commons Developers List
Subject: Re: [Pool] force client to return the borrowed object to the pool

Edin,

The technique you propose can already be seen in DBCP.
The real database connections are wrapped with a "poolable" delegating 
wrapper. The close method has been overwritten to call returnObject.

But an example inside commons-pool would be nice. In the wiki or on the 
website.
Maybe some general code could be written to support this pattern.
Using reflexion/java proxy or even bytecode manipulation you could 
implement the "forced" return of the object.

The challenge is of course to find an elegant implementation that 
doesn't add too much complexity.

Cheers
Dirk



Edin Ahmetagic wrote:
> Hello,
> 
> could there be an architectual solution to force the clients, that borrows
> objects from the pool, to return this back?
> An approach coud be, to have an Interface "PoolableObject" which have to
be
> implemented by the Objects that want to be pooled. In this Interface there
> could be an methode returnObject.
> I`am not sure if this is really possible, it is only an idea.
> 
> Edin
> --
> 



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


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


Mime
View raw message