Class AbstractResource
- java.lang.Object
-
- com.yahoo.jdisc.AbstractResource
-
- All Implemented Interfaces:
SharedResource
- Direct Known Subclasses:
AbstractRequestHandler
,AbstractServerProvider
,Request
public abstract class AbstractResource extends java.lang.Object implements SharedResource
This class provides a thread-safe implementation of theSharedResource
interface, and should be used for all subclasses ofRequestHandler
,ClientProvider
andServerProvider
. Once the reference count of this resource reaches zero, thedestroy()
method is called.- Author:
- Simon Thoresen Hult
-
-
Field Summary
-
Fields inherited from interface com.yahoo.jdisc.SharedResource
DEBUG, SYSTEM_PROPERTY_NAME_DEBUG
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractResource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
currentState()
Returns a string describing the current state of references in human-friendly terms.protected void
destroy()
This method signals that this AbstractResource can dispose of any internal resources, and commence with shut down of any internal threads.ResourceReference
refer()
Increments the reference count of this resource.void
release()
Releases the "main" reference to this resource (the implicit reference due to creation of the object).int
retainCount()
Returns the reference count of this resource.
-
-
-
Method Detail
-
refer
public final ResourceReference refer()
Description copied from interface:SharedResource
Increments the reference count of 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 callingResourceReference.close()
on it. A reference created by this method can NOT be released by callingSharedResource.release()
.- Specified by:
refer
in interfaceSharedResource
- See Also:
ResourceReference.close()
-
release
public 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 callingResourceReference.close()
on theResourceReference
returned fromSharedResource.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 interfaceSharedResource
- See Also:
ResourceReference
-
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 java.lang.String currentState()
Returns a string describing the current state of references in human-friendly terms. May be used for debugging.
-
-