HighAvailabilityModeSwitcher refactoring and fixes

HAMS has been refactored so that it mainly deals with decision and coordination. The actual switch code is in separate classes.
This PR also fixes that shutdown was not happening on switcher thread, which during testing can cause the situation that an instance is first shutdown, but then switches to slave in the separate thread. All switching now happens on the same thread, so that the outcome is deterministic.