...
A note on the subscriptionState: Its reference will be shared by both the polling and background threads.
Important Components
Background thread and its lifecycle
...
Background thread and its lifecycle
Upon initialization of the consumer, the coordinator is down
The polling thread starts the background thread; the background thread moves to the initialized state
The background thread loop:
Poll for the new events (for example, a commit event) from the queue, if any
Check the background thread state (connected to a coordinator or not)
If the event requires a coordinator. Moves the coordinator to the discovery (coordinator discovery) state.
If not, execute the event.
Check the coordinator connection. If the FindCoordinator request hasn't been completed, stay in the discovery state. If the request fails, transition to the initialized state. Otherwise, the coordinator is found and transition to the stable state.
Poll ConsumerCoordinator
Poll networkClient
Go to 3
If close() is received:
set close to true to that the loop and exit
poll coordinator and network client
Commit
...