| | | 1 | | // Copyright (c) Microsoft. All rights reserved. |
| | | 2 | | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| | | 3 | | |
| | | 4 | | namespace Microsoft.Azure.EventHubs.Processor |
| | | 5 | | { |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Contains partition ownership information. |
| | | 10 | | /// </summary> |
| | | 11 | | public class Lease |
| | | 12 | | { |
| | | 13 | | /// <summary></summary> |
| | 0 | 14 | | protected Lease() |
| | | 15 | | { |
| | 0 | 16 | | } |
| | | 17 | | |
| | | 18 | | /// <summary></summary> |
| | | 19 | | /// <param name="partitionId"></param> |
| | 0 | 20 | | protected Lease(string partitionId) |
| | | 21 | | { |
| | 0 | 22 | | this.PartitionId = partitionId; |
| | 0 | 23 | | this.Owner = string.Empty; |
| | 0 | 24 | | this.Token = string.Empty; |
| | 0 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary></summary> |
| | | 28 | | /// <param name="source"></param> |
| | 0 | 29 | | protected Lease(Lease source) |
| | | 30 | | { |
| | 0 | 31 | | this.PartitionId = source.PartitionId; |
| | 0 | 32 | | this.Epoch = source.Epoch; |
| | 0 | 33 | | this.Owner = source.Owner; |
| | 0 | 34 | | this.Token = source.Token; |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Gets or sets the current value for the offset in the stream. |
| | | 39 | | /// </summary> |
| | 0 | 40 | | public string Offset { get; set; } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Gets or sets the last checkpointed sequence number in the stream. |
| | | 44 | | /// </summary> |
| | 0 | 45 | | public long SequenceNumber { get; set; } |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// Gets the ID of the partition to which this lease belongs. |
| | | 49 | | /// </summary> |
| | 0 | 50 | | public string PartitionId { get; set; } |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// Gets or sets the host owner for the partition. |
| | | 54 | | /// </summary> |
| | 0 | 55 | | public string Owner { get; set; } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Gets or sets the lease token that manages concurrency between hosts. You can use this token to guarantee sin |
| | | 59 | | /// </summary> |
| | 0 | 60 | | public string Token { get; set; } |
| | | 61 | | |
| | | 62 | | /// <summary> |
| | | 63 | | /// Gets or sets the epoch year of the lease, which is a value you can use to determine the most recent owner of |
| | | 64 | | /// </summary> |
| | 0 | 65 | | public long Epoch { get; set; } |
| | | 66 | | |
| | | 67 | | /// <summary> |
| | | 68 | | /// Determines whether the lease is expired. |
| | | 69 | | /// </summary> |
| | | 70 | | /// <returns></returns> |
| | | 71 | | public virtual Task<bool> IsExpired() |
| | | 72 | | { |
| | | 73 | | // By default lease never expires. |
| | | 74 | | // Deriving class will implement the lease expiry logic. |
| | 0 | 75 | | return Task.FromResult(false); |
| | | 76 | | } |
| | | 77 | | |
| | | 78 | | /// <summary> |
| | | 79 | | /// Increments the stored epoch in the checkpoint. |
| | | 80 | | /// </summary> |
| | | 81 | | /// <returns></returns> |
| | | 82 | | public long IncrementEpoch() |
| | | 83 | | { |
| | 0 | 84 | | this.Epoch++; |
| | 0 | 85 | | return this.Epoch; |
| | | 86 | | } |
| | | 87 | | } |
| | | 88 | | } |