/** * Compute the and set the current pool. Based on the pool priority and pool state. * * @param connection * @return */ @Override protected void computeCurrentPool() throws NoPoolAvailableException { List<Pool> pools = getProxyManager().getPools(); Pool newPool = null; checkPoolPriorities(pools); Collections.sort( pools, new Comparator<Pool>() { public int compare(Pool o1, Pool o2) { return o1.getPriority().compareTo(o2.getPriority()); } }); for (Pool pool : pools) { if (pool.isReady() && pool.isEnabled() && pool.isStable()) { newPool = pool; break; } } if (newPool == null) { throw new NoPoolAvailableException("No pool available. " + pools); } else { setCurrentPool(newPool); } }
/** * Disable/Enable the pool with the given name * * @param poolName * @param isEnabled * @throws NoPoolAvailableException */ public void setPoolEnabled(String poolName, boolean isEnabled) throws NoPoolAvailableException, Exception { Pool pool = getPool(poolName); if (pool == null) { throw new NoPoolAvailableException("Pool with name " + poolName + " is not found"); } if (pool.isEnabled() != isEnabled) { LOGGER.info("Set pool {} {}", pool.getName(), isEnabled ? "enabled" : "disabled"); pool.setEnabled(isEnabled, this); } }
/** 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; }