Пример #1
0
 /**
  * Check that all parameters to add the pool are presents and valid.
  *
  * @param addPoolDTO
  * @throws URISyntaxException
  */
 private void checkAddPoolParameters(AddPoolDTO addPoolDTO)
     throws BadParameterException, URISyntaxException {
   checkPoolParameters(
       addPoolDTO.getPoolHost(),
       addPoolDTO.getUsername(),
       addPoolDTO.getAppendWorkerNames(),
       addPoolDTO.getPassword(),
       addPoolDTO.getUseWorkerPassword());
 }
Пример #2
0
  /**
   * Add the pool described in the given poolDTO
   *
   * @param addPoolDTO
   * @return
   * @throws URISyntaxException
   * @throws PoolStartException
   * @throws SocketException
   */
  public Pool addPool(AddPoolDTO addPoolDTO)
      throws BadParameterException, SocketException, PoolStartException, URISyntaxException {

    LOGGER.debug("Trying to add pool {}.", addPoolDTO);

    checkAddPoolParameters(addPoolDTO);

    Pool poolToAdd =
        new Pool(
            addPoolDTO.getPoolName(),
            addPoolDTO.getPoolHost(),
            addPoolDTO.getUsername(),
            addPoolDTO.getPassword());

    // By default, does not enable extranonce subscribe.
    poolToAdd.setExtranonceSubscribeEnabled(
        addPoolDTO.getEnableExtranonceSubscribe() != null
            && addPoolDTO.getEnableExtranonceSubscribe());

    poolToAdd.setAppendWorkerNames(
        addPoolDTO.getAppendWorkerNames() != null ? addPoolDTO.getAppendWorkerNames() : false);
    poolToAdd.setWorkerSeparator(
        addPoolDTO.getWorkerNameSeparator() != null
            ? addPoolDTO.getWorkerNameSeparator()
            : Constants.DEFAULT_WORKER_NAME_SEPARTOR);
    poolToAdd.setUseWorkerPassword(
        addPoolDTO.getUseWorkerPassword() != null ? addPoolDTO.getUseWorkerPassword() : false);

    if (addPoolDTO.getPriority() != null) {
      poolToAdd.setPriority(addPoolDTO.getPriority());
    }

    if (addPoolDTO.getWeight() != null) {
      poolToAdd.setWeight(addPoolDTO.getWeight());
    }

    // Add the pool to the pool list
    pools.add(poolToAdd);

    if (addPoolDTO.getPriority() != null) {
      try {
        setPoolPriority(addPoolDTO.getPoolName(), addPoolDTO.getPriority());
      } catch (NoPoolAvailableException e) {
        LOGGER.error("BUG DETECTED !!! This exceptin should not happen.", e);
      }
    }

    LOGGER.info("Pool added {}.", addPoolDTO);

    try {
      poolToAdd.setEnabled(addPoolDTO.getIsEnabled() == null || addPoolDTO.getIsEnabled());
    } catch (Exception e) {
      throw new PoolStartException(
          "Failed to enable the created pool with name "
              + poolToAdd.getName()
              + ". This should not happen. Surely a BUUUUGGGG !!!!",
          e);
    }

    if (poolToAdd.isEnabled()) {
      poolToAdd.startPool(this);
    }

    poolSwitchingStrategyManager.onPoolAdded(poolToAdd);

    return poolToAdd;
  }