The STATE_TRANSFER layer is responsible to reply to GET_STATE events sent from the channel and return the state in a GET_STATE_OK event. It will interact with other group members to get the group state. The protocol interaction is shown in fig. 7.2.
In the second phase, the initiator selects one member (possibly the oldest, or the coordinator) and sends a RETURN_STATE message to it. The receiver returns its copy of the state that was created upon reception of MAKE_COPY. The initiator sets its state and then replays all queued messages before accepting regular messages again. (Message will not be queued after replaying the queued messages).
The above scheme requires that messages are received by all members in the same order (total ordering). Thus, message MAKE_COPY is received by all members at the same logical time, allowing the initiator of a state transfer to queue all subsequent messages until reception of the state.
The events exchanged between peer STATE_TRANSFER layers and their JChannel instances are shown in fig. 7.3.
The second message is a RETURN_STATE message (2) sent only to one selected member7.5. This is currently the oldest member (usually the coordinator). Note that the message is never sent to the initiator itself. The receiver just returns the previously saved copy of the state.
When the initiator receives the copy from the selected member, it does two things: first it sets its own state from the data received. Then, it blocks all message reception, replays the message queue (to which all messages received after MAKE_COPY were queued), disables queueing and unblocks message reception. From now on, messages received will not be queued, but passed up to the channel and on to the application where they will be applied to the application's current state. Queueing ensures that any message sent after MAKE_COPY and before receiving the state will not be lost, but properly applied to construct a valid state.
When the state was received, a GET_STATE_OK event is passed up the stack. When processed by JChannel, a STATE_RECEIVED event is created and inserted into JChanel's event queue. After this, a caller blocked on the GetState method will return (true or false). One of the next calls to Receive will return a SetStateEvent object containing the state, which can then be set by the application.
The implementation of STATE_TRANSFER relies on total ordering of messages multicast to all group members: it is based on the assumption that all members receive the MAKE_COPY message at the same logical time. If this was not the case, then the different participants might save different versions of the state. For example if participant Q received messages m1, MAKE_COPY and m2, and participant R received m1, m2 and MAKE_COPY then, the state saved by Q would include m1, but R's state would include m1 and m2.