Class AbstractObjectWrapper<T,E extends Exception>
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractObjectWrapper(ObjectPool<T, E> objectPool, T pooledObject) Constructs a newAbstractObjectWrapperfor the given object and pool. -
Method Summary
Modifier and TypeMethodDescriptionprotected void_checkIn()Checks the wrapped object back into the object pool.protected voidSimply returns if the wrapper is still valid and throws anIllegalStateExceptionif it isn't.longReturns the last active time, i.e.protected TReturns the wrapped object or throws anIllegalStateExceptionif the wrapper has already been invalidated.protected voidInvalidates this wrapper, i.e.protected boolean_isValid()Returns whether this wrapper is still valid.protected voidUpdates thelast active timeto the current system time.
-
Constructor Details
-
AbstractObjectWrapper
Constructs a newAbstractObjectWrapperfor the given object and pool.- Parameters:
objectPool- the object to be wrappedpooledObject- the pool responsible for the given object
-
-
Method Details
-
_getObject
Returns the wrapped object or throws anIllegalStateExceptionif 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 differently
-
_ensureIsValid
Simply returns if the wrapper is still valid and throws anIllegalStateExceptionif 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 classes
-
_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
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)
-
_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 timeto the current system time. This method is implicitly called by_getObject().
-