/** * get current working node, recursive, trims disconnected clients */ public static function getClient($writeMode = FALSE) { // Catch trimmed nodes or a completely trimmed pool if (empty(self::$_activeNode) || empty(self::$_socketPool[self::$_activePool])) { self::registerError('Not Connected', PandraLog::LOG_CRIT); throw new Exception('Not Connected'); } $activePool = self::$_socketPool[self::$_activePool]; $useMode = $writeMode ? self::$writeMode : self::$readMode; switch ($useMode) { case self::MODE_ROUND: if (!current(self::$_socketPool[self::$_activePool])) { reset(self::$_socketPool[self::$_activePool]); } $curConn = each(self::$_socketPool[self::$_activePool]); self::$_activeNode = $curConn['key']; // store current working node $conn = self::$_socketPool[self::$_activePool][self::$_activeNode]['client']; break; case self::MODE_RANDOM: self::$_activeNode = array_rand($activePool); $conn = self::$_socketPool[self::$_activePool][self::$_activeNode]['client']; break; case self::MODE_ACTIVE: default: // If we're trying to use an explicit connection id and it's down, then bail if (self::priorFail(self::$_activeNode)) { return NULL; } $conn = self::$_socketPool[self::$_activePool][self::$_activeNode]['client']; break; } // check connection is open try { self::$_socketPool[self::$_activePool][self::$_activeNode]['transport']->open(); return $conn; } catch (TException $te) { if (++self::$_socketPool[self::$_activePool][self::$_activeNode]['retries'] > self::$_maxRetries) { self::setLastFail(); unset(self::$_socketPool[self::$_activePool][self::$_activeNode]); } self::registerError(self::$_activePool . ':' . self::$_activeNode . ': Marked as DOWN, trying next in pool'); return self::getClient($writeMode); } }
/** * get current working node, recursive, trims disconnected clients */ public static function getClient($writeMode = FALSE) { if (empty(self::$_activeNode)) { throw new Exception('Not Connected'); } $useMode = $writeMode ? self::$writeMode : self::$readMode; switch ($useMode) { case self::MODE_ROUND: if (!current(self::$_nodeConns)) { reset(self::$_nodeConns); } $curConn = each(self::$_nodeConns); self::$_activeNode = $curConn['key']; // store current working node return self::$_nodeConns[self::$_activeNode]['client']; break; case self::MODE_RANDOM: $randConn =& array_rand(self::$_nodeConns); return self::$_nodeConns[$randConn]['client']; break; case self::MODE_ACTIVE: default: return self::$_nodeConns[self::$_activeNode]['client']; break; } }