/** Start all pools. */ public void startPools(List<Pool> pools) { this.pools = Collections.synchronizedList(new ArrayList<Pool>(pools)); synchronized (pools) { for (Pool pool : pools) { try { if (pool.isEnabled()) { pool.startPool(this); } else { LOGGER.warn("Do not start pool {} since it is disabled.", pool.getName()); } } catch (Exception e) { LOGGER.error("Failed to start the pool {}.", pool, e); } } } }
/** * 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; }
/** * @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); } }