diff --git a/README.md b/README.md index 07258dc..d099953 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,11 @@ and the Flutter guide for 4. `brew info dart` to determine where the dart sdk is installed 5. followed [these](https://fluttermaster.com/config-dart-sdk-inside-intellij-idea-on-macos/) instructions on how to setup sdk inside of intellij +In VSCode, there's an extension for Dart and Flutter files. +To install dependencies using CLI: `dart pub get` +Running tests: `dart test` +Linting and formatting: `dart format` and `dart fix` + TODO: Put a short description of the package here that helps potential users know whether this package might be useful for them. @@ -40,6 +45,17 @@ to `/example` folder. const like = 'sample'; ``` +## Logging + +We use the [Dart logging package](https://github.com/dart-lang/logging) to create internal Loggers for producing Momento-related logs. The default logger does not do anything with the logs, so you must configure the logging level and handler at the beginning of your program: + +``` +Logger.root.level = Level.ALL; // defaults to Level.INFO +Logger.root.onRecord.listen((record) { + print('${record.level.name}: ${record.time}: ${record.message}'); +}); +``` + ## Additional information TODO: Tell users more about the package: where to find more information, how to diff --git a/lib/src/config/topic_configuration.dart b/lib/src/config/topic_configuration.dart index e69de29..0ec0800 100644 --- a/lib/src/config/topic_configuration.dart +++ b/lib/src/config/topic_configuration.dart @@ -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))); + } +} \ No newline at end of file diff --git a/lib/src/config/topic_configurations.dart b/lib/src/config/topic_configurations.dart index e69de29..1545bb8 100644 --- a/lib/src/config/topic_configurations.dart +++ b/lib/src/config/topic_configurations.dart @@ -0,0 +1,17 @@ +import 'topic_configuration.dart'; +import 'transport/grpc_configuration.dart'; +import 'transport/transport_strategy.dart'; + +/// Prebuilt configurations for Momento Topics clients +sealed class TopicClientConfigurations {} + +/// Provides prebuilt configurations for the `TopicClient` on mobile platforms +sealed class Mobile extends TopicClientConfigurations { + static TopicClientConfiguration defaultConfig() { + return latest(); + } + + static TopicClientConfiguration latest() { + return TopicClientConfiguration(StaticTransportStrategy(StaticGrpcConfiguration(Duration(seconds: 15))));; + } +} \ No newline at end of file diff --git a/lib/src/config/transport/grpc_configuration.dart b/lib/src/config/transport/grpc_configuration.dart new file mode 100644 index 0000000..dce078a --- /dev/null +++ b/lib/src/config/transport/grpc_configuration.dart @@ -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); + } +} \ No newline at end of file diff --git a/lib/src/config/transport/transport_strategy.dart b/lib/src/config/transport/transport_strategy.dart new file mode 100644 index 0000000..96724b4 --- /dev/null +++ b/lib/src/config/transport/transport_strategy.dart @@ -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); + } + +} \ No newline at end of file diff --git a/lib/src/topic_client.dart b/lib/src/topic_client.dart index fd07a1c..d25cfd3 100644 --- a/lib/src/topic_client.dart +++ b/lib/src/topic_client.dart @@ -1,4 +1,5 @@ import 'package:client_sdk_dart/src/auth/credential_provider.dart'; +import 'package:logging/logging.dart'; import 'internal/pubsub_client.dart'; import 'messages/Values.dart'; import 'messages/responses/topics/topic_publish.dart'; @@ -10,6 +11,7 @@ abstract class ITopicClient { class TopicClient implements ITopicClient { ClientPubsub _pubsubClient; CredentialProvider _credentialProvider; + final Logger _logger = Logger('MomentoTopicClient'); TopicClient(this._credentialProvider) : _pubsubClient = ClientPubsub(_credentialProvider); diff --git a/pubspec.yaml b/pubspec.yaml index bfc2d06..b40ae61 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,6 +10,7 @@ environment: dependencies: grpc: ^3.2.4 jwt_decoder: ^2.0.1 + logging: ^1.2.0 protobuf: ^3.1.0 string_validator: ^1.0.2 # path: ^1.8.0