Exemplo n.º 1
0
 /**
  * Check that all parameters to update the pool are presents and valid.
  *
  * @param updatePoolDTO
  * @throws URISyntaxException
  */
 private void checkUpdatePoolParameters(UpdatePoolDTO updatePoolDTO)
     throws BadParameterException, URISyntaxException {
   checkPoolParameters(
       updatePoolDTO.getHost(),
       updatePoolDTO.getUsername(),
       updatePoolDTO.getAppendWorkerNames(),
       updatePoolDTO.getPassword(),
       updatePoolDTO.getUseWorkerPassword());
 }
Exemplo n.º 2
0
  /**
   * @param poolToUpdate
   * @throws URISyntaxException
   * @throws PoolStartException
   * @throws SocketException
   * @throws BadParameterException
   */
  public void updatePool(UpdatePoolDTO poolToUpdate)
      throws NotFoundException, SocketException, PoolStartException, URISyntaxException,
          BadParameterException {
    boolean hasBeenStopped = false;
    Pool pool = getPool(poolToUpdate.getName());

    if (pool == null) {
      throw new NotFoundException(
          "The pool with name " + poolToUpdate.getName() + " has not been found.");
    }

    checkUpdatePoolParameters(poolToUpdate);

    if (poolToUpdate.getHost() != null && !poolToUpdate.getHost().equals(pool.getHost())) {
      if (!hasBeenStopped) {
        pool.stopPool("Pool updated and needed to restart.");
      }
      hasBeenStopped = true;
      pool.setHost(poolToUpdate.getHost());
    }

    if (poolToUpdate.getIsExtranonceSubscribeEnabled() != null
        && !poolToUpdate
            .getIsExtranonceSubscribeEnabled()
            .equals(pool.getIsExtranonceSubscribeEnabled())) {
      if (!hasBeenStopped) {
        pool.stopPool("Pool updated and needed to restart.");
      }
      hasBeenStopped = true;
      pool.setIsExtranonceSubscribeEnabled(poolToUpdate.getIsExtranonceSubscribeEnabled());
    }

    if (poolToUpdate.getPassword() != null
        && !poolToUpdate.getPassword().equals(pool.getPassword())) {
      if (!hasBeenStopped) {
        pool.stopPool("Pool updated and needed to restart.");
      }
      hasBeenStopped = true;
      pool.setPassword(poolToUpdate.getPassword());
    }

    if (poolToUpdate.getUsername() != null
        && !poolToUpdate.getUsername().equals(pool.getUsername())) {
      if (!hasBeenStopped) {
        pool.stopPool("Pool updated and needed to restart.");
      }
      hasBeenStopped = true;
      pool.setUsername(poolToUpdate.getUsername());
    }

    if (poolToUpdate.getPriority() != null
        && !poolToUpdate.getPriority().equals(pool.getPriority())) {
      if (poolToUpdate.getPriority() < 0) {
        throw new BadParameterException("The priority has to be higher or equal to 0");
      }
      pool.setPriority(poolToUpdate.getPriority());
      if (poolSwitchingStrategyManager != null) {
        poolSwitchingStrategyManager.onPoolUpdated(pool);
      }
    }

    if (poolToUpdate.getWeight() != null && !poolToUpdate.getWeight().equals(pool.getWeight())) {
      if (poolToUpdate.getWeight() < 0) {
        throw new BadParameterException("The weight has to be higher or equal to 0");
      }
      pool.setWeight(poolToUpdate.getWeight());
      if (poolSwitchingStrategyManager != null) {
        poolSwitchingStrategyManager.onPoolUpdated(pool);
      }
    }

    if (poolToUpdate.getAppendWorkerNames() != null
        && !poolToUpdate.getAppendWorkerNames().equals(pool.isAppendWorkerNames())) {
      if (!hasBeenStopped) {
        pool.stopPool("Pool updated and needed to restart.");
      }
      hasBeenStopped = true;
      pool.setAppendWorkerNames(poolToUpdate.getAppendWorkerNames());
    }

    if (poolToUpdate.getWorkerNamesSeparator() != null
        && !poolToUpdate.getWorkerNamesSeparator().equals(pool.getWorkerSeparator())) {
      pool.setWorkerSeparator(poolToUpdate.getWorkerNamesSeparator());
    }

    if (poolToUpdate.getUseWorkerPassword() != null
        && !poolToUpdate.getUseWorkerPassword().equals(pool.isUseWorkerPassword())) {
      pool.setUseWorkerPassword(poolToUpdate.getUseWorkerPassword());
    }

    // If the pool has been stopped since some options needs a restart,
    // restart the pool.
    if (hasBeenStopped) {
      pool.startPool(this);
    }
  }