Class AbstractObjectWrapper<T,​E extends Exception>


  • 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 Detail

      • AbstractObjectWrapper

        protected AbstractObjectWrapper​(ObjectPool<T,​E> objectPool,
                                        T pooledObject)
        Constructs a new AbstractObjectWrapper for the given object and pool.
        Parameters:
        objectPool - the object to be wrapped
        pooledObject - the pool responsible for the given object
    • Method Detail

      • _getObject

        protected T _getObject()
                        throws E extends Exception
        Returns the wrapped object or throws an IllegalStateException 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 differently
        E extends Exception
      • _ensureIsValid

        protected void _ensureIsValid()
                               throws E extends Exception
        Simply returns if the wrapper is still valid and throws an IllegalStateException 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 classes
        E 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 an IllegalStateException.

        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 from ObjectPool.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 the last active time to the current system time. This method is implicitly called by _getObject().