Skip to content

Commit

Permalink
fix: update client to use updated GRPC protocols. update to use long …
Browse files Browse the repository at this point in the history
…for ttl (#132)
  • Loading branch information
tylerburdsall authored Apr 4, 2022
1 parent 3640175 commit 5e38099
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion messages/src/client_protos
22 changes: 11 additions & 11 deletions momento-sdk/src/main/java/momento/sdk/ScsDataClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ final class ScsDataClient implements Closeable {
Metadata.Key.of("cache", ASCII_STRING_MARSHALLER);

private final Optional<Tracer> tracer;
private int itemDefaultTtlSeconds;
private long itemDefaultTtlSeconds;
private ScsDataGrpcStubsManager scsDataGrpcStubsManager;

ScsDataClient(
String authToken,
String endpoint,
int defaultTtlSeconds,
long defaultTtlSeconds,
Optional<OpenTelemetry> openTelemetry,
Optional<Duration> requestTimeout) {
this.tracer = openTelemetry.map(ot -> ot.getTracer("momento-java-scs-client", "1.0.0"));
Expand All @@ -68,7 +68,7 @@ CacheGetResponse get(String cacheName, byte[] key) {
return sendBlockingGet(cacheName, convert(key));
}

CacheSetResponse set(String cacheName, String key, ByteBuffer value, int ttlSeconds) {
CacheSetResponse set(String cacheName, String key, ByteBuffer value, long ttlSeconds) {
ensureValidCacheSet(key, value, ttlSeconds);
return sendBlockingSet(cacheName, convert(key), convert(value), ttlSeconds);
}
Expand All @@ -77,7 +77,7 @@ CacheSetResponse set(String cacheName, String key, ByteBuffer value) {
return set(cacheName, key, value, itemDefaultTtlSeconds);
}

CacheSetResponse set(String cacheName, String key, String value, int ttlSeconds) {
CacheSetResponse set(String cacheName, String key, String value, long ttlSeconds) {
ensureValidCacheSet(key, value, ttlSeconds);
return sendBlockingSet(cacheName, convert(key), convert(value), ttlSeconds);
}
Expand All @@ -86,7 +86,7 @@ CacheSetResponse set(String cacheName, String key, String value) {
return set(cacheName, key, value, itemDefaultTtlSeconds);
}

CacheSetResponse set(String cacheName, byte[] key, byte[] value, int ttlSeconds) {
CacheSetResponse set(String cacheName, byte[] key, byte[] value, long ttlSeconds) {
ensureValidCacheSet(key, value, ttlSeconds);
return sendBlockingSet(cacheName, convert(key), convert(value), ttlSeconds);
}
Expand All @@ -106,7 +106,7 @@ CompletableFuture<CacheGetResponse> getAsync(String cacheName, String key) {
}

CompletableFuture<CacheSetResponse> setAsync(
String cacheName, String key, ByteBuffer value, int ttlSeconds) {
String cacheName, String key, ByteBuffer value, long ttlSeconds) {
ensureValidCacheSet(key, value, ttlSeconds);
return sendSet(cacheName, convert(key), convert(value), ttlSeconds);
}
Expand All @@ -116,7 +116,7 @@ CompletableFuture<CacheSetResponse> setAsync(String cacheName, String key, ByteB
}

CompletableFuture<CacheSetResponse> setAsync(
String cacheName, byte[] key, byte[] value, int ttlSeconds) {
String cacheName, byte[] key, byte[] value, long ttlSeconds) {
ensureValidCacheSet(key, value, ttlSeconds);
return sendSet(cacheName, convert(key), convert(value), ttlSeconds);
}
Expand All @@ -126,7 +126,7 @@ CompletableFuture<CacheSetResponse> setAsync(String cacheName, byte[] key, byte[
}

CompletableFuture<CacheSetResponse> setAsync(
String cacheName, String key, String value, int ttlSeconds) {
String cacheName, String key, String value, long ttlSeconds) {
ensureValidCacheSet(key, value, ttlSeconds);
return sendSet(cacheName, convert(key), convert(value), ttlSeconds);
}
Expand Down Expand Up @@ -163,7 +163,7 @@ private CacheGetResponse sendBlockingGet(String cacheName, ByteString key) {
}

private CacheSetResponse sendBlockingSet(
String cacheName, ByteString key, ByteString value, int itemTtlSeconds) {
String cacheName, ByteString key, ByteString value, long itemTtlSeconds) {
try {
return sendSet(cacheName, key, value, itemTtlSeconds).get();
} catch (Throwable t) {
Expand Down Expand Up @@ -226,7 +226,7 @@ public void onFailure(Throwable e) {
}

private CompletableFuture<CacheSetResponse> sendSet(
String cacheName, ByteString key, ByteString value, int ttlSeconds) {
String cacheName, ByteString key, ByteString value, long ttlSeconds) {
checkCacheNameValid(cacheName);
Optional<Span> span = buildSpan("java-sdk-set-request");
Optional<Scope> scope = (span.map(ImplicitContextKeyed::makeCurrent));
Expand Down Expand Up @@ -294,7 +294,7 @@ private _GetRequest buildGetRequest(ByteString key) {
return _GetRequest.newBuilder().setCacheKey(key).build();
}

private _SetRequest buildSetRequest(ByteString key, ByteString value, int ttl) {
private _SetRequest buildSetRequest(ByteString key, ByteString value, long ttl) {
return _SetRequest.newBuilder()
.setCacheKey(key)
.setCacheBody(value)
Expand Down
40 changes: 20 additions & 20 deletions momento-sdk/src/main/java/momento/sdk/SimpleCacheClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class SimpleCacheClient implements Closeable {

SimpleCacheClient(
String authToken,
int itemDefaultTtlSeconds,
long itemDefaultTtlSeconds,
Optional<OpenTelemetry> telemetryOptional,
Optional<Duration> requestTimeout) {
MomentoEndpointsResolver.MomentoEndpoints endpoints =
Expand All @@ -39,7 +39,7 @@ public final class SimpleCacheClient implements Closeable {
requestTimeout);
}

public static SimpleCacheClientBuilder builder(String authToken, int itemDefaultTtlSeconds) {
public static SimpleCacheClientBuilder builder(String authToken, long itemDefaultTtlSeconds) {
return new SimpleCacheClientBuilder(authToken, itemDefaultTtlSeconds);
}

Expand Down Expand Up @@ -131,14 +131,14 @@ public CacheGetResponse get(String cacheName, byte[] key) {
* @param key The key under which the value is to be added.
* @param value The value to be stored.
* @param ttlSeconds Time to Live for the item in Cache. This ttl takes precedence over the TTL
* used when building a cache client {@link SimpleCacheClient#builder(String, int)}
* used when building a cache client {@link SimpleCacheClient#builder(String, long)}
* @return Result of the set operation.
* @throws momento.sdk.exceptions.PermissionDeniedException
* @throws ClientSdkException if key, value is null or if ttlSeconds is less than or equal to zero
* @throws NotFoundException
* @throws momento.sdk.exceptions.InternalServerException
*/
public CacheSetResponse set(String cacheName, String key, ByteBuffer value, int ttlSeconds) {
public CacheSetResponse set(String cacheName, String key, ByteBuffer value, long ttlSeconds) {
return scsDataClient.set(cacheName, key, value, ttlSeconds);
}

Expand All @@ -147,7 +147,7 @@ public CacheSetResponse set(String cacheName, String key, ByteBuffer value, int
* the new value.
*
* <p>The Time to Live (TTL) seconds defaults to the parameter used when building this Cache
* client - {@link SimpleCacheClient#builder(String, int)}
* client - {@link SimpleCacheClient#builder(String, long)}
*
* @param cacheName Name of the cache to store the item in
* @param key The key under which the value is to be added.
Expand All @@ -170,14 +170,14 @@ public CacheSetResponse set(String cacheName, String key, ByteBuffer value) {
* @param key The key under which the value is to be added.
* @param value The value to be stored.
* @param ttlSeconds Time to Live for the item in Cache. This ttl takes precedence over the TTL
* used when building a cache client {@link SimpleCacheClient#builder(String, int)}
* used when building a cache client {@link SimpleCacheClient#builder(String, long)}
* @return Result of the set operation.
* @throws momento.sdk.exceptions.PermissionDeniedException
* @throws ClientSdkException if key or value is null or ttlSeconds is less than or equal to zero
* @throws NotFoundException
* @throws momento.sdk.exceptions.InternalServerException
*/
public CacheSetResponse set(String cacheName, String key, String value, int ttlSeconds) {
public CacheSetResponse set(String cacheName, String key, String value, long ttlSeconds) {
return scsDataClient.set(cacheName, key, value, ttlSeconds);
}

Expand All @@ -186,7 +186,7 @@ public CacheSetResponse set(String cacheName, String key, String value, int ttlS
* the new value.
*
* <p>The Time to Live (TTL) seconds defaults to the parameter used when building this Cache
* client - {@link SimpleCacheClient#builder(String, int)}
* client - {@link SimpleCacheClient#builder(String, long)}
*
* @param cacheName Name of the cache to store the item in
* @param key The key under which the value is to be added.
Expand All @@ -210,14 +210,14 @@ public CacheSetResponse set(String cacheName, String key, String value) {
* @param key The key under which the value is to be added.
* @param value The value to be stored.
* @param ttlSeconds Time to Live for the item in Cache. This ttl takes precedence over the TTL
* used when building a cache client {@link SimpleCacheClient#builder(String, int)}
* used when building a cache client {@link SimpleCacheClient#builder(String, long)}
* @return Result of the set operation.
* @throws momento.sdk.exceptions.PermissionDeniedException
* @throws ClientSdkException if key or value is null or ttlSeconds is less than or equal to zero
* @throws NotFoundException
* @throws momento.sdk.exceptions.InternalServerException
*/
public CacheSetResponse set(String cacheName, byte[] key, byte[] value, int ttlSeconds) {
public CacheSetResponse set(String cacheName, byte[] key, byte[] value, long ttlSeconds) {
return scsDataClient.set(cacheName, key, value, ttlSeconds);
}

Expand All @@ -226,7 +226,7 @@ public CacheSetResponse set(String cacheName, byte[] key, byte[] value, int ttlS
* the new value.
*
* <p>The Time to Live (TTL) seconds defaults to the parameter used when building this Cache
* client - {@link SimpleCacheClient#builder(String, int)}
* client - {@link SimpleCacheClient#builder(String, long)}
*
* @param cacheName Name of the cache to store the item in
* @param key The key under which the value is to be added.
Expand Down Expand Up @@ -282,15 +282,15 @@ public CompletableFuture<CacheGetResponse> getAsync(String cacheName, String key
* @param key The key under which the value is to be added.
* @param value The value to be stored.
* @param ttlSeconds Time to Live for the item in Cache. This ttl takes precedence over the TTL
* used when building a cache client {@link SimpleCacheClient#builder(String, int)}
* used when building a cache client {@link SimpleCacheClient#builder(String, long)}
* @return Future containing the result of the set operation.
* @throws momento.sdk.exceptions.PermissionDeniedException
* @throws ClientSdkException if key or value is null or ttlSeconds is less than or equal to zero
* @throws NotFoundException
* @throws momento.sdk.exceptions.InternalServerException
*/
public CompletableFuture<CacheSetResponse> setAsync(
String cacheName, String key, ByteBuffer value, int ttlSeconds) {
String cacheName, String key, ByteBuffer value, long ttlSeconds) {
return scsDataClient.setAsync(cacheName, key, value, ttlSeconds);
}

Expand All @@ -299,7 +299,7 @@ public CompletableFuture<CacheSetResponse> setAsync(
* the new value.
*
* <p>The Time to Live (TTL) seconds defaults to the parameter used when building this Cache
* client - {@link SimpleCacheClient#builder(String, int)}
* client - {@link SimpleCacheClient#builder(String, long)}
*
* @param cacheName Name of the cache to store the item in
* @param key The key under which the value is to be added.
Expand All @@ -324,15 +324,15 @@ public CompletableFuture<CacheSetResponse> setAsync(
* @param key The key under which the value is to be added.
* @param value The value to be stored.
* @param ttlSeconds Time to Live for the item in Cache. This ttl takes precedence over the TTL
* used when building a cache client {@link SimpleCacheClient#builder(String, int)}
* used when building a cache client {@link SimpleCacheClient#builder(String, long)}
* @return Future containing the result of the set operation.
* @throws momento.sdk.exceptions.PermissionDeniedException
* @throws ClientSdkException if key or value is null or ttlSeconds is less than or equal to zero
* @throws NotFoundException
* @throws momento.sdk.exceptions.InternalServerException
*/
public CompletableFuture<CacheSetResponse> setAsync(
String cacheName, byte[] key, byte[] value, int ttlSeconds) {
String cacheName, byte[] key, byte[] value, long ttlSeconds) {
return scsDataClient.setAsync(cacheName, key, value, ttlSeconds);
}

Expand All @@ -341,7 +341,7 @@ public CompletableFuture<CacheSetResponse> setAsync(
* the new value.
*
* <p>The Time to Live (TTL) seconds defaults to the parameter used when building this Cache
* client - {@link SimpleCacheClient#builder(String, int)}
* client - {@link SimpleCacheClient#builder(String, long)}
*
* @param cacheName Name of the cache to store the item in
* @param key The key under which the value is to be added.
Expand All @@ -365,15 +365,15 @@ public CompletableFuture<CacheSetResponse> setAsync(String cacheName, byte[] key
* @param key The key under which the value is to be added.
* @param value The value to be stored.
* @param ttlSeconds Time to Live for the item in Cache. This ttl takes precedence over the TTL
* used when building a cache client {@link SimpleCacheClient#builder(String, int)}
* used when building a cache client {@link SimpleCacheClient#builder(String, long)}
* @return Future containing the result of the set operation.
* @throws momento.sdk.exceptions.PermissionDeniedException
* @throws ClientSdkException if key or value is null or ttlSeconds is less than or equal to zero
* @throws NotFoundException
* @throws momento.sdk.exceptions.InternalServerException
*/
public CompletableFuture<CacheSetResponse> setAsync(
String cacheName, String key, String value, int ttlSeconds) {
String cacheName, String key, String value, long ttlSeconds) {
return scsDataClient.setAsync(cacheName, key, value, ttlSeconds);
}

Expand All @@ -382,7 +382,7 @@ public CompletableFuture<CacheSetResponse> setAsync(
* the new value.
*
* <p>The Time to Live (TTL) seconds defaults to the parameter used when building this Cache
* client - {@link SimpleCacheClient#builder(String, int)}
* client - {@link SimpleCacheClient#builder(String, long)}
*
* @param cacheName Name of the cache to store the item in
* @param key The key under which the value is to be added.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
public final class SimpleCacheClientBuilder {

private final String authToken;
private final int itemDefaultTtlSeconds;
private final long itemDefaultTtlSeconds;
private Optional<Duration> requestTimeout = Optional.empty();

SimpleCacheClientBuilder(String authToken, int itemTtlDefaultSeconds) {
SimpleCacheClientBuilder(String authToken, long itemTtlDefaultSeconds) {
this.authToken = authToken;
ValidationUtils.ensureValidTtl(itemTtlDefaultSeconds);
this.itemDefaultTtlSeconds = itemTtlDefaultSeconds;
Expand Down
4 changes: 2 additions & 2 deletions momento-sdk/src/main/java/momento/sdk/ValidationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static void checkCacheNameValid(String cacheName) {
}
}

static void ensureValidCacheSet(Object key, Object value, int ttlSeconds) {
static void ensureValidCacheSet(Object key, Object value, long ttlSeconds) {
ensureValidKey(key);
if (value == null) {
throw new InvalidArgumentException(A_NON_NULL_VALUE_IS_REQUIRED);
Expand All @@ -33,7 +33,7 @@ static void ensureValidKey(Object key) {
}
}

static void ensureValidTtl(int ttlSeconds) {
static void ensureValidTtl(long ttlSeconds) {
if (ttlSeconds < 0) {
throw new InvalidArgumentException(CACHE_ITEM_TTL_CANNOT_BE_NEGATIVE);
}
Expand Down

0 comments on commit 5e38099

Please sign in to comment.