You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Zoltan Farkas (JIRA)" <ji...@apache.org> on 2011/02/02 21:12:29 UTC

[jira] Created: (POOL-183) potential new method for interface ObjectPool: returnAndValidateObject

potential new method for interface ObjectPool<T>: returnAndValidateObject
-------------------------------------------------------------------------

                 Key: POOL-183
                 URL: https://issues.apache.org/jira/browse/POOL-183
             Project: Commons Pool
          Issue Type: New Feature
    Affects Versions: 2.0
            Reporter: Zoltan Farkas
            Priority: Minor


Would it be possible to add a method:

void returnAndValidateObject(T obj) throws Exception

In general I was thinking of the following use case:

Object o = pool.borrowObject();
try
{
    .........
    o.doStuff();
    .........
    pool.returnObject(o);
}
catch(Exception e)
{
    // not sure what the cause is, let's make sure o is valid.
    pool.returnAndValidateObject(o);
}

the reason is that validation in general is an expensive operation, and enabling 
it all the time is inpractical.

any thoughts ?


-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (POOL-183) potential new method for interface ObjectPool: returnAndValidateObject

Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/POOL-183?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12990358#comment-12990358 ] 

Phil Steitz commented on POOL-183:
----------------------------------

Maybe to PoolUtils or something.  It would not make sense to add to the factory.  A pool "has a" factory, which it uses for all object lifecycle events.  I don't see any badness with exposing the pool factory via a getter.

> potential new method for interface ObjectPool<T>: returnAndValidateObject
> -------------------------------------------------------------------------
>
>                 Key: POOL-183
>                 URL: https://issues.apache.org/jira/browse/POOL-183
>             Project: Commons Pool
>          Issue Type: New Feature
>    Affects Versions: 2.0
>            Reporter: Zoltan Farkas
>            Priority: Minor
>
> Would it be possible to add a method:
> void returnAndValidateObject(T obj) throws Exception
> In general I was thinking of the following use case:
> Object o = pool.borrowObject();
> try
> {
>     .........
>     o.doStuff();
>     .........
>     pool.returnObject(o);
> }
> catch(Exception e)
> {
>     // not sure what the cause is, let's make sure o is valid.
>     pool.returnAndValidateObject(o);
> }
> the reason is that validation in general is an expensive operation, and enabling 
> it all the time is inpractical.
> any thoughts ?

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (POOL-183) potential new method for interface ObjectPool: returnAndValidateObject

Posted by "Mark Thomas (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/POOL-183?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mark Thomas resolved POOL-183.
------------------------------

    Resolution: Fixed

factory getter added
                
> potential new method for interface ObjectPool<T>: returnAndValidateObject
> -------------------------------------------------------------------------
>
>                 Key: POOL-183
>                 URL: https://issues.apache.org/jira/browse/POOL-183
>             Project: Commons Pool
>          Issue Type: New Feature
>    Affects Versions: 2.0
>            Reporter: Zoltan Farkas
>            Priority: Minor
>             Fix For: 2.0
>
>
> Would it be possible to add a method:
> void returnAndValidateObject(T obj) throws Exception
> In general I was thinking of the following use case:
> Object o = pool.borrowObject();
> try
> {
>     .........
>     o.doStuff();
>     .........
>     pool.returnObject(o);
> }
> catch(Exception e)
> {
>     // not sure what the cause is, let's make sure o is valid.
>     pool.returnAndValidateObject(o);
> }
> the reason is that validation in general is an expensive operation, and enabling 
> it all the time is inpractical.
> any thoughts ?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (POOL-183) potential new method for interface ObjectPool: returnAndValidateObject

Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/POOL-183?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12990289#comment-12990289 ] 

Gary Gregory commented on POOL-183:
-----------------------------------

Could we add {{validateAndReturn}} (as opposed to {{returnAndValidate}}) to {{PoolUtils}} or the factory?

> potential new method for interface ObjectPool<T>: returnAndValidateObject
> -------------------------------------------------------------------------
>
>                 Key: POOL-183
>                 URL: https://issues.apache.org/jira/browse/POOL-183
>             Project: Commons Pool
>          Issue Type: New Feature
>    Affects Versions: 2.0
>            Reporter: Zoltan Farkas
>            Priority: Minor
>
> Would it be possible to add a method:
> void returnAndValidateObject(T obj) throws Exception
> In general I was thinking of the following use case:
> Object o = pool.borrowObject();
> try
> {
>     .........
>     o.doStuff();
>     .........
>     pool.returnObject(o);
> }
> catch(Exception e)
> {
>     // not sure what the cause is, let's make sure o is valid.
>     pool.returnAndValidateObject(o);
> }
> the reason is that validation in general is an expensive operation, and enabling 
> it all the time is inpractical.
> any thoughts ?

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (POOL-183) potential new method for interface ObjectPool: returnAndValidateObject

Posted by "Zoltan Farkas (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/POOL-183?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12990158#comment-12990158 ] 

Zoltan Farkas commented on POOL-183:
------------------------------------

I don't see a problem from an interface contract point of view.

It is like returning merchandise to a store, they ask you what is wrong with the product. This can save the store testing every product that is returned.
This way they can poot it back on shelves or return it to the manufacturer ...

--zoly




> potential new method for interface ObjectPool<T>: returnAndValidateObject
> -------------------------------------------------------------------------
>
>                 Key: POOL-183
>                 URL: https://issues.apache.org/jira/browse/POOL-183
>             Project: Commons Pool
>          Issue Type: New Feature
>    Affects Versions: 2.0
>            Reporter: Zoltan Farkas
>            Priority: Minor
>
> Would it be possible to add a method:
> void returnAndValidateObject(T obj) throws Exception
> In general I was thinking of the following use case:
> Object o = pool.borrowObject();
> try
> {
>     .........
>     o.doStuff();
>     .........
>     pool.returnObject(o);
> }
> catch(Exception e)
> {
>     // not sure what the cause is, let's make sure o is valid.
>     pool.returnAndValidateObject(o);
> }
> the reason is that validation in general is an expensive operation, and enabling 
> it all the time is inpractical.
> any thoughts ?

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (POOL-183) potential new method for interface ObjectPool: returnAndValidateObject

Posted by "Mark Thomas (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/POOL-183?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mark Thomas updated POOL-183:
-----------------------------

    Fix Version/s: 2.0

Consider for 2.0.x

> potential new method for interface ObjectPool<T>: returnAndValidateObject
> -------------------------------------------------------------------------
>
>                 Key: POOL-183
>                 URL: https://issues.apache.org/jira/browse/POOL-183
>             Project: Commons Pool
>          Issue Type: New Feature
>    Affects Versions: 2.0
>            Reporter: Zoltan Farkas
>            Priority: Minor
>             Fix For: 2.0
>
>
> Would it be possible to add a method:
> void returnAndValidateObject(T obj) throws Exception
> In general I was thinking of the following use case:
> Object o = pool.borrowObject();
> try
> {
>     .........
>     o.doStuff();
>     .........
>     pool.returnObject(o);
> }
> catch(Exception e)
> {
>     // not sure what the cause is, let's make sure o is valid.
>     pool.returnAndValidateObject(o);
> }
> the reason is that validation in general is an expensive operation, and enabling 
> it all the time is inpractical.
> any thoughts ?

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] Commented: (POOL-183) potential new method for interface ObjectPool: returnAndValidateObject

Posted by "Holger Hoffstätte (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/POOL-183?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12990113#comment-12990113 ] 

Holger Hoffstätte commented on POOL-183:
----------------------------------------

This looks very confusing. We would be breaking the general interface contract because client code tries to act on behalf of both the pool and the factory, but only "sometimes" - and that is just not its role.
Also if validation is so expensive then nothing would stop a factory from doing so concurrently, while the client can quickly continue to do other things.


> potential new method for interface ObjectPool<T>: returnAndValidateObject
> -------------------------------------------------------------------------
>
>                 Key: POOL-183
>                 URL: https://issues.apache.org/jira/browse/POOL-183
>             Project: Commons Pool
>          Issue Type: New Feature
>    Affects Versions: 2.0
>            Reporter: Zoltan Farkas
>            Priority: Minor
>
> Would it be possible to add a method:
> void returnAndValidateObject(T obj) throws Exception
> In general I was thinking of the following use case:
> Object o = pool.borrowObject();
> try
> {
>     .........
>     o.doStuff();
>     .........
>     pool.returnObject(o);
> }
> catch(Exception e)
> {
>     // not sure what the cause is, let's make sure o is valid.
>     pool.returnAndValidateObject(o);
> }
> the reason is that validation in general is an expensive operation, and enabling 
> it all the time is inpractical.
> any thoughts ?

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Commented: (POOL-183) potential new method for interface ObjectPool: returnAndValidateObject

Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/POOL-183?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12990240#comment-12990240 ] 

Phil Steitz commented on POOL-183:
----------------------------------

I agree that adding the exact method above to the *interface* is not desirable (IMO).  I think the use case is legitimate; however, and I could see it addressed in at least three ways:

1. As suggested, but added to the GenericObjectPool (GOP) implementation, not the ObjectPool interface
2. Have GOP expose the factory's validate method
3. Add validate to the ObjectPool interface

I think 2 is probably the best.  Then the code example above becomes

{code}
Object o = pool.borrowObject();
try { ...
    o.doStuff();
    ...
    pool.returnObject(o);
} catch(Exception e) {
   if (!pool.validate(o)) {
   pool.invalidate(o);
} else {
pool.returnObject(o);
}
{code}

> potential new method for interface ObjectPool<T>: returnAndValidateObject
> -------------------------------------------------------------------------
>
>                 Key: POOL-183
>                 URL: https://issues.apache.org/jira/browse/POOL-183
>             Project: Commons Pool
>          Issue Type: New Feature
>    Affects Versions: 2.0
>            Reporter: Zoltan Farkas
>            Priority: Minor
>
> Would it be possible to add a method:
> void returnAndValidateObject(T obj) throws Exception
> In general I was thinking of the following use case:
> Object o = pool.borrowObject();
> try
> {
>     .........
>     o.doStuff();
>     .........
>     pool.returnObject(o);
> }
> catch(Exception e)
> {
>     // not sure what the cause is, let's make sure o is valid.
>     pool.returnAndValidateObject(o);
> }
> the reason is that validation in general is an expensive operation, and enabling 
> it all the time is inpractical.
> any thoughts ?

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (POOL-183) potential new method for interface ObjectPool: returnAndValidateObject

Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/POOL-183?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12990242#comment-12990242 ] 

Phil Steitz commented on POOL-183:
----------------------------------

I forgot to add my comment from the mailing list that a workaround to provide this functionality is to have code retain a reference to the pool's PoolableObjectFactory and use the factory to validate the instance, so in place of
{code}
pool.validate(o)
{code}
above which is impossible with current code, you have
{code}
factory.validate(o)
{code}

> potential new method for interface ObjectPool<T>: returnAndValidateObject
> -------------------------------------------------------------------------
>
>                 Key: POOL-183
>                 URL: https://issues.apache.org/jira/browse/POOL-183
>             Project: Commons Pool
>          Issue Type: New Feature
>    Affects Versions: 2.0
>            Reporter: Zoltan Farkas
>            Priority: Minor
>
> Would it be possible to add a method:
> void returnAndValidateObject(T obj) throws Exception
> In general I was thinking of the following use case:
> Object o = pool.borrowObject();
> try
> {
>     .........
>     o.doStuff();
>     .........
>     pool.returnObject(o);
> }
> catch(Exception e)
> {
>     // not sure what the cause is, let's make sure o is valid.
>     pool.returnAndValidateObject(o);
> }
> the reason is that validation in general is an expensive operation, and enabling 
> it all the time is inpractical.
> any thoughts ?

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (POOL-183) potential new method for interface ObjectPool: returnAndValidateObject

Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/POOL-183?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12990290#comment-12990290 ] 

Gary Gregory commented on POOL-183:
-----------------------------------

Also, the pool could track from which factory it was made.

> potential new method for interface ObjectPool<T>: returnAndValidateObject
> -------------------------------------------------------------------------
>
>                 Key: POOL-183
>                 URL: https://issues.apache.org/jira/browse/POOL-183
>             Project: Commons Pool
>          Issue Type: New Feature
>    Affects Versions: 2.0
>            Reporter: Zoltan Farkas
>            Priority: Minor
>
> Would it be possible to add a method:
> void returnAndValidateObject(T obj) throws Exception
> In general I was thinking of the following use case:
> Object o = pool.borrowObject();
> try
> {
>     .........
>     o.doStuff();
>     .........
>     pool.returnObject(o);
> }
> catch(Exception e)
> {
>     // not sure what the cause is, let's make sure o is valid.
>     pool.returnAndValidateObject(o);
> }
> the reason is that validation in general is an expensive operation, and enabling 
> it all the time is inpractical.
> any thoughts ?

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira