public function getConnection($url = null, $cb = null, $pri = 0)
    {
        if (!is_string($url) && $url !== null && $cb === null) { // if called getConnection(function....)
            $cb = $url;
            $url = null;
        }
        if ($url === null) {
            if (isset($this->config->server->value)) {
                $url = $this->config->server->value;
            } elseif (isset($this->servers) && sizeof($this->servers)) {
                $url = array_rand($this->servers);
            } else {
                if ($cb) {
                    $cb(false);
                }
                return false;
            }
        }

        start:
        $conn = false;
        if (isset($this->servConn[$url])) {
            $storage = $this->servConn[$url];
            $free = $this->servConnFree[$url];
            if ($free->count() > 0) {
                $conn = $free->getFirst();
                if (!$conn->isConnected() || $conn->isFinished()) {
                    $free->detach($conn);
                    goto start;
                }
                if ($this->acquireOnGet) {
                    $free->detach($conn);
                }
            } elseif ($storage->count() >= $this->maxConnPerServ) {
                if (!isset($this->pending[$url])) {
                    $this->pending[$url] = new PriorityQueueCallbacks;
                }
                $this->pending[$url]->enqueue($cb, $pri);
                return true;
            }
            if ($conn) {
                if ($cb !== null) {
                    $conn->onConnected($cb);
                }
                return true;
            }
        } else {
            $this->servConn[$url] = new ObjectStorage;
            $this->servConnFree[$url] = new ObjectStorage;
        }
        //Daemon::log($url . "\n" . Debug::dump($this->finished) . "\n" . Debug::backtrace(true));
        $conn = $this->connect($url, $cb);

        if (!$conn || $conn->isFinished()) {
            return false;
        }
        $this->servConn[$url]->attach($conn);
        return true;
    }