Ejemplo n.º 1
0
  @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 start() throws Throwable {
   memberStateMachine.addHighAvailabilityMemberListener(listener);
 }