| | | 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 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Options to control various aspects of partition distribution happening within <see cref="EventProcessorHost"/> i |
| | | 10 | | /// </summary> |
| | | 11 | | public class PartitionManagerOptions |
| | | 12 | | { |
| | | 13 | | const int MinLeaseDurationInSeconds = 15; |
| | | 14 | | const int MaxLeaseDurationInSeconds = 60; |
| | | 15 | | |
| | 0 | 16 | | TimeSpan renewInterval = TimeSpan.FromSeconds(10); |
| | 0 | 17 | | TimeSpan leaseDuration = TimeSpan.FromSeconds(30); |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Renew interval for all leases for partitions currently held by <see cref="EventProcessorHost"/> instance. |
| | | 21 | | /// </summary> |
| | | 22 | | public TimeSpan RenewInterval |
| | | 23 | | { |
| | | 24 | | get |
| | | 25 | | { |
| | 0 | 26 | | return this.renewInterval; |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | set |
| | | 30 | | { |
| | 0 | 31 | | if (value >= this.leaseDuration) |
| | | 32 | | { |
| | 0 | 33 | | throw new ArgumentException("Renew interval needs to be smaller than the lease duration."); |
| | | 34 | | } |
| | | 35 | | |
| | 0 | 36 | | this.renewInterval = value; |
| | 0 | 37 | | } |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Interval for which the lease is taken on Azure Blob representing an EventHub partition. If the lease is not |
| | | 42 | | /// interval, it will cause it to expire and ownership of the partition will move to another <see cref="EventPro |
| | | 43 | | /// </summary> |
| | | 44 | | public TimeSpan LeaseDuration |
| | | 45 | | { |
| | | 46 | | get |
| | | 47 | | { |
| | 0 | 48 | | return this.leaseDuration; |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | set |
| | | 52 | | { |
| | 0 | 53 | | if (value <= this.renewInterval) |
| | | 54 | | { |
| | 0 | 55 | | throw new ArgumentException("Lease duration needs to be greater than the renew interval."); |
| | | 56 | | } |
| | | 57 | | |
| | 0 | 58 | | if (value.TotalSeconds < MinLeaseDurationInSeconds || value.TotalSeconds > MaxLeaseDurationInSeconds) |
| | | 59 | | { |
| | 0 | 60 | | throw new ArgumentException($"Lease duration needs to be between {MinLeaseDurationInSeconds} seconds |
| | | 61 | | } |
| | | 62 | | |
| | 0 | 63 | | this.leaseDuration = value; |
| | 0 | 64 | | } |
| | | 65 | | } |
| | | 66 | | } |
| | | 67 | | } |