code: private Behavior becomePostAdded(BlogState newState) {
      BehaviorBuilder b = newBehaviorBuilder(newState);
  
      b.setCommandHandler(ChangeBody.class,
          (cmd, ctx) -> ctx.thenPersist(new BodyChanged(entityId(), cmd.getBody()), evt ->
            ctx.reply(Done.getInstance())));
  
      b.setEventHandler(BodyChanged.class, evt -> state().withBody(evt.getBody()));
  
      //#publish
      b.setCommandHandler(Publish.class,
          (cmd, ctx) -> ctx.thenPersist(new PostPublished(entityId()), evt -> {
              ctx.reply(Done.getInstance());
              publishedTopic.publish(evt);
            }));
      //#publish
  
      b.setEventHandler(PostPublished.class, evt ->
        new BlogState(state().getContent(), true));
  
      return b.build();
    }
docs: Behavior can be changed in the event handlers.