-
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.
improve concurrent fetching efficiency.
- Loading branch information
Showing
4 changed files
with
157 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ hs_err_pid* | |
out/ | ||
benchmark-results/ | ||
gradle.properties | ||
ignore | ||
ignore | ||
configs |
58 changes: 58 additions & 0 deletions
58
core/src/main/java/software/sava/services/core/request_capacity/UriCapacityConfig.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,58 @@ | ||
package software.sava.services.core.request_capacity; | ||
|
||
import systems.comodal.jsoniter.FieldBufferPredicate; | ||
import systems.comodal.jsoniter.JsonIterator; | ||
import systems.comodal.jsoniter.ValueType; | ||
|
||
import java.net.URI; | ||
import java.net.http.HttpResponse; | ||
import java.util.Objects; | ||
|
||
import static systems.comodal.jsoniter.JsonIterator.fieldEquals; | ||
|
||
public record UriCapacityConfig(URI endpoint, CapacityConfig capacityConfig) { | ||
|
||
public static UriCapacityConfig parseConfig(final JsonIterator ji) { | ||
if (ji.whatIsNext() == ValueType.STRING) { | ||
final var endpoint = ji.readString(); | ||
return new UriCapacityConfig(URI.create(endpoint), null); | ||
} else { | ||
final var parser = new UriCapacityConfig.Builder(); | ||
ji.testObject(parser); | ||
return parser.create(); | ||
} | ||
} | ||
|
||
public ErrorTrackedCapacityMonitor<HttpResponse<byte[]>> createMonitor(final String serviceName, | ||
final CapacityConfig defaultConfig) { | ||
return Objects.requireNonNullElse(capacityConfig, defaultConfig).createHttpResponseMonitor(serviceName); | ||
} | ||
|
||
private static final class Builder implements FieldBufferPredicate { | ||
|
||
private URI endpoint; | ||
private CapacityConfig capacityConfig; | ||
|
||
private Builder() { | ||
} | ||
|
||
private UriCapacityConfig create() { | ||
return new UriCapacityConfig(endpoint, capacityConfig); | ||
} | ||
|
||
@Override | ||
public boolean test(final char[] buf, final int offset, final int len, final JsonIterator ji) { | ||
if (fieldEquals("url", buf, offset, len)) { | ||
final var endpoint = ji.readString(); | ||
if (endpoint != null && !endpoint.isBlank()) { | ||
this.endpoint = URI.create(endpoint); | ||
} | ||
} else if (fieldEquals("capacity", buf, offset, len)) { | ||
capacityConfig = CapacityConfig.parse(ji); | ||
} else { | ||
ji.skip(); | ||
} | ||
return true; | ||
} | ||
} | ||
} |
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