forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a time supplier interface instead of passing ThreadPool (elastic#…
…116333) An attempt to use a basic interface for time supplier based on elastic#115511 (comment). (TLDR: sometimes we pass around a ThreadPool instance just to be able to get time. It might be more reasonable to separate those use cases)
- Loading branch information
Showing
8 changed files
with
148 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
server/src/main/java/org/elasticsearch/common/time/TimeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.common.time; | ||
|
||
/** | ||
* An interface encapsulating the different methods for getting relative and absolute time. The main | ||
* implementation of this is {@link org.elasticsearch.threadpool.ThreadPool}. To make it clear that a | ||
* {@code ThreadPool} is being passed around only to get time, it is preferred to use this interface. | ||
*/ | ||
public interface TimeProvider { | ||
|
||
/** | ||
* Returns a value of milliseconds that may be used for relative time calculations. | ||
* | ||
* This method should only be used for calculating time deltas. For an epoch based | ||
* timestamp, see {@link #absoluteTimeInMillis()}. | ||
*/ | ||
long relativeTimeInMillis(); | ||
|
||
/** | ||
* Returns a value of nanoseconds that may be used for relative time calculations. | ||
* | ||
* This method should only be used for calculating time deltas. For an epoch based | ||
* timestamp, see {@link #absoluteTimeInMillis()}. | ||
*/ | ||
long relativeTimeInNanos(); | ||
|
||
/** | ||
* Returns a value of milliseconds that may be used for relative time calculations. Similar to {@link #relativeTimeInMillis()} except | ||
* that this method is more expensive: the return value is computed directly from {@link System#nanoTime} and is not cached. You should | ||
* use {@link #relativeTimeInMillis()} unless the extra accuracy offered by this method is worth the costs. | ||
* | ||
* When computing a time interval by comparing relative times in milliseconds, you should make sure that both endpoints use cached | ||
* values returned from {@link #relativeTimeInMillis()} or that they both use raw values returned from this method. It doesn't really | ||
* make sense to compare a raw value to a cached value, even if in practice the result of such a comparison will be approximately | ||
* sensible. | ||
*/ | ||
long rawRelativeTimeInMillis(); | ||
|
||
/** | ||
* Returns the value of milliseconds since UNIX epoch. | ||
* | ||
* This method should only be used for exact date/time formatting. For calculating | ||
* time deltas that should not suffer from negative deltas, which are possible with | ||
* this method, see {@link #relativeTimeInMillis()}. | ||
*/ | ||
long absoluteTimeInMillis(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.