-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update CacheMaintainer to be a generic ScheduledExecutor class that c…
…an accept a Runnable and an interval Signed-off-by: owenhalpert <[email protected]>
- Loading branch information
1 parent
8392b1d
commit 601a24a
Showing
5 changed files
with
50 additions
and
54 deletions.
There are no files selected for viewing
42 changes: 0 additions & 42 deletions
42
src/main/java/org/opensearch/knn/index/CacheMaintainer.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/main/java/org/opensearch/knn/index/ScheduledExecutor.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,40 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.index; | ||
|
||
import java.io.Closeable; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Executes a task periodically | ||
*/ | ||
public class ScheduledExecutor implements Closeable { | ||
private final ScheduledExecutorService executor; | ||
final Runnable task; | ||
|
||
/** | ||
* @param task task to be completed | ||
* @param scheduleMillis time in milliseconds to wait before executing the task again | ||
*/ | ||
public ScheduledExecutor(Runnable task, long scheduleMillis) { | ||
this.task = task; | ||
this.executor = Executors.newSingleThreadScheduledExecutor(); | ||
executor.scheduleAtFixedRate( | ||
task, | ||
0, | ||
scheduleMillis, | ||
TimeUnit.MILLISECONDS | ||
); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
executor.shutdown(); | ||
} | ||
} |
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