public function getConnection($type = \Octris\Db::DB_MASTER)
    {
        if ($type != \Octris\Db::DB_MASTER && $type != \Octris\Db::DB_SLAVE) {
            throw new \Exception('unknown connection type "' . $type . '"');
        } else {
            if (!($cn = array_shift($this->pool[$type]))) {
                // no more connections in the pool, create new one
                if (count($this->hosts[$type]) == 0) {
                    throw new \Exception(sprintf('No database configuration available for connection to a "%s" host.', $type));
                }

                shuffle($this->hosts[$type]);

                $cn = $this->createConnection($this->hosts[$type][0]);

                if (!($cn instanceof \Octris\Db\Device\ConnectionInterface)) {
                    throw new \Exception('connection handler needs to implement interface "\Octris\Db\Device\ConnectionInterface"');
                }
            }

            $this->connections[spl_object_hash($cn)] = $type;
        }

        return $cn;
    }