@SuppressWarnings("unchecked")
  public <Reply, Cmd extends Object & PersistentEntity.ReplyType<Reply>> CompletionStage<Reply> ask(Cmd command) {

    CompletionStage<Object> future = Patterns.ask(region, new CommandEnvelope(entityId, command), timeout);

    return future.thenCompose(result -> {
      if (result instanceof Throwable) {
        CompletableFuture<Reply> failed = new CompletableFuture<>();
        failed.completeExceptionally((Throwable) result);
        return failed;
      } else {
        return CompletableFuture.completedFuture((Reply) result);
      }
    });

  }
@ SuppressWarnings ( "unchecked" ) public < Reply , Cmd extends Object & PersistentEntity . ReplyType < Reply > > CompletionStage < Reply > ask ( Cmd command ) { CompletionStage < Object > future = Patterns . ask ( region , new CommandEnvelope ( entityId , command ) , timeout ) ; return future . thenCompose ( result -> { if ( result instanceof Throwable ) { CompletableFuture < Reply > failed = new CompletableFuture < > ( ) ; failed . completeExceptionally ( ( Throwable ) result ) ; return failed ; } else { return CompletableFuture . completedFuture ( ( Reply ) result ) ; } } ) ; }
Send the <code>command</code> to the {@link PersistentEntity}. The returned
<code>CompletionStage</code> will be completed with the reply from the <code>PersistentEntity</code>.
The type of the reply is defined by the command (see {@link PersistentEntity.ReplyType}).
<p>
The <code>CompletionStage</code> may also be completed with failure, sent by the <code>PersistentEntity</code>
or a <code>akka.pattern.AskTimeoutException</code> if there is no reply within a timeout.
The timeout can defined in configuration or overridden using {@link #withAskTimeout(Duration)}.