-
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.
Merge pull request #10 from momentohq/topics-configs
feat: add configuration objects for TopicClient
- Loading branch information
Showing
7 changed files
with
124 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'transport/grpc_configuration.dart'; | ||
import 'transport/transport_strategy.dart'; | ||
|
||
abstract interface class TopicConfiguration { | ||
/// Configures low-level options for network interactions with the Momento service | ||
late TransportStrategy transportStrategy; | ||
|
||
/// Constructor for a TopicConfiguration | ||
TopicConfiguration(this.transportStrategy); | ||
|
||
/// Copy constructor for overriding TransportStrategy | ||
TopicConfiguration withTransportStrategy(TransportStrategy transportStrategy); | ||
|
||
/// Convenience copy constructor that updates the client-side | ||
/// timeout setting in the transport strategy | ||
TopicConfiguration withDeadline(Duration deadline); | ||
} | ||
|
||
/// Configuration options for Momento TopicClient. | ||
/// The easiest way to get a `TopicClientConfiguration` object is | ||
/// to use one of the prebuilt TopicClientConfigurations classes. | ||
class TopicClientConfiguration implements TopicConfiguration { | ||
@override | ||
late TransportStrategy transportStrategy; | ||
|
||
TopicClientConfiguration(this.transportStrategy); | ||
|
||
@override | ||
TopicConfiguration withTransportStrategy(TransportStrategy transportStrategy) { | ||
return TopicClientConfiguration(transportStrategy); | ||
} | ||
|
||
@override | ||
TopicConfiguration withDeadline(Duration deadline) { | ||
return TopicClientConfiguration(StaticTransportStrategy(StaticGrpcConfiguration(deadline))); | ||
} | ||
} |
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,17 @@ | ||
import 'topic_configuration.dart'; | ||
import 'transport/grpc_configuration.dart'; | ||
import 'transport/transport_strategy.dart'; | ||
|
||
/// Prebuilt configurations for Momento Topics clients | ||
abstract interface class TopicClientConfigurations {} | ||
|
||
/// Provides prebuilt configurations for the `TopicClient` on mobile platforms | ||
class Mobile extends TopicClientConfigurations { | ||
static TopicClientConfiguration defaultConfig() { | ||
return latest(); | ||
} | ||
|
||
static TopicClientConfiguration latest() { | ||
return TopicClientConfiguration(StaticTransportStrategy(StaticGrpcConfiguration(Duration(seconds: 15)))); | ||
} | ||
} |
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,21 @@ | ||
abstract interface class GrpcConfiguration { | ||
/// Duration of time the client is willing to wait for an RPC to | ||
/// complete before it is terminated with a DeadlineExceeded error | ||
late Duration deadline; | ||
|
||
/// Copy constructor for overriding the client-side deadline | ||
GrpcConfiguration withDeadline(Duration deadline); | ||
} | ||
|
||
/// Encapsulates gRPC configuration tunables | ||
class StaticGrpcConfiguration implements GrpcConfiguration { | ||
@override | ||
late Duration deadline; | ||
|
||
StaticGrpcConfiguration(this.deadline); | ||
|
||
@override | ||
GrpcConfiguration withDeadline(Duration deadline) { | ||
return StaticGrpcConfiguration(deadline); | ||
} | ||
} |
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,30 @@ | ||
import 'grpc_configuration.dart'; | ||
|
||
abstract interface class TransportStrategy { | ||
/// Low-level gRPC settings for communication with the Momento server | ||
late GrpcConfiguration grpcConfig; | ||
|
||
/// Copy constructor to update the client-side timeout | ||
TransportStrategy withGrpcConfig(GrpcConfiguration grpcConfig); | ||
|
||
/// Copy constructor to update the client-side timeout | ||
TransportStrategy withClientTimeout(Duration timeout); | ||
} | ||
|
||
class StaticTransportStrategy implements TransportStrategy { | ||
@override | ||
late GrpcConfiguration grpcConfig; | ||
|
||
StaticTransportStrategy(this.grpcConfig); | ||
|
||
@override | ||
TransportStrategy withClientTimeout(Duration timeout) { | ||
return StaticTransportStrategy(StaticGrpcConfiguration(timeout)); | ||
} | ||
|
||
@override | ||
TransportStrategy withGrpcConfig(GrpcConfiguration grpcConfig) { | ||
return StaticTransportStrategy(grpcConfig); | ||
} | ||
|
||
} |
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