/**
   * Change the EPP client password from oldPassword to newPassword. Note that this does not update
   * the configuration source to reflect the change - that must be done separately before any future
   * attempts to (re-)configure the system.
   */
  @Override
  public void changePassword(String oldPassword, String newPassword) {
    debugLogger.finest("enter");

    userLogger.info(
        ErrorPkg.getMessage(
            "reconfigure.pw.change.init",
            new String[] {"<<old>>", "<<new>>"},
            new String[] {oldPassword, newPassword}));

    sessionPool.empty();

    try {
      Session session = SessionFactory.newInstance(properties.getSessionProperties());
      session.changePassword(newPassword);
      // Attempts to get a session between changePassword and setClientPW
      // will fail if the password was successfully changed. It is the
      // application's responsibility to handle transaction failures
      // during a change of password. This is expected to occur very
      // infrequently.
      properties.getSessionProperties().setClientPW(newPassword);
    } catch (Exception ex) {
      userLogger.severe(ex.getMessage());
      userLogger.severe(ErrorPkg.getMessage("reconfigure.pw.change.fail"));
    }

    debugLogger.finest("exit");
  }
 private void interruptThread(Thread thread) {
   if (thread == null) {
     return;
   }
   try {
     thread.interrupt();
   } catch (SecurityException se) {
     userLogger.warning(ErrorPkg.getMessage("thread.interrupt.secex"));
   }
 }
  /**
   * Prepare the SessionManager for providing Transaction processing services. This initialises the
   * {@link com.ausregistry.jtoolkit2.session.SessionPool} managed by the SessionManager,
   * guaranteeing that any requirements defined by SessionPool properties are met, providing the
   * pool is initialised successfully.
   *
   * @throws SessionConfigurationException The pool was unable configure a session due to a
   *     configuration issue. Such problems include invalid server location specification and
   *     missing or invalid authentication resources.
   * @throws SessionOpenException The pool was unable to open a session due to a configuration
   *     issue. Such problems include incorrect server location, failed authentication and network
   *     failure.
   */
  @Override
  public void startup() throws SessionConfigurationException, SessionOpenException {

    userLogger.info("Startup");

    int failCount = 0;
    boolean initialised = false;

    while (!initialised) {
      try {
        sessionPool.getLastGreeting();
        initialised = true;
        state = SMState.STARTED;
      } catch (InterruptedException ie) {
        failCount++;

        if (failCount < MAX_ACCEPTABLE_FAIL_COUNT) {
          userLogger.warning(ErrorPkg.getMessage("startup.interrupted"));
        } else {
          userLogger.severe(ErrorPkg.getMessage("startup.interrupted"));
          throw new SessionOpenException(ie);
        }
      } catch (SessionOpenException soe) {
        Throwable t = soe.getCause();

        if (t instanceof LoginException
            && t.getCause() instanceof CommandFailedException
            && failCount < MAX_ACCEPTABLE_FAIL_COUNT) {

          failCount++;
        } else {
          throw soe;
        }
      }
    }
  }
  /**
   * Initiate the SessionPool's keep-alive system. This will run until <a
   * href=#shutdown()>shutdown</a> is invoked on the SessionManager.
   */
  @Override
  public void run() {
    debugLogger.finest("enter");

    if (state != SMState.STARTED) {
      return;
    }

    runThread = Thread.currentThread();
    state = SMState.RUNNING;

    try {
      while (state == SMState.RUNNING) {
        long sleepInterval = sessionPool.keepAlive();

        boolean interrupted = false;
        int retry = 0;
        int maxRetries = MAX_SLEEP_INTERRUPTS_TO_FAIL;

        long sleepTime, awakenTime;
        do {
          sleepTime = Timer.now();

          try {
            retry++;
            if (sleepInterval > 0) {
              Thread.sleep(sleepInterval);
            }
            interrupted = false;
          } catch (InterruptedException ie) {
            // reduce the remaining sleep interval
            awakenTime = Timer.now();
            sleepInterval += sleepTime - awakenTime;
            interrupted = true;
          }
        } while (interrupted && retry < maxRetries && state == SMState.RUNNING);
      }
    } catch (IOException ioe) {
      userLogger.severe(ioe.getMessage());
      userLogger.severe(ioe.getCause().getMessage());
      userLogger.severe(ErrorPkg.getMessage("epp.session.poll.cfg.fail"));
    }

    debugLogger.finest("exit");
  }