@Override
  protected void registerRecovery() {
    memberStateMachine.addHighAvailabilityMemberListener(
        new HighAvailabilityMemberListener() {
          @Override
          public void masterIsElected(HighAvailabilityMemberChangeEvent event) {}

          @Override
          public void masterIsAvailable(HighAvailabilityMemberChangeEvent event) {
            if (event.getOldState().equals(HighAvailabilityMemberState.TO_MASTER)
                && event.getNewState().equals(HighAvailabilityMemberState.MASTER)) {
              doAfterRecoveryAndStartup(true);
            }
          }

          @Override
          public void slaveIsAvailable(HighAvailabilityMemberChangeEvent event) {
            if (event.getOldState().equals(HighAvailabilityMemberState.TO_SLAVE)
                && event.getNewState().equals(HighAvailabilityMemberState.SLAVE)) {
              doAfterRecoveryAndStartup(false);
            }
          }

          @Override
          public void instanceStops(HighAvailabilityMemberChangeEvent event) {}

          private void doAfterRecoveryAndStartup(boolean isMaster) {
            try {
              synchronized (xaDataSourceManager) {
                HighlyAvailableGraphDatabase.this.doAfterRecoveryAndStartup(isMaster);
              }
            } catch (Throwable throwable) {
              msgLog.error("Post recovery error", throwable);
              try {
                memberStateMachine.stop();
              } catch (Throwable throwable1) {
                msgLog.warn("Could not stop", throwable1);
              }
              try {
                memberStateMachine.start();
              } catch (Throwable throwable1) {
                msgLog.warn("Could not start", throwable1);
              }
            }
          }
        });
  }
 @Override
 public void stop() throws Throwable {
   memberStateMachine.removeHighAvailabilityMemberListener(listener);
 }
 @Override
 public void start() throws Throwable {
   memberStateMachine.addHighAvailabilityMemberListener(listener);
 }
 public boolean isMaster() {
   return memberStateMachine.getCurrentState() == HighAvailabilityMemberState.MASTER;
 }
 public String getInstanceState() {
   return memberStateMachine.getCurrentState().name();
 }