Skip to content

Commit

Permalink
Add support for file lease
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinming-Hu authored and vinjiang committed Mar 4, 2020
1 parent bef3af8 commit 3c895d6
Show file tree
Hide file tree
Showing 9 changed files with 946 additions and 329 deletions.
230 changes: 0 additions & 230 deletions Microsoft.WindowsAzure.Storage/includes/was/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -830,236 +830,6 @@ namespace azure { namespace storage {
int64_t m_append_position;
};

/// <summary>
/// The lease state of a resource.
/// </summary>
enum class lease_state
{
/// <summary>
/// The lease state is not specified.
/// </summary>
unspecified,

/// <summary>
/// The lease is in the Available state.
/// </summary>
available,

/// <summary>
/// The lease is in the Leased state.
/// </summary>
leased,

/// <summary>
/// The lease is in the Expired state.
/// </summary>
expired,

/// <summary>
/// The lease is in the Breaking state.
/// </summary>
breaking,

/// <summary>
/// The lease is in the Broken state.
/// </summary>
broken,
};

/// <summary>
/// The lease status of a resource.
/// </summary>
enum class lease_status
{
/// <summary>
/// The lease status is not specified.
/// </summary>
unspecified,

/// <summary>
/// The resource is locked.
/// </summary>
locked,

/// <summary>
/// The resource is available to be locked.
/// </summary>
unlocked
};

/// <summary>
/// Specifies the proposed duration of seconds that the lease should continue before it is broken.
/// </summary>
class lease_break_period
{
public:
/// <summary>
/// Initializes a new instance of the <see cref="azure::storage::lease_break_period" /> class that breaks
/// a fixed-duration lease after the remaining lease period elapses, or breaks an infinite lease immediately.
/// </summary>
lease_break_period()
: m_seconds(std::chrono::seconds::max())
{
}

/// <summary>
/// Initializes a new instance of the <see cref="azure::storage::lease_break_period" /> class that breaks
/// a lease after the proposed duration.
/// </summary>
/// <param name="seconds">The proposed duration, in seconds, for the lease before it is broken. Value may
/// be between 0 and 60 seconds.</param>
lease_break_period(const std::chrono::seconds& seconds)
: m_seconds(seconds)
{
if (seconds != std::chrono::seconds::max())
{
utility::assert_in_bounds(_XPLATSTR("seconds"), seconds, protocol::minimum_lease_break_period, protocol::maximum_lease_break_period);
}
}

#if defined(_MSC_VER) && _MSC_VER < 1900
// Compilers that fully support C++ 11 rvalue reference, e.g. g++ 4.8+, clang++ 3.3+ and Visual Studio 2015+,
// have implicitly-declared move constructor and move assignment operator.

/// <summary>
/// Initializes a new instance of the <see cref="azure::storage::lease_break_period" /> class based on an existing instance.
/// </summary>
/// <param name="other">An existing <see cref="azure::storage::lease_break_period" /> object.</param>
lease_break_period(lease_break_period&& other)
{
*this = std::move(other);
}

/// <summary>
/// Returns a reference to an <see cref="azure::storage::lease_break_period" /> object.
/// </summary>
/// <param name="other">An existing <see cref="azure::storage::lease_break_period" /> object to use to set properties.</param>
/// <returns>An <see cref="azure::storage::lease_break_period" /> object with properties set.</returns>
lease_break_period& operator=(lease_break_period&& other)
{
if (this != &other)
{
m_seconds = std::move(other.m_seconds);
}
return *this;
}
#endif

/// <summary>
/// Indicates whether the <see cref="azure::storage::lease_break_period" /> object is valid.
/// </summary>
/// <returns><c>true</c> if the <see cref="azure::storage::lease_break_period" /> object is valid; otherwise, <c>false</c>.</returns>
bool is_valid() const
{
return m_seconds < std::chrono::seconds::max();
}

/// <summary>
/// Gets the proposed duration for the lease before it is broken.
/// </summary>
/// <returns>The proposed proposed duration for the lease before it is broken, in seconds.</returns>
const std::chrono::seconds& seconds() const
{
return m_seconds;
}

private:

std::chrono::seconds m_seconds;
};

/// <summary>
/// The lease duration for a Blob service resource.
/// </summary>
enum class lease_duration
{
/// <summary>
/// The lease duration is not specified.
/// </summary>
unspecified,

/// <summary>
/// The lease duration is finite.
/// </summary>
fixed,

/// <summary>
/// The lease duration is infinite.
/// </summary>
infinite,
};

/// <summary>
/// Specifies the duration of the lease.
/// </summary>
class lease_time
{
public:
/// <summary>
/// Initializes a new instance of the <see cref="azure::storage::lease_time" /> class that never expires.
/// </summary>
lease_time()
: m_seconds(-1)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="azure::storage::lease_time" /> class that expires after the
/// specified duration.
/// </summary>
/// <param name="seconds">The duration of the lease in seconds. For a non-infinite lease, this value can be
/// between 15 and 60 seconds.</param>
lease_time(const std::chrono::seconds& seconds)
: m_seconds(seconds)
{
if (seconds.count() != -1)
{
utility::assert_in_bounds(_XPLATSTR("seconds"), seconds, protocol::minimum_fixed_lease_duration, protocol::maximum_fixed_lease_duration);
}
}

#if defined(_MSC_VER) && _MSC_VER < 1900
// Compilers that fully support C++ 11 rvalue reference, e.g. g++ 4.8+, clang++ 3.3+ and Visual Studio 2015+,
// have implicitly-declared move constructor and move assignment operator.

/// <summary>
/// Initializes a new instance of the <see cref="azure::storage::lease_time" /> class based on an existing instance.
/// </summary>
/// <param name="other">An existing <see cref="azure::storage::lease_time" /> object.</param>
lease_time(lease_time&& other)
{
*this = std::move(other);
}

/// <summary>
/// Returns a reference to an <see cref="azure::storage::lease_time" /> object.
/// </summary>
/// <param name="other">An existing <see cref="azure::storage::lease_time" /> object to use to set properties.</param>
/// <returns>An <see cref="azure::storage::lease_time" /> object with properties set.</returns>
lease_time& operator=(lease_time&& other)
{
if (this != &other)
{
m_seconds = std::move(other.m_seconds);
}
return *this;
}
#endif

/// <summary>
/// Gets the duration of the lease in seconds for a non-infinite lease.
/// </summary>
/// <returns>The duration of the lease.</returns>
const std::chrono::seconds& seconds() const
{
return m_seconds;
}

private:

std::chrono::seconds m_seconds;
};

/// <summary>
/// The tier of the block blob on a standard storage account.
/// </summary>
Expand Down
Loading

0 comments on commit 3c895d6

Please sign in to comment.