Class SharedResources


  • public final class SharedResources
    extends Object
    A map that keeps track of acquired shared resources and handles their allocation disposal.
    • Constructor Detail

      • SharedResources

        public SharedResources()
    • Method Detail

      • getOrAllocateSharedResource

        public <T extends AutoCloseableSharedResources.ResourceAndSize<T> getOrAllocateSharedResource​(String type,
                                                                                                        Object leaseHolder,
                                                                                                        org.apache.flink.util.function.LongFunctionWithException<T,​Exception> initializer,
                                                                                                        long sizeForInitialization)
                                                                                                 throws Exception
        Gets the shared memory resource for the given owner and registers a lease. If the resource does not yet exist, it will be created via the given initializer function.

        The resource must be released when no longer used. That releases the lease. When all leases are released, the resource is disposed.

        Throws:
        Exception
      • release

        public void release​(String type,
                            Object leaseHolder,
                            LongConsumer releaser)
                     throws Exception
        Releases a lease (identified by the lease holder object) for the given type. If no further leases exist, the resource is disposed.

        This method takes an additional hook that is called when the resource is disposed.

        Throws:
        Exception