public interface ResourceContext extends AutoCloseable
ResourceContextFactory.getThreadContext()
and
bindThreadContext()
methods respectively get and set
the association between the current thread and a ResourceContext.
New threads are implicitly bound to the ResourceContext
of the thread invoking new Thread
.
The Thread's Runnable
should explicitly
bind
to the desired context as required.
Each meter is identified by a ResourceType. Resource meters are created
with the desired behavior and
added
to the
context.
The semantics of a particular meter are specified by each ResourceMeter
subtype.
Resource implementations locate the appropriate meter using
getMeter(ResourceType)
.
The ResourceRequest
is obtained
by getResourceRequest(ResourceType)
.
ResourceContextFactory
,
ResourceMeter
Modifier and Type | Method and Description |
---|---|
default void |
addResourceMeter(ResourceMeter meter)
Add a ResourceMeter.
|
default ResourceContext |
bindThreadContext()
Binds the ResourceContext to the current thread.
|
default Stream<Thread> |
boundThreads()
Returns a Stream of threads bound to the ResourceContext.
|
void |
close()
Close the ResourceContext, unbinding from all threads and removing all meters.
|
ResourceMeter |
getMeter(ResourceType type)
Return the ResourceMeter for the ResourceType.
|
String |
getName()
Return the name of the ResourceContext.
|
ResourceRequest |
getResourceRequest(ResourceType type)
Returns the ResourceRequest in the ResourceContext that handles
requests to allocate or release for the ResourceType.
|
Stream<ResourceMeter> |
meters()
Returns a Stream of ResourceMeters in the ResourceContext.
|
default boolean |
removeResourceMeter(ResourceMeter meter)
Remove the ResourceMeter from the ResourceContext.
|
default void |
requestAccurateUpdate(ResourceAccuracy accuracy)
Request an update of the metrics for the ResourceContext.
|
static ResourceContext |
unbindThreadContext()
Unbind the current thread from the ResourceContext.
|
void close()
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.close
in interface AutoCloseable
String getName()
default ResourceContext bindThreadContext()
unassigned
context is returned if the thread is
otherwise not boundUnsupportedOperationException
- if the ResourceContext does not
support bindingstatic ResourceContext unbindThreadContext()
unassigned context
.unassigned
context is returned if the thread is
otherwise not boundUnsupportedOperationException
- if the ResourceContext does not
support unbindingdefault Stream<Thread> boundThreads()
UnsupportedOperationException
- if the ResourceContext does not maintain a set of ThreadsResourceRequest getResourceRequest(ResourceType type)
type
- the ResourceType of the resource making the requestnull
if the ResourceContext
is not counting metrics for the resource or the meter
does not implement ResourceRequest
default void addResourceMeter(ResourceMeter meter)
meter
- a resource meterIllegalArgumentException
- if the ResourceContext contains a
ResourceMeter with the same
ResourceTypeUnsupportedOperationException
- if the ResourceContext does not
support adding or removing ResourceMeters or
if the ResourceType is not supporteddefault boolean removeResourceMeter(ResourceMeter meter)
meter
- the ResourceMeter to removeUnsupportedOperationException
- if the ResourceContext does not
support adding or removing MetersResourceMeter getMeter(ResourceType type)
type
- a ResourceTypetype
or null
if noneStream<ResourceMeter> meters()
default void requestAccurateUpdate(ResourceAccuracy accuracy)
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.accuracy
- the requested accuracy
Copyright © 2014, 2016, Oracle and/or its affiliates. All rights reserved.