Interface SharedResource
-
- All Known Subinterfaces:
ClientProvider
,Container
,DelegatedRequestHandler
,RequestHandler
,ServerProvider
- All Known Implementing Classes:
AbstractClientProvider
,AbstractRequestHandler
,AbstractResource
,AbstractServerProvider
,ActiveContainer
,NonWorkingClientProvider
,NonWorkingRequestHandler
,NonWorkingServerProvider
,NoopSharedResource
,Request
,ResourcePool
,ThreadedRequestHandler
public interface SharedResource
This interface defines a reference counted resource. This is the parent interface of
RequestHandler
,ClientProvider
andServerProvider
, and is used by jDISC to appropriately signal resources as they become candidates for deallocation. As aContainerBuilder
isactivated
, all its components areretained
by thatContainer
. Once aDeactivatedContainer
terminates, all of that Container's components arereleased
. This resource tracking allows an Application to implement a significantly simpler scheme for managing its resources than would otherwise be possible.Objects are created with an initial reference count of 1, representing the reference held by the object creator.
You should not really think about the management of resources in terms of reference counting, instead think of it in terms of resource ownership. You retain a resource to prevent it from being destroyed while you are using it, and you release a resource once you are done using it.
- Author:
- Simon Thoresen Hult
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
SharedResource.Debug
-
Field Summary
Fields Modifier and Type Field Description static SharedResource.Debug
DEBUG
static java.lang.String
SYSTEM_PROPERTY_NAME_DEBUG
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default ResourceReference
refer()
Creates a reference to this resource.default ResourceReference
refer(java.lang.Object context)
Creates a reference to this resource.void
release()
Releases the "main" reference to this resource (the implicit reference due to creation of the object).
-
-
-
Field Detail
-
SYSTEM_PROPERTY_NAME_DEBUG
static final java.lang.String SYSTEM_PROPERTY_NAME_DEBUG
- See Also:
- Constant Field Values
-
DEBUG
static final SharedResource.Debug DEBUG
-
-
Method Detail
-
refer
default ResourceReference refer()
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 callingResourceReference.close()
on it. A reference created by this method can NOT be released by callingrelease()
.- See Also:
ResourceReference.close()
-
refer
default ResourceReference refer(java.lang.Object context)
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.
- 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 callingResourceReference.close()
on it. A reference created by this method can NOT be released by callingrelease()
.- See Also:
ResourceReference.close()
-
release
void release()
Releases the "main" reference to this resource (the implicit reference due to creation of the object).
References obtained by calling
refer()
must be released by callingResourceReference.close()
on theResourceReference
returned fromrefer()
, NOT by calling this method. You call this method once you are done using an object that you have previously caused instantiation of.- See Also:
ResourceReference
-
-