Homework 0 forum

Purpose of Exec function and Handler

 
Picture of Mathieu Caboche
Purpose of Exec function and Handler
by Mathieu Caboche - Tuesday, 29 September 2020, 16:19
 
Hello,

I do not completely understand the way we are supposed to use handlers and the Exec function.

My understanding is that the handlers are registered in the NewGossiper function (given). The handlers use the Exec function to handle different types of received messages.

However I don't get if we are ever supposed to call Exec ourselves (either directly or via ExecuteHandler). Additionally, it doesn't seem clear from the handout or the code what functionnality should be in Exec, i.e. should Exec be sending any messages? Or is Run responsible for this? Or maybe AddMessage?

I feel the purpose and functionnality of Exec should be explained more precisely.

Thanks!
Mathieu
Picture of Mathieu Caboche
Purpose of Exec function and Handler
by Mathieu Caboche - Tuesday, 29 September 2020, 16:36
 
Also, I wonder if (and where) we are supposed to be listening for client connections in the gossiper since there is no mention of this either in the code or in the handout.
Picture of Adrian Matthijs Christian Hamelink
Purpose of Exec function and Handler
by Adrian Matthijs Christian Hamelink - Tuesday, 29 September 2020, 17:15
 
The controller.go handles client messages. If you look at the code, you will see that it calls Gossiper.AddSimpleMessage when a POST is called on /message
Picture of Mathieu Caboche
Purpose of Exec function and Handler
by Mathieu Caboche - Tuesday, 29 September 2020, 18:24
 
Thanks !

I understand that this means that Exec should not be sending anything, rather just processing the messages, is that right?
Picture of Mathieu Caboche
Purpose of Exec function and Handler
by Mathieu Caboche - Tuesday, 29 September 2020, 16:36
 
Also, I wonder if (and where) we are supposed to be listening for client connections in the gossiper since there is no mention of this either in the code or in the handout.
Picture of Adrian Matthijs Christian Hamelink
Purpose of Exec function and Handler
by Adrian Matthijs Christian Hamelink - Tuesday, 29 September 2020, 17:38
 
The code for handlers is a bit complicated to understand but rather elegant. The gossiper stores the types of messages it can handle via the RegisterHandler method.
Using these, the ExecuteHandler method, when called with a pointer to a strict with the same type (here *SimpleMessage), will find the Exec method defined for this type.
In future homework, if we need to handle other message types, you can continue calling ExecuteHandler on the new message type and just define a new Exec method.
Therefore, the (*SimpleMessage) Exec method is called by ExecuteHandler when the gossiper receives a new message from the network, and you need to only call ExecuteHandler

This is just from my understanding of the code. There may be other reasons why it was designed as such.
Picture of Mathieu Caboche
Purpose of Exec function and Handler
by Mathieu Caboche - Tuesday, 29 September 2020, 18:28
 
Thanks for your answer!

That's how I understood it also.
profile
Re: Purpose of Exec function and Handler
by Kirill Nikitin - Tuesday, 29 September 2020, 22:28
 

Thanks to Adrian for the great explanation!

Mathieu, we indeed suggest in the skeleton to define the Exec method that handles a given message type (in the case of this homework, it's SimpleMessage). Adrian explains well the logic of how it can be executed. Note that we, however, do not require you to strictly follow the proposed structure in your implementation. In fact, designing the logic of your program is a part of this assignment (and of the learning process). Hence, I suggest that you consider possible designs and decide yourself where certain logic, e.g., of message sending, should be placed.

Best,

Kirill

Picture of Mathieu Caboche
Purpose of Exec function and Handler
by Mathieu Caboche - Tuesday, 29 September 2020, 23:10
 
Well that clears it up,

Thanks to everyone for all this input !