Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: specialize storage transport strategy and grpc configs #364

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public PreviewStorageClient(
this.dataClient = new StorageDataClient(credentialProvider, configuration);
}

/** Control operations */
// Control operations

public CompletableFuture<CreateStoreResponse> createStore(String storeName) {
return this.controlClient.createStore(storeName);
}
Expand All @@ -39,7 +40,8 @@ public CompletableFuture<ListStoresResponse> listStores() {
return this.controlClient.listStores();
}

/** Data operations */
// Data operations

public CompletableFuture<GetResponse> get(String storeName, String key) {
return this.dataClient.get(storeName, key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import javax.annotation.Nonnull;
import momento.sdk.auth.CredentialProvider;
import momento.sdk.config.StorageConfiguration;
import momento.sdk.config.transport.GrpcConfiguration;
import momento.sdk.config.transport.storage.StorageGrpcConfiguration;
import momento.sdk.internal.GrpcChannelOptions;

/**
Expand Down Expand Up @@ -41,7 +41,7 @@ private static ManagedChannel setupConnection(
NettyChannelBuilder.forAddress(credentialProvider.getControlEndpoint(), 443);

// Override grpc config to disable keepalive for control clients
final GrpcConfiguration controlConfig =
final StorageGrpcConfiguration controlConfig =
configuration.getTransportStrategy().getGrpcConfiguration().withKeepAliveDisabled();

// set additional channel options (message size, keepalive, auth, etc)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package momento.sdk.config;

import momento.sdk.config.transport.TransportStrategy;
import momento.sdk.config.transport.storage.StorageTransportStrategy;

/** The contract for SDK configurables. A configuration must have a transport strategy. */
public class StorageConfiguration {

private final TransportStrategy transportStrategy;
private final StorageTransportStrategy transportStrategy;

/**
* Creates a new configuration object.
*
* @param transportStrategy Responsible for configuring network tunables.
*/
public StorageConfiguration(TransportStrategy transportStrategy) {
public StorageConfiguration(StorageTransportStrategy transportStrategy) {
this.transportStrategy = transportStrategy;
}

Expand All @@ -21,7 +21,7 @@ public StorageConfiguration(TransportStrategy transportStrategy) {
*
* @return The transport strategy
*/
public TransportStrategy getTransportStrategy() {
public StorageTransportStrategy getTransportStrategy() {
return transportStrategy;
}

Expand All @@ -31,7 +31,8 @@ public TransportStrategy getTransportStrategy() {
* @param transportStrategy
* @return a new Configuration with the updated transport strategy
*/
public StorageConfiguration withTransportStrategy(final TransportStrategy transportStrategy) {
public StorageConfiguration withTransportStrategy(
final StorageTransportStrategy transportStrategy) {
return new StorageConfiguration(transportStrategy);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package momento.sdk.config;

import java.time.Duration;
import momento.sdk.config.transport.GrpcConfiguration;
import momento.sdk.config.transport.StaticTransportStrategy;
import momento.sdk.config.transport.TransportStrategy;
import momento.sdk.config.transport.storage.StaticStorageTransportStrategy;
import momento.sdk.config.transport.storage.StorageGrpcConfiguration;
import momento.sdk.config.transport.storage.StorageTransportStrategy;

/** Prebuilt {@link StorageConfiguration}s for different environments. */
public class StorageConfigurations {
Expand All @@ -13,7 +13,7 @@ public class StorageConfigurations {
*/
public static class Laptop extends StorageConfiguration {

private Laptop(TransportStrategy transportStrategy) {
private Laptop(StorageTransportStrategy transportStrategy) {
super(transportStrategy);
}

Expand All @@ -26,9 +26,10 @@ private Laptop(TransportStrategy transportStrategy) {
* @return the latest Laptop configuration
*/
public static StorageConfiguration latest() {
final TransportStrategy transportStrategy =
final StorageTransportStrategy transportStrategy =
// TODO
new StaticTransportStrategy(new GrpcConfiguration(Duration.ofMillis(15000)));
new StaticStorageTransportStrategy(
new StorageGrpcConfiguration(Duration.ofMillis(15000)));
return new Laptop(transportStrategy);
}
}
Expand All @@ -40,7 +41,7 @@ public static StorageConfiguration latest() {
*/
public static class InRegion extends StorageConfiguration {

private InRegion(TransportStrategy transportStrategy) {
private InRegion(StorageTransportStrategy transportStrategy) {
super(transportStrategy);
}

Expand All @@ -53,15 +54,16 @@ private InRegion(TransportStrategy transportStrategy) {
* @return the latest in-region configuration
*/
public static StorageConfiguration latest() {
final TransportStrategy transportStrategy =
final StorageTransportStrategy transportStrategy =
// TODO
new StaticTransportStrategy(new GrpcConfiguration(Duration.ofMillis(15000)));
new StaticStorageTransportStrategy(
new StorageGrpcConfiguration(Duration.ofMillis(15000)));
return new InRegion(transportStrategy);
}
}

public static class Lambda extends StorageConfiguration {
private Lambda(TransportStrategy transportStrategy) {
private Lambda(StorageTransportStrategy transportStrategy) {
super(transportStrategy);
}

Expand All @@ -81,10 +83,11 @@ private Lambda(TransportStrategy transportStrategy) {
* @return the latest Lambda configuration
*/
public static StorageConfiguration latest() {
final GrpcConfiguration grpcConfig =
final StorageGrpcConfiguration grpcConfig =
// TODO
new GrpcConfiguration(Duration.ofMillis(15000)).withKeepAliveDisabled();
final TransportStrategy transportStrategy = new StaticTransportStrategy(grpcConfig);
new StorageGrpcConfiguration(Duration.ofMillis(15000)).withKeepAliveDisabled();
final StorageTransportStrategy transportStrategy =
new StaticStorageTransportStrategy(grpcConfig);
return new Lambda(transportStrategy);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package momento.sdk.config.transport.storage;

/**
* The simplest way to configure gRPC for the Momento client. Specifies static values the transport
* options.
*/
public class StaticStorageTransportStrategy implements StorageTransportStrategy {

private final StorageGrpcConfiguration grpcConfiguration;

/**
* Constructs a StaticStorageTransportStrategy.
*
* @param grpcConfiguration gRPC tunables.
*/
public StaticStorageTransportStrategy(StorageGrpcConfiguration grpcConfiguration) {
this.grpcConfiguration = grpcConfiguration;
}

@Override
public StorageGrpcConfiguration getGrpcConfiguration() {
return grpcConfiguration;
}

@Override
public StorageTransportStrategy withGrpcConfiguration(
StorageGrpcConfiguration grpcConfiguration) {
return new StaticStorageTransportStrategy(grpcConfiguration);
}
}
Loading
Loading