Class References

    • Field Detail

      • NOOP_REFERENCE

        public static final ResourceReference NOOP_REFERENCE
        A ResourceReference that does nothing. Useful for e.g. testing of resource types when reference counting is not the focus.
    • Method Detail

      • fromResource

        public static ResourceReference fromResource​(SharedResource resource)

        Returns a ResourceReference that invokes SharedResource.release() on close. Useful for treating the "main" reference of a SharedResource just as any other reference obtained by calling SharedResource.refer(). Example:

             final Request request = new Request(...);
             try (final ResourceReference ref = References.fromResource(request)) {
                 ....
             }
             // The request will be released on exit from the try block.
         
        Parameters:
        resource - The resource to create a ResourceReference for.
        Returns:
        a ResourceReference whose close() method will call release() on the given resource.