Need bit clarification on sendAndWait() command

1,293 views
Skip to first unread message

Anand Kadhi

unread,
May 29, 2015, 6:03:23 AM5/29/15
to axonfr...@googlegroups.com
Hello,

I am a newbie in axon framework, I am a bit confused about sendAndWait command.

First :
From the docs :

Sends the given command and wait for it to execute. The result of the execution is returned when available. This method will block indefinitely, until a result is available, or until the Thread is interrupted. When the thread is interrupted, this method returns null. If command execution resulted in an exception, it is wrapped in a org.axonframework.commandhandling.CommandExecutionException..

So is the caller thread blocked or the thread spawned after the sendAndWait is fired is blocked.For example if i am calling the sendAndWait() command from main will main thread be blocked ? And if it is the case then

class main (String args[])

{

commandGateway.sendAndWait(new Command());

System.out.println("Thread not blocked");

}

"Thread not blocked" should not be logged.

Second:

The sendAndWait() command returns the result for the execution of the command.

From the docs:

The result of the execution is returned when available.

and in the commandHandler we write :

@CommandHandler
    public void acknowledge(AcknowledgedCommand acknowledgedCommand) {
        apply(new AcknowledgedEvent(
                acknowledgedCommand.getA(), acknowledgedCommand.getB()));
    }

The apply command return's void then how the command execution result is returned.Even if do some modification in the eventHandler like returning value from the event handler (which is not recommended but done only for the purpose of testing)

    @SagaEventHandler(associationProperty = "a")
    public String handle(StateEvent stateEvent) {
         return   this.state = stateEvent.getState();
        }

The event would not return back anything on the commandHandler. As the flow does not go back again to the commandHandler after execution of the event (until and unless command is published from the event ). Then what is actually returned from the execution ?

If anyone can clarify it would be great.

Thanks,




Anand Kadhi

unread,
May 29, 2015, 7:57:50 AM5/29/15
to axonfr...@googlegroups.com
Please ignore the First point of sendAndWait thread blocking , as i was using async saga it was firing the command and returning back.so the log statement was printed.

Allard Buijze

unread,
May 31, 2015, 12:31:15 PM5/31/15
to axonfr...@googlegroups.com
Hi,

the return value is the value returned by the @CommandHandler method. The event handlers don't play any role in this. Just imagine having dozens of listeners for an event applied by a command; what would be the return value? 

SendAndWait will block the sending thread until the command has been executed and its result has been reported.

cheers,

Allard




--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages