public abstract class ThreadPoolEnabledPropertyProvider extends AbstractPropertyProvider
PropertyProvider
should not be mistaken for a way to perform
expensive operations, as it is still called as part of the incoming REST
Jetty request. It is poor design to have UI threads from the web client
waiting on expensive operations from a PropertyProvider
, even if they
are spread across multiple threads.
Instead, this PropertyProvider
is useful for spreading many small,
quick operations across a threadpool. This is why the known implementations
of this class (such as the JMXPropertyProvider
) use a cache instead
of reaching out to network endpoints on their own.
This is also why the ThreadPoolExecutor
used here has an unbounded
worker queue and essentially a fixed core size to perform its work. When
Callable
s are rejected because of a worker queue exhaustion, they are
never submitted for execution, yet the Future
instance is still
returned. Therefore, if the queue is ever exhausted, incoming REST API
requests must wait the entire CompletionService.poll(long, TimeUnit)
timeout before skipping the result and returning control.Modifier and Type | Class and Description |
---|---|
protected static class |
ThreadPoolEnabledPropertyProvider.Ticket
Ticket used to cancel provider threads.
|
Modifier and Type | Field and Description |
---|---|
static Set<String> |
healthyStates
Host states that make available metrics collection
|
protected String |
hostNamePropertyId |
Constructor and Description |
---|
ThreadPoolEnabledPropertyProvider(Map<String,Map<String,PropertyInfo>> componentMetrics,
String hostNamePropertyId,
MetricHostProvider metricHostProvider,
String clusterNamePropertyId)
Construct a provider.
|
Modifier and Type | Method and Description |
---|---|
protected static String |
getCacheKeyForException(Throwable throwable) |
String |
getHost(Resource resource,
String clusterName,
String componentName)
Returns a hostname for component
|
protected String |
getSpec(String protocol,
String hostName,
String port,
String url)
Get complete URL from parts
|
static void |
init(Configuration configuration) |
protected static boolean |
isRequestedPropertyId(String propertyId,
String requestedPropertyId,
Request request)
Determine whether or not the given property id was requested.
|
protected static String |
logException(Throwable throwable)
Log an error for the given exception.
|
protected abstract Resource |
populateResource(Resource resource,
Request request,
Predicate predicate,
ThreadPoolEnabledPropertyProvider.Ticket ticket)
Populate a resource by obtaining the requested JMX properties.
|
Set<Resource> |
populateResources(Set<Resource> resources,
Request request,
Predicate predicate)
Populate the given set of resource with any properties that this property
provider can provide and return a populated set of resources.
|
protected static void |
rethrowSystemException(Throwable throwable)
Rethrow the given exception as a System exception and log the message.
|
protected void |
setPopulateTimeout(long populateTimeout)
Set the populate timeout value for this provider.
|
checkAuthorizationForMetrics, checkPropertyCategory, getClustersNameFromResources, getClustersResourceId, getComponentMetrics, getPropertyInfoMap, getResourceTypeFromResources, getValue, isSupportedPropertyId, substituteArgument, updateComponentMetricMap, updatePropertyInfo, updatePropertyInfoMap
checkCategory, checkConfigPropertyIds, checkPropertyIds, containsArguments, getCategoryIds, getPropertyIds, getRegexEntry, getRegexGroups, getRequestPropertyIds, isPatternKey, isPropertyCategoryRequested, isPropertyEntryRequested, isPropertyRequested, setResourceProperty
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
checkPropertyIds
public static final Set<String> healthyStates
protected final String hostNamePropertyId
public ThreadPoolEnabledPropertyProvider(Map<String,Map<String,PropertyInfo>> componentMetrics, String hostNamePropertyId, MetricHostProvider metricHostProvider, String clusterNamePropertyId)
componentMetrics
- map of metrics for this provider@Inject public static void init(Configuration configuration)
public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) throws SystemException
PropertyProvider
resources
- the resources to be populatedrequest
- the request object which defines the desired set of propertiespredicate
- the predicate object which filters which resources are returnedSystemException
- thrown if resources cannot be populatedprotected abstract Resource populateResource(Resource resource, Request request, Predicate predicate, ThreadPoolEnabledPropertyProvider.Ticket ticket) throws SystemException
resource
- the resource to be populatedrequest
- the requestpredicate
- the predicateSystemException
protected void setPopulateTimeout(long populateTimeout)
populateTimeout
- the populate timeout valueprotected static boolean isRequestedPropertyId(String propertyId, String requestedPropertyId, Request request)
protected static String logException(Throwable throwable)
throwable
- the caught exceptionprotected static void rethrowSystemException(Throwable throwable) throws SystemException
throwable
- the caught exceptionSystemException
- always around the given exceptionpublic String getHost(Resource resource, String clusterName, String componentName) throws SystemException
SystemException
Copyright © 2022 Apache Software Foundation. All rights reserved.