Re: [akka-user][deprecated] Stashing messages in persistent typed actor 2.5.17

2018-10-02 Thread oscar . sanchez . delarbol
Done!
https://github.com/akka/akka/issues/25717

thanks!

-- 
*
** New discussion forum: https://discuss.akka.io/ replacing akka-user 
google-group soon.
** This group will soon be put into read-only mode, and replaced by 
discuss.akka.io
** More details: https://akka.io/blog/news/2018/03/13/discuss.akka.io-announced
*
>> 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user][deprecated] Stashing messages in persistent typed actor 2.5.17

2018-10-02 Thread oscar . sanchez . delarbol
Done!
https://github.com/akka/akka/issues/25717

thanks!

El martes, 2 de octubre de 2018, 8:10:11 (UTC+2), Patrik Nordwall escribió:
>
> Could you create an issue  for 
> this. I think this is a bug.
>
> On Fri, Sep 28, 2018 at 1:53 PM > 
> wrote:
>
>> I have an actor with the next behaviour. When i stash commands, they 
>> never go back to mailbox. Use versions "akka-actor-typed" and 
>> "akka-persistence-typed" 2.5.17
>>
>> object Blog {
>>   //#event
>>   sealed trait BlogEvent   extends 
>> Serializable
>>   final case class PostAdded(postId: String, content: PostContent) extends 
>> BlogEvent
>>   //#event
>>
>>   //#state
>>   object BlogState {
>> val empty = BlogState(None)
>>   }
>>
>>   final case class BlogState(content: Option[PostContent]) {
>> def withContent(newContent: PostContent): BlogState =
>>   copy(content = Some(newContent))
>> def isEmpty: Boolean = content.isEmpty
>> def postId: String = content match {
>>   case Some(c) ⇒ c.postId
>>   case None⇒ throw new IllegalStateException("postId unknown before 
>> post is created")
>> }
>>   }
>>   //#state
>>
>>   //#commands
>>   sealed trait BlogCommand   
>> extends Serializable
>>   final case class AddPost(content: PostContent, replyTo: 
>> ActorRef[AddPostDone]) extends BlogCommand
>>   final case class Accumulate(num: Int)  
>> extends BlogCommand
>>   final case class AddPostDone(postId: String)
>>   final case class PostContent(postId: String, title: String, body: String)
>>   //#commands
>>
>>   def behavior: Behavior[BlogCommand] =
>> Behaviors.setup[BlogCommand] { ctx ⇒
>>   val buffer = StashBuffer[BlogCommand](capacity = 1000)
>>
>>   //#initial-command-handler
>>   def initial(cmd: BlogCommand): Effect[BlogEvent, BlogState] =
>> cmd match {
>>   case AddPost(content, replyTo) ⇒
>> Effect
>>   .persist(PostAdded(content.postId, content))
>>   .thenRun { _ ⇒
>> replyTo ! AddPostDone(content.postId)
>> println("initial thenRun " + buffer.toString)
>> buffer.unstashAll(ctx, this.behavior)
>> println("initial thenRun 2 " + buffer.toString)
>>   }
>>   case a @ Accumulate(_) =>
>> println("initial antes de stash " + buffer.toString)
>> buffer.stash(a)
>> println("initial despues de stash " + buffer.toString)
>> Effect.none
>>   case _ ⇒
>> Effect.unhandled
>> 
>>
>>
>
> -- 
>
> Patrik Nordwall
> Akka Tech Lead
> Lightbend  -  Reactive apps on the JVM
> Twitter: @patriknw
>
>

-- 
*
** New discussion forum: https://discuss.akka.io/ replacing akka-user 
google-group soon.
** This group will soon be put into read-only mode, and replaced by 
discuss.akka.io
** More details: https://akka.io/blog/news/2018/03/13/discuss.akka.io-announced
*
>> 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user][deprecated] Stashing messages in persistent typed actor 2.5.17

2018-10-02 Thread Patrik Nordwall
Could you create an issue  for
this. I think this is a bug.

On Fri, Sep 28, 2018 at 1:53 PM  wrote:

> I have an actor with the next behaviour. When i stash commands, they never
> go back to mailbox. Use versions "akka-actor-typed" and
> "akka-persistence-typed" 2.5.17
>
> object Blog {
>   //#event
>   sealed trait BlogEvent   extends 
> Serializable
>   final case class PostAdded(postId: String, content: PostContent) extends 
> BlogEvent
>   //#event
>
>   //#state
>   object BlogState {
> val empty = BlogState(None)
>   }
>
>   final case class BlogState(content: Option[PostContent]) {
> def withContent(newContent: PostContent): BlogState =
>   copy(content = Some(newContent))
> def isEmpty: Boolean = content.isEmpty
> def postId: String = content match {
>   case Some(c) ⇒ c.postId
>   case None⇒ throw new IllegalStateException("postId unknown before 
> post is created")
> }
>   }
>   //#state
>
>   //#commands
>   sealed trait BlogCommand
>extends Serializable
>   final case class AddPost(content: PostContent, replyTo: 
> ActorRef[AddPostDone]) extends BlogCommand
>   final case class Accumulate(num: Int)   
>extends BlogCommand
>   final case class AddPostDone(postId: String)
>   final case class PostContent(postId: String, title: String, body: String)
>   //#commands
>
>   def behavior: Behavior[BlogCommand] =
> Behaviors.setup[BlogCommand] { ctx ⇒
>   val buffer = StashBuffer[BlogCommand](capacity = 1000)
>
>   //#initial-command-handler
>   def initial(cmd: BlogCommand): Effect[BlogEvent, BlogState] =
> cmd match {
>   case AddPost(content, replyTo) ⇒
> Effect
>   .persist(PostAdded(content.postId, content))
>   .thenRun { _ ⇒
> replyTo ! AddPostDone(content.postId)
> println("initial thenRun " + buffer.toString)
> buffer.unstashAll(ctx, this.behavior)
> println("initial thenRun 2 " + buffer.toString)
>   }
>   case a @ Accumulate(_) =>
> println("initial antes de stash " + buffer.toString)
> buffer.stash(a)
> println("initial despues de stash " + buffer.toString)
> Effect.none
>   case _ ⇒
> Effect.unhandled
>
>
>

-- 

Patrik Nordwall
Akka Tech Lead
Lightbend  -  Reactive apps on the JVM
Twitter: @patriknw

-- 
*
** New discussion forum: https://discuss.akka.io/ replacing akka-user 
google-group soon.
** This group will soon be put into read-only mode, and replaced by 
discuss.akka.io
** More details: https://akka.io/blog/news/2018/03/13/discuss.akka.io-announced
*
>> 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user][deprecated] Stashing messages in persistent typed actor

2018-09-21 Thread oscar . sanchez . delarbol
I have an actor with the next behaviour. When i stash commands, they never 
go back to mailbox.
Use versions *"akka-actor-typed"* and *"akka-persistence-typed"* 2.5.16

object Blog {
  //#event
  sealed trait BlogEvent   
extends Serializable
  final case class PostAdded(postId: String, content: PostContent) 
extends BlogEvent
  //#event

  //#state
  object BlogState {
val empty = BlogState(None)
  }

  final case class BlogState(content: Option[PostContent]) {
def withContent(newContent: PostContent): BlogState =
  copy(content = Some(newContent))
def isEmpty: Boolean = content.isEmpty
def postId: String = content match {
  case Some(c) ⇒ c.postId
  case None⇒ throw new IllegalStateException("postId unknown 
before post is created")
}
  }
  //#state

  //#commands
  sealed trait BlogCommand 
  extends Serializable
  final case class AddPost(content: PostContent, replyTo: ActorRef[
AddPostDone]) extends BlogCommand
  final case class Accumulate(num: Int) 
 extends BlogCommand
  final case class AddPostDone(postId: String)
  final case class PostContent(postId: String, title: String, body: 
String)
  //#commands

  def behavior: Behavior[BlogCommand] =
Behaviors.setup[BlogCommand] { ctx ⇒
  val buffer = StashBuffer[BlogCommand](capacity = 1000)

  //#initial-command-handler
  val initial
: (ActorContext[BlogCommand], BlogState, BlogCommand) ⇒ Effect[
BlogEvent, BlogState] =
(ctx, state, cmd) ⇒
  cmd match {
case AddPost(content, replyTo) ⇒
  Effect
.persist(PostAdded(content.postId, content))
.thenRun { state2 ⇒
  replyTo ! AddPostDone(content.postId)
  buffer.unstashAll(ctx, this.behavior)
}
case a @ Accumulate(_) =>
  buffer.stash(a)
  Effect.none
case _ ⇒
  Effect.unhandled
}
  //#initial-command-handler

  //#post-added-command-handler
  val postAdded
: (ActorContext[BlogCommand], BlogState, BlogCommand) ⇒ Effect[
BlogEvent, BlogState] = {
(ctx, state, cmd) ⇒
  cmd match {
case _: AddPost ⇒
  Effect.unhandled
case Accumulate(num) ⇒
  println(s"Accumulate: $num**")
  Effect.none
case c ⇒
  Effect.unhandled
  }
  }
  //#post-added-command-handler

  //#by-state-command-handler
  val commandHandler
: (ActorContext[BlogCommand], BlogState, BlogCommand) ⇒ Effect[
BlogEvent, BlogState] =
CommandHandler.byState {
  case state if state.isEmpty ⇒
initial
  case state if !state.isEmpty ⇒
postAdded
}
  //#by-state-command-handler

  //#event-handler
  val eventHandler: (BlogState, BlogEvent) ⇒ BlogState = { (state, 
event) ⇒
event match {
  case PostAdded(postId, content) ⇒
state.withContent(content)
}
  }
  //#event-handler

  //#behavior
  PersistentBehaviors.receive[BlogCommand, BlogEvent, 
BlogState](persistenceId 
= "Blog",

 emptyState = BlogState.empty,

 commandHandler,

 eventHandler)
//#behavior
}
}

I try:

val blog = system.spawn(Blog.behavior, "Typed")

blog ! Accumulate(1)
blog ! Accumulate(2)
blog ! Accumulate(3)
blog ! AddPost(PostContent("id1", "title1", "body"), typedSystem.
deadLetters)
blog ! Accumulate(4)

The commands *Accumulate(1), Accumulate(2), Accumulate(3)* were stashed in* 
initial-command-handler* but when do *buffer.unstashAll(ctx, this.behavior)* 
the commands are lost, they do not go back to mailbox

-- 
*
** New discussion forum: https://discuss.akka.io/ replacing akka-user 
google-group soon.
** This group will soon be put into read-only mode, and replaced by 
discuss.akka.io
** More details: https://akka.io/blog/news/2018/03/13/discuss.akka.io-announced
*
>> 
>>