net.csdn.modules.thrift.pool
Interface PoolableObjectFactory<K,V>


public interface PoolableObjectFactory<K,V>

An interface defining life-cycle methods for instances to be served by a ObjectPool

By contract, when an ObjectPool delegates to a PoolableObjectFactory, createObject is called whenever a new instance is needed. validateObject is invoked for making sure they can be borrowed or returned from the pool. destroyObject is invoked on every instance when it is being "dropped" from the pool.

Author:
Bongjae Chang

Method Summary
 V createObject(K key)
          Create an instance that can be served by the pool
 void destroyObject(K key, V value)
          Destroy an instance no longer needed by the pool
 boolean validateObject(K key, V value)
          Ensures that the instance is safe to be borrowed and returned by the pool
 

Method Detail

createObject

V createObject(K key)
               throws Exception
Create an instance that can be served by the pool

Parameters:
key - the key used when constructing the object
Returns:
an instance that can be served by the pool
Throws:
Exception - if there is a problem creating a new instance

destroyObject

void destroyObject(K key,
                   V value)
                   throws Exception
Destroy an instance no longer needed by the pool

Parameters:
key - the key used when selecting the instance
value - the instance to be destroyed
Throws:
Exception - if there is a problem destroying value

validateObject

boolean validateObject(K key,
                       V value)
                       throws Exception
Ensures that the instance is safe to be borrowed and returned by the pool

Parameters:
key - the key used when selecting the object
value - the instance to be validated
Returns:
false if value is not valid and should be dropped from the pool, true otherwise
Throws:
Exception - if there is a problem validating value. an exception should be avoided as it may be swallowed by the pool implementation.


Copyright © 2014. All Rights Reserved.