PoolSelector.js 588 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * PoolSelector
  3. */
  4. var PoolSelector = module.exports = {};
  5. PoolSelector.RR = function PoolSelectorRoundRobin() {
  6. var index = 0;
  7. return function(clusterIds) {
  8. if (index >= clusterIds.length) {
  9. index = 0;
  10. }
  11. var clusterId = clusterIds[index++];
  12. return clusterId;
  13. };
  14. };
  15. PoolSelector.RANDOM = function PoolSelectorRandom() {
  16. return function(clusterIds) {
  17. return clusterIds[Math.floor(Math.random() * clusterIds.length)];
  18. };
  19. };
  20. PoolSelector.ORDER = function PoolSelectorOrder() {
  21. return function(clusterIds) {
  22. return clusterIds[0];
  23. };
  24. };