| | 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; |
| | 7 | | using System.Threading.Tasks; |
| | 8 | | using Microsoft.Azure.Storage.Blob; |
| | 9 | | using Newtonsoft.Json; |
| | 10 | |
|
| | 11 | | class AzureBlobLease : Lease |
| | 12 | | { |
| | 13 | | readonly bool isOwned; |
| | 14 | |
|
| | 15 | | // ctor needed for deserialization |
| 0 | 16 | | internal AzureBlobLease() |
| | 17 | | { |
| 0 | 18 | | } |
| | 19 | |
|
| 0 | 20 | | internal AzureBlobLease(string partitionId, CloudBlockBlob blob) : base(partitionId) |
| | 21 | | { |
| 0 | 22 | | this.Blob = blob; |
| 0 | 23 | | this.isOwned = blob.Properties.LeaseState == LeaseState.Leased; |
| 0 | 24 | | } |
| | 25 | |
|
| 0 | 26 | | internal AzureBlobLease(string partitionId, string owner, CloudBlockBlob blob) : base(partitionId) |
| | 27 | | { |
| 0 | 28 | | this.Blob = blob; |
| 0 | 29 | | this.Owner = owner; |
| 0 | 30 | | this.isOwned = blob.Properties.LeaseState == LeaseState.Leased; |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | internal AzureBlobLease(AzureBlobLease source) |
| 0 | 34 | | : base(source) |
| | 35 | | { |
| 0 | 36 | | this.Offset = source.Offset; |
| 0 | 37 | | this.SequenceNumber = source.SequenceNumber; |
| 0 | 38 | | this.Blob = source.Blob; |
| 0 | 39 | | this.isOwned = source.isOwned; |
| 0 | 40 | | } |
| | 41 | |
|
| 0 | 42 | | internal AzureBlobLease(AzureBlobLease source, CloudBlockBlob blob) : base(source) |
| | 43 | | { |
| 0 | 44 | | this.Offset = source.Offset; |
| 0 | 45 | | this.SequenceNumber = source.SequenceNumber; |
| 0 | 46 | | this.Blob = blob; |
| 0 | 47 | | this.isOwned = blob.Properties.LeaseState == LeaseState.Leased; |
| 0 | 48 | | } |
| | 49 | |
|
| | 50 | | // do not serialize |
| | 51 | | [JsonIgnore] |
| 0 | 52 | | public CloudBlockBlob Blob { get; } |
| | 53 | |
|
| | 54 | | public override Task<bool> IsExpired() |
| | 55 | | { |
| 0 | 56 | | return Task.FromResult(!this.isOwned); |
| | 57 | | } |
| | 58 | | } |
| | 59 | | } |