-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
1 parent
27c72f8
commit 2cc6b70
Showing
9 changed files
with
123 additions
and
12 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
59 changes: 59 additions & 0 deletions
59
.../src/main/java/io/github/jeremylong/openvulnerability/client/nvd/NvdApiRetryStrategy.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,59 @@ | ||
/* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) 2023 Jeremy Long. All Rights Reserved. | ||
*/ | ||
package io.github.jeremylong.openvulnerability.client.nvd; | ||
|
||
import org.apache.hc.client5.http.impl.DefaultHttpRequestRetryStrategy; | ||
import org.apache.hc.core5.http.HttpResponse; | ||
import org.apache.hc.core5.http.protocol.HttpContext; | ||
import org.apache.hc.core5.util.TimeValue; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Implements a back-off delay retry strategy. | ||
*/ | ||
public class NvdApiRetryStrategy extends DefaultHttpRequestRetryStrategy { | ||
/** | ||
* Maximum number of allowed retries. | ||
*/ | ||
private final int maxRetries; | ||
|
||
/** | ||
* Retry interval between subsequent retries in milliseconds. | ||
*/ | ||
private final long delay; | ||
|
||
public NvdApiRetryStrategy(int maxRetries, long delay) { | ||
super(maxRetries, TimeValue.of(delay, TimeUnit.MILLISECONDS), new ArrayList<Class<? extends IOException>>(), | ||
Arrays.asList(503)); | ||
this.maxRetries = maxRetries; | ||
this.delay = delay; | ||
} | ||
|
||
@Override | ||
public TimeValue getRetryInterval(final HttpResponse response, final int execCount, final HttpContext context) { | ||
|
||
if (execCount < maxRetries / 2) { | ||
return TimeValue.of(delay * execCount, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
return TimeValue.of(delay * execCount / 2, TimeUnit.MILLISECONDS); | ||
} | ||
} |
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
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