1 | <?php |
||
29 | class ZooKeeperConfig implements ConfigInterface, LoggerAwareInterface |
||
30 | { |
||
31 | /** |
||
32 | * Parent path. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | private $parentPath; |
||
37 | |||
38 | /** |
||
39 | * ZK. |
||
40 | * |
||
41 | * @var \Zookeeper |
||
42 | */ |
||
43 | private $zk; |
||
44 | |||
45 | /** |
||
46 | * Process ID for a multi-process-single-machine setup. |
||
47 | * |
||
48 | * @var integer |
||
49 | */ |
||
50 | private $procesId = 1; |
||
51 | |||
52 | /** |
||
53 | * Logger. |
||
54 | * |
||
55 | * @var LoggerInterface |
||
56 | */ |
||
57 | private $logger; |
||
58 | |||
59 | /** |
||
60 | * Constructor. |
||
61 | * |
||
62 | * @param string $hostnames A comma separated list of hostnames (including |
||
63 | * port) |
||
64 | * @param integer $processId If you want to run multiple server processes on a single machine, |
||
65 | * you have to provide each one an unique ID, |
||
66 | * so the zookeeper knows, which machine ID belongs to which process. |
||
67 | * @param string $zkPath The ZK path we look to find other machines under |
||
68 | * @param LoggerInterface $logger Logger class |
||
69 | */ |
||
70 | public function __construct($hostnames, $processId = 1, $zkPath = '/cruftflake', LoggerInterface $logger = null) |
||
87 | |||
88 | /** |
||
89 | * Get machine identifier. |
||
90 | * |
||
91 | * @return int Should be a 10-bit int (decimal 0 to 1023) |
||
92 | * @throws RuntimeException Thrown, when obtaining machine ID has failed. |
||
93 | */ |
||
94 | public function getMachine() |
||
125 | |||
126 | /** |
||
127 | * Compare found machine information with expected values. |
||
128 | * |
||
129 | * @param array $found |
||
130 | * @param array $expected |
||
131 | * @return boolean |
||
132 | */ |
||
133 | private function compareMachineInfo(array $found, array $expected) |
||
140 | |||
141 | /** |
||
142 | * Attempt to claim and create new machine ID in Zookeeper. |
||
143 | * |
||
144 | * @param array $children |
||
145 | * @param array $machineInfo |
||
146 | * @return integer Machine ID. |
||
147 | * @throws RuntimeException Thrown, when creation of machine ID has failed. |
||
148 | */ |
||
149 | private function createMachineInfo(array $children, array $machineInfo) |
||
176 | |||
177 | /** |
||
178 | * Get mac address and hostname. |
||
179 | * |
||
180 | * @return array "macAddress", "hostname" keys |
||
181 | */ |
||
182 | private function getMachineInfo() |
||
212 | |||
213 | /** |
||
214 | * Create parent node, if needed. |
||
215 | * |
||
216 | * @param string $nodePath |
||
217 | */ |
||
218 | private function createParentIfNeeded($nodePath) |
||
231 | |||
232 | /** |
||
233 | * Machine ID to ZK node. |
||
234 | * |
||
235 | * @param int $id |
||
236 | * |
||
237 | * @return string The node path to use in ZK |
||
238 | */ |
||
239 | private function machineToNode($id) |
||
243 | |||
244 | /** |
||
245 | * Set logger. |
||
246 | * |
||
247 | * @param LoggerInterface $logger |
||
248 | */ |
||
249 | public function setLogger(LoggerInterface $logger) |
||
253 | } |
||
254 |