Interface ResourceReference

  • All Superinterfaces:
    java.lang.AutoCloseable

    public interface ResourceReference
    extends java.lang.AutoCloseable

    Represents a live reference to a SharedResource. Only provides the ability to release the reference.

    Implements AutoCloseable so that it can be used in try-with-resources statements. Example

         void doSomethingWithRequest(final Request request) {
             try (final ResourceReference ref = request.refer()) {
                 // Do something with request
             }
             // ref.close() will be called automatically on exit from the try block, releasing the reference on 'request'.
         }
     
    Author:
    bakksjo
    • Method Detail

      • close

        void close()

        Decrements the reference count of the referenced resource. You call this method once you are done using an object that you have previously referred.

        Note that this method is NOT idempotent; you must call it exactly once.

        Specified by:
        close in interface java.lang.AutoCloseable
        See Also:
        SharedResource.refer()