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 and ServerProvider, and is used by jDISC to appropriately signal resources as they become candidates for deallocation. As a ContainerBuilder is activated, all its components are retained by that Container. Once a DeactivatedContainer terminates, all of that Container's components are released. 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
  • Field Details

  • Method Details

    • 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 calling ResourceReference.close() on it. A reference created by this method can NOT be released by calling release().

      See Also:
    • refer

      default ResourceReference refer(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 calling ResourceReference.close() on it. A reference created by this method can NOT be released by calling release().

      See Also:
    • 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 calling ResourceReference.close() on the ResourceReference returned from refer(), 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: