forked from akka/akka
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Horrible hack to access latestSeqNr in typed persistence akka#25113
- Loading branch information
1 parent
b0b0865
commit f23d627
Showing
4 changed files
with
45 additions
and
3 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
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
39 changes: 39 additions & 0 deletions
39
...istence-typed/src/main/scala/akka/persistence/typed/scaladsl/PersistentActorContext.scala
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,39 @@ | ||
/* | ||
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package akka.persistence.typed.scaladsl | ||
|
||
import akka.actor.typed.internal.adapter.ActorContextAdapter | ||
import akka.actor.typed.scaladsl.ActorContext | ||
import akka.persistence.typed.internal.Running | ||
|
||
object PersistentActorContext { | ||
|
||
/** | ||
* Access the to details about the persistent actor from the actor context, can only be used in response | ||
* to a command, will throw `IllegalState` for other cases | ||
*/ | ||
def apply(context: ActorContext[_]): PersistentActorContext = { | ||
context match { | ||
case impl: ActorContextAdapter[_] ⇒ | ||
impl.currentBehavior match { | ||
case w: Running.WithStateAccessible ⇒ | ||
new PersistentActorContext { | ||
def lastSequenceNr: Long = w.state.seqNr | ||
} | ||
|
||
case s ⇒ throw new IllegalStateException(s"Cannot extract the PersistentActorContext in state ${s.getClass.getName}") | ||
|
||
} | ||
|
||
case c ⇒ throw new IllegalStateException(s"Cannot extract the PersistentActorContext from context ${c.getClass.getName}") | ||
} | ||
} | ||
|
||
} | ||
|
||
trait PersistentActorContext { | ||
def lastSequenceNr: Long | ||
} | ||
|