public function lock($timeout = 0, $interval = 50000)
    {
        if ((!is_numeric($timeout)) || ($timeout < 0))
        {
            throw new \Exception("Lock timeout should be an integer greater or equals to 0.");
        }

        if ((!is_numeric($interval)) || ($interval < 5000))
        {
            throw new \Exception("Lock check interval should be an integer greater or equals to 5000.");
        }

        $this->storage->openWriter();

        $object = $this->getObjectSafely('openWriter');
        $object->setLocked(true);
        $object->setTimeout($timeout);
        $object->setInterval($interval);

        $this->lock = true;
        $this->storage->setObject($object);
        $this->storage->close();
    }