Class AbstractResource

java.lang.Object
com.yahoo.jdisc.AbstractResource
All Implemented Interfaces:
SharedResource
Direct Known Subclasses:
AbstractRequestHandler, AbstractServerProvider, ActiveContainer, Request, ResourcePool

public abstract class AbstractResource extends Object implements SharedResource
This class provides a thread-safe implementation of the SharedResource interface, and should be used for all subclasses of RequestHandler, ClientProvider and ServerProvider. Once the reference count of this resource reaches zero, the destroy() method is called.
Author:
Simon Thoresen Hult
  • Constructor Details

    • AbstractResource

      protected AbstractResource()
  • Method Details

    • refer

      public final ResourceReference refer()
      Description copied from interface: SharedResource

      Creates a reference to this resource. You call this method to prevent an object from being destroyed until you have finished using it.

      You MUST keep the returned ResourceReference object and release the reference by calling ResourceReference.close() on it. A reference created by this method can NOT be released by calling SharedResource.release().

      Specified by:
      refer in interface SharedResource
      See Also:
    • refer

      public final ResourceReference refer(Object context)
      Description copied from interface: SharedResource

      Creates a reference to this resource. You call this method to prevent an object from being destroyed until you have finished using it. You can attach a context that will live as long as the reference.

      Specified by:
      refer in interface SharedResource
      Parameters:
      context - A context to be associated with the reference. It should give some clue as to who referenced it.

      You MUST keep the returned ResourceReference object and release the reference by calling ResourceReference.close() on it. A reference created by this method can NOT be released by calling SharedResource.release().

      See Also:
    • release

      public final void release()
      Description copied from interface: SharedResource

      Releases the "main" reference to this resource (the implicit reference due to creation of the object).

      References obtained by calling SharedResource.refer() must be released by calling ResourceReference.close() on the ResourceReference returned from SharedResource.refer(), NOT by calling this method. You call this method once you are done using an object that you have previously caused instantiation of.

      Specified by:
      release in interface SharedResource
      See Also:
    • retainCount

      public final int retainCount()

      Returns the reference count of this resource. This typically has no value for other than single-threaded unit- tests, as it is merely a snapshot of the counter.

      Returns:
      The current value of the reference counter.
    • destroy

      protected void destroy()

      This method signals that this AbstractResource can dispose of any internal resources, and commence with shut down of any internal threads. This will be called once the reference count of this resource reaches zero.

    • currentState

      public String currentState()
      Returns a string describing the current state of references in human-friendly terms. May be used for debugging.