Class AbstractObjectWrapper<T,E extends Exception>
- java.lang.Object
-
- de.aristaflow.adept2.util.objectpool.AbstractObjectWrapper<T,E>
-
public abstract class AbstractObjectWrapper<T,E extends Exception> extends Object
This is an abstract base class for wrapper implementations. It's only provided for convenience, i.e. object wrappers are not required to extend it.- See Also:
ObjectWrapperLifeCycle
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractObjectWrapper(ObjectPool<T,E> objectPool, T pooledObject)
Constructs a newAbstractObjectWrapper
for the given object and pool.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_checkIn()
Checks the wrapped object back into the object pool.protected void
_ensureIsValid()
Simply returns if the wrapper is still valid and throws anIllegalStateException
if it isn't.long
_getLastActiveTime()
Returns the last active time, i.e. the last time the wrapped object was used by the borrower.protected T
_getObject()
Returns the wrapped object or throws anIllegalStateException
if the wrapper has already been invalidated.protected void
_invalidate()
Invalidates this wrapper, i.e. references to the wrapped object and the object pool are discarded.protected boolean
_isValid()
Returns whether this wrapper is still valid.protected void
_updateLastActiveTime()
Updates thelast active time
to the current system time.
-
-
-
Constructor Detail
-
AbstractObjectWrapper
protected AbstractObjectWrapper(ObjectPool<T,E> objectPool, T pooledObject)
Constructs a newAbstractObjectWrapper
for the given object and pool.- Parameters:
objectPool
- the object to be wrappedpooledObject
- the pool responsible for the given object
-
-
Method Detail
-
_getObject
protected T _getObject() throws E extends Exception
Returns the wrapped object or throws anIllegalStateException
if the wrapper has already been invalidated.This method is intended to be called in subclasses to implement the delegating methods. It will update the
_getLastActiveTime()
last active time} to the current system time and - as already mentioned - it will fail if the wrapper was invalidated.In subclasses, this method will have to be overridden with a simple call to its super implementation in order to provide access to the implementation of
ObjectWrapperLifeCycle.unwrap(Object)
.- Returns:
- the wrapped object
- Throws:
E
- not thrown by this implementation, but may be thrown in sub classes if_ensureIsValid()
is implemented differentlyE extends Exception
-
_ensureIsValid
protected void _ensureIsValid() throws E extends Exception
Simply returns if the wrapper is still valid and throws anIllegalStateException
if it isn't. May be overridden in subclasses to either throw the same exception type with a different message or a domain-specific exception.- Throws:
IllegalStateException
- if the wrapper has been invalidated (may change of overridden)E
- not thrown by this implementation, but may be thrown in sub classesE extends Exception
-
_isValid
protected boolean _isValid()
Returns whether this wrapper is still valid. Invalidated wrappers will prevent all access to the wrapped object (at least by the burrower). Subsequent calls to_getObject()
will raise anIllegalStateException
.Please note that this does in no way indicate whether the wrapped object is still valid!
- Returns:
- whether this wrapper is still valid
-
_invalidate
protected void _invalidate()
Invalidates this wrapper, i.e. references to the wrapped object and the object pool are discarded. After this method returns, calls to_getObject()
will fail!In subclasses, this method will have to be overridden with a simple call to its super implementation in order to provide access to the implementation of
ObjectWrapperLifeCycle.invalidate(Object)
.
-
_checkIn
protected void _checkIn() throws E extends Exception
Checks the wrapped object back into the object pool. The wrapper will be invalidated by the object pool in the process. The user of the object (through the wrapper) does not need to have a reference to the object pool in order to return it.- Throws:
E
- passed through exception fromObjectPool.checkIn(Object)
E extends Exception
-
_getLastActiveTime
public long _getLastActiveTime()
Returns the last active time, i.e. the last time the wrapped object was used by the borrower. This time is automatically updated every time_getObject()
is called.This method may be overridden to fetch this information directly from the wrapped object.
- Returns:
- the last active time
-
_updateLastActiveTime
protected void _updateLastActiveTime()
Updates thelast active time
to the current system time. This method is implicitly called by_getObject()
.
-
-