Interface ResourceContext

    • Method Detail

      • close

        void close​()
        Close the ResourceContext, unbinding from all threads and removing all meters. The value and allocated values of meters is retained and included in the TotalsResourceContext. After close the ResourceContext behaves as if it has no ResourceMeters, ResourceMeters cannot be added, and it cannot be bound to a thread. Closing a closed ResourceContext has no effect.
        Specified by:
        close in interface AutoCloseable
      • getName

        String getName​()
        Return the name of the ResourceContext.
        Returns:
        the name of the ResourceContext
      • bindThreadContext

        default ResourceContext bindThreadContext​()
        Binds the ResourceContext to the current thread.
        Implementation Note:
        the default behavior is to throw UnsupportedOperationException
        Returns:
        the ResourceContext the thread was bound to; the unassigned context is returned if the thread is otherwise not bound
        Throws:
        UnsupportedOperationException - if the ResourceContext does not support binding
      • unbindThreadContext

        static ResourceContext unbindThreadContext​()
        Unbind the current thread from the ResourceContext. The thread is implicitly bound to the unassigned context.
        Implementation Note:
        the default behavior is to throw UnsupportedOperationException
        Returns:
        the ResourceContext the thread was bound to; the unassigned context is returned if the thread is otherwise not bound
        Throws:
        UnsupportedOperationException - if the ResourceContext does not support unbinding
      • boundThreads

        default Stream<Thread> boundThreads​()
        Returns a Stream of threads bound to the ResourceContext. The Threads bound to a ResourceContext is fluid and may change at any time. If thread pooling is in use a Thread may be bound to different ResourceContexts at different times and may change dynamically.
        Implementation Note:
        the default behavior is to throw UnsupportedOperationException
        Returns:
        a Stream of the threads bound to the ResourceContext
        Throws:
        UnsupportedOperationException - if the ResourceContext does not maintain a set of Threads
      • getResourceRequest

        ResourceRequest getResourceRequest​(ResourceType type)
        Returns the ResourceRequest in the ResourceContext that handles requests to allocate or release for the ResourceType.
        Parameters:
        type - the ResourceType of the resource making the request
        Returns:
        a ResourceRequest; null if the ResourceContext is not counting metrics for the resource or the meter does not implement ResourceRequest
      • addResourceMeter

        default void addResourceMeter​(ResourceMeter meter)
        Add a ResourceMeter. ResourceMeters must have unique ResourceTypes within a ResourceContext.
        Implementation Note:
        the default behavior is to throw UnsupportedOperationException
        Parameters:
        meter - a resource meter
        Throws:
        IllegalArgumentException - if the ResourceContext contains a ResourceMeter with the same ResourceType
        UnsupportedOperationException - if the ResourceContext does not support adding or removing ResourceMeters or if the ResourceType is not supported
      • removeResourceMeter

        default boolean removeResourceMeter​(ResourceMeter meter)
        Remove the ResourceMeter from the ResourceContext. Note that this does not actually deactivate the meter, but merely excises it from the scope of the current context.
        Parameters:
        meter - the ResourceMeter to remove
        Returns:
        true if an element was removed as a result of this call
        Throws:
        UnsupportedOperationException - if the ResourceContext does not support adding or removing Meters
      • getMeter

        ResourceMeter getMeter​(ResourceType type)
        Return the ResourceMeter for the ResourceType.
        Parameters:
        type - a ResourceType
        Returns:
        the ResourceMeter for the type or null if none
      • meters

        Stream<ResourceMeter> meters​()
        Returns a Stream of ResourceMeters in the ResourceContext.
        Returns:
        stream of the ResourceMeters
      • requestAccurateUpdate

        default void requestAccurateUpdate​(ResourceAccuracy accuracy)
        Request an update of the metrics for the ResourceContext. If the accuracy of the information provided for this ResourceContext is less than the requested accuracy, the implementation starts a computation that will delivery the requested accuracy. Computing more accurate measurements may take some time. For example, it may be necessary to scan the heap to determine more accurately how much of the heap is retained to deliver an updated HEAP_RETAINED amount. When the computation is completed, the updated values are reported through the ResourceMeters in the ResourceContext. Only values that change are reported and use the normal ResourceMeter granularity and notification mechanisms. The resourceId.getAccuracy method returns the accuracy.
        Parameters:
        accuracy - the requested accuracy