Aucune description

Server.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zhangdali
  5. * Date: 2016/12/5
  6. * Time: 下午4:36
  7. */
  8. namespace xmpush;
  9. class Server {
  10. /**
  11. * @var string
  12. */
  13. private $host;
  14. /**
  15. * @var int
  16. */
  17. private $priority;
  18. private $minPriority;
  19. private $maxPriority;
  20. private $decrStep;
  21. private $incrStep;
  22. /**
  23. * Server constructor.
  24. * @param string $host
  25. * @param int $minPriority
  26. * @param int $maxPriority
  27. * @param int $decrStep
  28. * @param int $incrStep
  29. */
  30. public function __construct($host, $minPriority, $maxPriority, $decrStep, $incrStep) {
  31. $this->host = $host;
  32. $this->priority = $maxPriority;
  33. $this->minPriority = $minPriority;
  34. $this->maxPriority = $maxPriority;
  35. $this->decrStep = $decrStep;
  36. $this->incrStep = $incrStep;
  37. }
  38. function __destruct() {
  39. }
  40. /**
  41. * @return string
  42. */
  43. public function getHost() {
  44. return $this->host;
  45. }
  46. /**
  47. * @param $host
  48. */
  49. public function setHost($host) {
  50. $this->host = $host;
  51. }
  52. /**
  53. * @return int
  54. */
  55. public function getPriority() {
  56. return $this->priority;
  57. }
  58. /**
  59. * @param int $priority
  60. */
  61. public function setPriority($priority) {
  62. $this->priority = $priority;
  63. }
  64. public function incrPriority() {
  65. $this->changePriority(true, $this->incrStep);
  66. }
  67. public function decrPriority() {
  68. $this->changePriority(false, $this->incrStep);
  69. }
  70. /**
  71. * @param bool $incr
  72. * @param int $step
  73. */
  74. private function changePriority($incr, $step) {
  75. $newPriority = $incr ? $this->priority + $step : $this->priority - $step;
  76. if ($newPriority < $this->minPriority) {
  77. $newPriority = $this->minPriority;
  78. }
  79. if ($newPriority > $this->maxPriority) {
  80. $newPriority = $this->maxPriority;
  81. }
  82. $this->priority = $newPriority;
  83. }
  84. }