public class RankingBuilder extends Object
Ranking.
Basic examples of usage:
Ranking ranking = Ranking.builder(3).resetAllPositionsOnSnapshot().build();
MetricSet metricSet = new RankingMetricSet("my-top", top, TimeUnit.MILLISECONDS, 5);
registry.registerAll(metricSet);
Ranking| Modifier and Type | Field and Description |
|---|---|
static Duration |
DEFAULT_LATENCY_THRESHOLD |
static int |
DEFAULT_MAX_LENGTH_OF_QUERY_DESCRIPTION |
static Duration |
DEFAULT_SNAPSHOT_CACHING_DURATION |
static int |
MAX_CHUNKS |
static int |
MAX_POSITION_COUNT |
static long |
MIN_CHUNK_RESETTING_INTERVAL_MILLIS |
static int |
MIN_LENGTH_OF_QUERY_DESCRIPTION |
| Modifier and Type | Method and Description |
|---|---|
<T> Ranking<T> |
build()
Constructs new
Ranking instance |
RankingBuilder |
neverResetPositions()
Top configured with this strategy will store all values since the ranking was created.
|
static RankingBuilder |
newBuilder(int size)
Creates new builder instance.
|
RankingBuilder |
resetAllPositionsOnSnapshot()
Ranking configured with this strategy will be cleared each time when
Ranking.getPositionsInDescendingOrder() invoked. |
RankingBuilder |
resetAllPositionsPeriodically(Duration intervalBetweenResetting)
Ranking configured with this strategy will be cleared at all after each
intervalBetweenResetting elapsed. |
RankingBuilder |
resetPositionsPeriodicallyByChunks(Duration rollingTimeWindow,
int numberChunks)
Ranking configured with this strategy will be divided to numberChunks parts,
and one chunk will be cleared after each rollingTimeWindow / numberChunks elapsed.
|
RankingBuilder |
withBackgroundExecutor(Executor backgroundExecutor)
Configures the executor which will be used if any of
resetAllPositionsPeriodically(Duration) (Duration)} or resetPositionsPeriodicallyByChunks(Duration, int) (Duration, int)} (Duration)}. |
RankingBuilder |
withLatencyThreshold(Duration latencyThreshold)
Configures the latency threshold.
|
RankingBuilder |
withMaxLengthOfQueryDescription(int maxLengthOfQueryDescription)
Specifies the max length of description position int the ranking.
|
RankingBuilder |
withPositionCount(int size)
Configures the maximum count of positions for ranking which will be constructed by this builder.
|
RankingBuilder |
withSnapshotCachingDuration(Duration snapshotCachingDuration)
Configures the duration for caching the results of invocation of
Ranking.getPositionsInDescendingOrder(). |
RankingBuilder |
withTicker(Ticker ticker)
Replaces default ticker.
|
public static final int MAX_POSITION_COUNT
public static final long MIN_CHUNK_RESETTING_INTERVAL_MILLIS
public static final int MAX_CHUNKS
public static final int MIN_LENGTH_OF_QUERY_DESCRIPTION
public static final int DEFAULT_MAX_LENGTH_OF_QUERY_DESCRIPTION
public static final Duration DEFAULT_LATENCY_THRESHOLD
public static final Duration DEFAULT_SNAPSHOT_CACHING_DURATION
public static RankingBuilder newBuilder(int size)
size - the count of positions for ranking which will be constructed by this builderpublic RankingBuilder withPositionCount(int size)
size - the maximum count of positionspublic RankingBuilder withLatencyThreshold(Duration latencyThreshold)
DEFAULT_LATENCY_THRESHOLD, means that all queries can be recorded independent of its latency.
Specify this parameter when you want not to track queries which fast,
in other words when you want see nothing when all going well.latencyThreshold - public RankingBuilder withSnapshotCachingDuration(Duration snapshotCachingDuration)
Ranking.getPositionsInDescendingOrder().
Currently the caching is only one way to solve atomicity read problem.
The default value is one second DEFAULT_SNAPSHOT_CACHING_DURATION.
You can specify zero duration to discard caching at all, but theoretically,
you should not disable cache until Dropwizard-Metrics reporting pipeline will be rewritten in scope of v-4-0snapshotCachingDuration - public RankingBuilder withMaxLengthOfQueryDescription(int maxLengthOfQueryDescription)
maxLengthOfQueryDescription limit will be truncated
The default value is 1000 symbol DEFAULT_MAX_LENGTH_OF_QUERY_DESCRIPTION.
maxLengthOfQueryDescription - the max length of description position int the top.public RankingBuilder withTicker(Ticker ticker)
ticker - the abstraction over timepublic RankingBuilder withBackgroundExecutor(Executor backgroundExecutor)
resetAllPositionsPeriodically(Duration) (Duration)} or resetPositionsPeriodicallyByChunks(Duration, int) (Duration, int)} (Duration)}.
Normally you should not use this method because of default executor provided by ResilientExecutionUtil.getBackgroundExecutor() is quietly enough for mostly use cases.
You can use this method for example inside JEE environments with enabled SecurityManager,
in case of ResilientExecutionUtil.setThreadFactory(ThreadFactory) is not enough to meat security rules.
public RankingBuilder neverResetPositions()
This is default strategy for RankingBuilder.
This strategy is useless for long running applications, because very slow queries happen in the past
will not provide chances to fresh queries to take place in the ranking.
So, it is strongly recommended to switch eviction strategy to one of:
resetPositionsPeriodicallyByChunks(Duration, int),
resetAllPositionsPeriodically(Duration),
resetAllPositionsOnSnapshot()public RankingBuilder resetAllPositionsOnSnapshot()
Ranking.getPositionsInDescendingOrder() invoked.resetPositionsPeriodicallyByChunks(Duration, int),
resetAllPositionsPeriodically(Duration)public RankingBuilder resetAllPositionsPeriodically(Duration intervalBetweenResetting)
intervalBetweenResetting elapsed.
If You use this strategy inside JEE environment,
then it would be better to call ResilientExecutionUtil.getInstance().shutdownBackgroundExecutor()
once in application shutdown listener,
in order to avoid leaking reference to classloader through the thread which this library creates for resetting of ranking in background.
intervalBetweenResetting - specifies how often need to reset the rankingpublic RankingBuilder resetPositionsPeriodicallyByChunks(Duration rollingTimeWindow, int numberChunks)
The value recorded to ranking will take affect at least rollingTimeWindow and at most rollingTimeWindow *(1 + 1/numberChunks) time, for example when you configure rollingTimeWindow=60 seconds and numberChunks=6 then each value recorded to ranking will be stored at 60-70 seconds
If You use this strategy inside JEE environment,
then it would be better to call ResilientExecutionUtil.getInstance().shutdownBackgroundExecutor()
once in application shutdown listener,
in order to avoid leaking reference to classloader through the thread which this library creates for rotation of ranking in background.
rollingTimeWindow - the total rolling time window, any value recorded to ranking will not be evicted from it at least rollingTimeWindownumberChunks - specifies number of chunks by which the ranking will be slittedCopyright © 2020. All rights reserved.