private void Lock()
        {
            using (var session = _storage.Repository.OpenSession()) {
                _distributedLock = new DistributedLock() {
                    ClientId = _storage.Options.ClientId,
                    Resource = _resource
                };

                session.Store(_distributedLock);
                session.Advanced.AddExpire(_distributedLock, DateTime.UtcNow + _timeout);

                try {
                    // Blocking session!
                    session.Advanced.UseOptimisticConcurrency = true;
                    session.SaveChanges();
                } catch (Exception e) {
                    _distributedLock = null;
                    throw new RavenDistributedLockException("Lock already given.", e);
                }
            }

            Heartbeat();
        }
        private void Release()
        {
            lock (_lock) {
                if (_distributedLock != null) {
                    // Non blocking session!
                    try {
                        using (var session = _storage.Repository.OpenSession()) {
                            session.Delete(_distributedLock.Id);
                            session.SaveChanges();
                        }
                    } catch {
                        Console.WriteLine("Unable to delete lock: {0}", _resource);
                    }

                    _distributedLock = null;
                }

                // Stop timer
                if (_heartbeatTimer != null) {
                    _heartbeatTimer.Dispose();
                    _heartbeatTimer = null;
                }
            }
        }