Class References

java.lang.Object
com.yahoo.jdisc.References

public class References extends Object
Utility class for working with SharedResources and ResourceReferences.
Author:
bakksjo
  • Field Details

    • 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 Details

    • 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.