| | 1 | | // Copyright (c) Microsoft. All rights reserved. |
| | 2 | | // Licensed under the MIT license. See LICENSE file in the project root for full license information.using System; |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.EventHubs.ServiceFabricProcessor |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | | using System.Collections.Generic; |
| | 8 | | using System.Threading; |
| | 9 | | using System.Threading.Tasks; |
| | 10 | |
|
| | 11 | | /// <summary> |
| | 12 | | /// Interface for processing events. |
| | 13 | | /// </summary> |
| | 14 | | public abstract class IEventProcessor |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Called on startup. |
| | 18 | | /// </summary> |
| | 19 | | /// <param name="cancellationToken"></param> |
| | 20 | | /// <param name="context"></param> |
| | 21 | | /// <returns></returns> |
| | 22 | | abstract public Task OpenAsync(CancellationToken cancellationToken, PartitionContext context); |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Called on shutdown. |
| | 26 | | /// </summary> |
| | 27 | | /// <param name="context"></param> |
| | 28 | | /// <param name="reason"></param> |
| | 29 | | /// <returns></returns> |
| | 30 | | abstract public Task CloseAsync(PartitionContext context, CloseReason reason); |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Called when events are available. |
| | 34 | | /// </summary> |
| | 35 | | /// <param name="cancellationToken"></param> |
| | 36 | | /// <param name="context"></param> |
| | 37 | | /// <param name="events"></param> |
| | 38 | | /// <returns></returns> |
| | 39 | | abstract public Task ProcessEventsAsync(CancellationToken cancellationToken, PartitionContext context, IEnumerab |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// Called when an error occurs. |
| | 43 | | /// </summary> |
| | 44 | | /// <param name="context"></param> |
| | 45 | | /// <param name="error"></param> |
| | 46 | | /// <returns></returns> |
| | 47 | | abstract public Task ProcessErrorAsync(PartitionContext context, Exception error); |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Called periodically to get user-supplied load metrics. |
| | 51 | | /// </summary> |
| | 52 | | /// <param name="cancellationToken"></param> |
| | 53 | | /// <param name="context"></param> |
| | 54 | | /// <returns></returns> |
| | 55 | | virtual public Dictionary<string, int> GetLoadMetric(CancellationToken cancellationToken, PartitionContext conte |
| | 56 | | { |
| | 57 | | // By default all partitions have a metric of named CountOfPartitions with value 1. If Service Fabric is con |
| | 58 | | // it will balance primaries across nodes simply by the number of primaries on a node. This can be overridde |
| | 59 | | // more sophisticated metrics like number of events processed or CPU usage. |
| 8 | 60 | | Dictionary<string, int> defaultMetric = new Dictionary<string, int>(); |
| 8 | 61 | | defaultMetric.Add(Constants.DefaultUserLoadMetricName, 1); |
| 8 | 62 | | return defaultMetric; |
| | 63 | | } |
| | 64 | | } |
| | 65 | | } |