-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
421 additions
and
168 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
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
105 changes: 105 additions & 0 deletions
105
src/main/java/io/nats/client/api/KeyValuePurgeOptions.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,105 @@ | ||
// Copyright 2022 The NATS Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package io.nats.client.api; | ||
|
||
import java.time.Duration; | ||
|
||
public class KeyValuePurgeOptions { | ||
|
||
/** | ||
* The default time in millis that is used for as the threshold to keep markers. | ||
*/ | ||
public static long DEFAULT_THRESHOLD_MILLIS = Duration.ofMinutes(30).toMillis(); | ||
|
||
private final long deleteMarkersThresholdMillis; | ||
|
||
private KeyValuePurgeOptions(Builder b) { | ||
this.deleteMarkersThresholdMillis = b.deleteMarkersThresholdMillis; | ||
} | ||
|
||
/** | ||
* The value of the delete marker threshold, in milliseconds. | ||
* @return the threshold | ||
*/ | ||
public long getDeleteMarkersThresholdMillis() { | ||
return deleteMarkersThresholdMillis; | ||
} | ||
|
||
/** | ||
* Creates a builder for the Key Value Purge Options. | ||
* @return a key value purge options builder | ||
*/ | ||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
/** | ||
* KeyValuePurgeOptions is created using a Builder. The builder supports chaining and will | ||
* create a default set of options if no methods are calls. | ||
* | ||
* <p>{@code new KeyValuePurgeOptions.Builder().build()} will create a new KeyValuePurgeOptions. | ||
* | ||
*/ | ||
public static class Builder { | ||
private long deleteMarkersThresholdMillis = DEFAULT_THRESHOLD_MILLIS; | ||
|
||
/** | ||
* Set the delete marker threshold. | ||
* Null or duration of 0 will assume the default threshold {@link #DEFAULT_THRESHOLD_MILLIS} | ||
* Duration less than zero will assume no threshold and will not keep any markers. | ||
* @param deleteMarkersThreshold the threshold duration or null | ||
* @return The builder | ||
*/ | ||
public Builder deleteMarkersThreshold(Duration deleteMarkersThreshold) { | ||
this.deleteMarkersThresholdMillis = deleteMarkersThreshold == null | ||
? DEFAULT_THRESHOLD_MILLIS : deleteMarkersThreshold.toMillis(); | ||
return this; | ||
} | ||
|
||
/** | ||
* Set the delete marker threshold. | ||
* 0 will assume the default threshold {@link #DEFAULT_THRESHOLD_MILLIS} | ||
* Less than zero will assume no threshold and will not keep any markers. | ||
* @param deleteMarkersThresholdMillis the threshold millis | ||
* @return The builder | ||
*/ | ||
public Builder deleteMarkersThreshold(long deleteMarkersThresholdMillis) { | ||
this.deleteMarkersThresholdMillis = deleteMarkersThresholdMillis; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set the delete marker threshold to -1 so as to not keep any markers | ||
* @return The builder | ||
*/ | ||
public Builder deleteMarkersNoThreshold() { | ||
this.deleteMarkersThresholdMillis = -1; | ||
return this; | ||
} | ||
|
||
/** | ||
* Build the Key Value Purge Options | ||
* @return the options | ||
*/ | ||
public KeyValuePurgeOptions build() { | ||
if (deleteMarkersThresholdMillis < 0) { | ||
deleteMarkersThresholdMillis = -1; | ||
} | ||
else if (deleteMarkersThresholdMillis == 0) { | ||
deleteMarkersThresholdMillis = DEFAULT_THRESHOLD_MILLIS; | ||
} | ||
return new KeyValuePurgeOptions(this); | ||
} | ||
} | ||
} |
Oops, something went wrong.