@@ -10,6 +10,8 @@ import scala.jdk.CollectionConverters._
10
10
import scala .jdk .DurationConverters ._
11
11
12
12
import akka .actor .typed .ActorSystem
13
+ import akka .annotation .ApiMayChange
14
+ import akka .annotation .DoNotInherit
13
15
import akka .annotation .InternalStableApi
14
16
import akka .util .Helpers
15
17
import com .typesafe .config .Config
@@ -61,6 +63,10 @@ object DynamoDBSettings {
61
63
62
64
val clockSkewSettings = new ClockSkewSettings (config)
63
65
66
+ val journalFallbackSettings = JournalFallbackSettings (config.getConfig(" journal.fallback-store" ))
67
+
68
+ val snapshotFallbackSettings = SnapshotFallbackSettings (config.getConfig(" snapshot.fallback-store" ))
69
+
64
70
new DynamoDBSettings (
65
71
journalTable,
66
72
journalPublishEvents,
@@ -70,7 +76,9 @@ object DynamoDBSettings {
70
76
timeToLiveSettings,
71
77
journalBySliceGsi,
72
78
snapshotBySliceGsi,
73
- clockSkewSettings)
79
+ clockSkewSettings,
80
+ journalFallbackSettings,
81
+ snapshotFallbackSettings)
74
82
}
75
83
76
84
/**
@@ -93,7 +101,16 @@ final class DynamoDBSettings private (
93
101
val timeToLiveSettings : TimeToLiveSettings ,
94
102
val journalBySliceGsi : String ,
95
103
val snapshotBySliceGsi : String ,
96
- val clockSkewSettings : ClockSkewSettings )
104
+ val clockSkewSettings : ClockSkewSettings ,
105
+ val journalFallbackSettings : JournalFallbackSettings ,
106
+ val snapshotFallbackSettings : SnapshotFallbackSettings ) {
107
+ override def toString : String =
108
+ s " DynamoDBSettings(journalTable= $journalTable, journalPublishEvents= $journalPublishEvents, " +
109
+ s " snapshotTable= $snapshotTable, querySettings= $querySettings, cleanupSettings= $cleanupSettings, " +
110
+ s " timeToLiveSettings= $timeToLiveSettings, journalBySliceGsi= $journalBySliceGsi, " +
111
+ s " snapshotBySliceGsi= $snapshotBySliceGsi, clockSkewSettings= $clockSkewSettings, " +
112
+ s " journalFallbackSettings= $journalFallbackSettings, snapshotFallbackSettings= $snapshotFallbackSettings) "
113
+ }
97
114
98
115
final class QuerySettings (config : Config ) {
99
116
val refreshInterval : FiniteDuration = config.getDuration(" refresh-interval" ).toScala
@@ -320,6 +337,55 @@ final class ClockSkewSettings(config: Config) {
320
337
override def toString : String = s " ClockSkewSettings( $warningTolerance) "
321
338
}
322
339
340
+ /** Not for user extension */
341
+ @ DoNotInherit
342
+ sealed abstract class FallbackSettings (val plugin : String , val threshold : Int ) {
343
+ require(threshold > 0 , " threshold must be positive" )
344
+ require(threshold <= (400 * 1000 ), " threshold must be at most 400 KB" )
345
+
346
+ // Must be overridden in subclasses
347
+ override def toString : String = throw new scala.NotImplementedError
348
+
349
+ def isEnabled : Boolean = plugin.nonEmpty
350
+ }
351
+
352
+ @ ApiMayChange
353
+ final class SnapshotFallbackSettings (plugin : String , threshold : Int ) extends FallbackSettings (plugin, threshold) {
354
+ override def toString : String =
355
+ if (isEnabled)
356
+ s " SnapshotFallbackSettings(plugin= $plugin, threshold= ${threshold}B) "
357
+ else " disabled"
358
+ }
359
+
360
+ object SnapshotFallbackSettings {
361
+ def apply (config : Config ): SnapshotFallbackSettings = {
362
+ val plugin = config.getString(" plugin" )
363
+ val threshold = java.lang.Long .min(config.getBytes(" threshold" ), 400 * 1000 ).toInt
364
+
365
+ new SnapshotFallbackSettings (plugin, threshold)
366
+ }
367
+ }
368
+
369
+ @ ApiMayChange
370
+ final class JournalFallbackSettings (commonSettings : SnapshotFallbackSettings , val batchSize : Int )
371
+ extends FallbackSettings (commonSettings.plugin, commonSettings.threshold) {
372
+ require(! commonSettings.isEnabled || batchSize > 0 , " batch size must be positive" )
373
+
374
+ override def toString : String =
375
+ if (isEnabled)
376
+ s " JournalFallbackSettings(plugin= $plugin, threshold= ${threshold}B, batchSize= $batchSize) "
377
+ else " disabled"
378
+ }
379
+
380
+ object JournalFallbackSettings {
381
+ def apply (config : Config ): JournalFallbackSettings = {
382
+ val commonSettings = SnapshotFallbackSettings (config)
383
+ val batchSize = config.getInt(" batch-size" )
384
+
385
+ new JournalFallbackSettings (commonSettings, batchSize)
386
+ }
387
+ }
388
+
323
389
private [akka] object ConfigHelpers {
324
390
def optString (config : Config , path : String ): Option [String ] = {
325
391
if (config.hasPath(path)) {
0 commit comments