-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
WorkerWeightedAllocation.cs
44 lines (40 loc) · 1.58 KB
/
WorkerWeightedAllocation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
using System;
using System.Linq;
using System.Text.Json;
using Azure.Core;
namespace Azure.Communication.JobRouter
{
public partial class WorkerWeightedAllocation : IUtf8JsonSerializable
{
/// <summary> Initializes a new instance of WorkerWeightedAllocation. </summary>
/// <param name="weight"> The percentage of this weight, expressed as a fraction of 1. </param>
/// <param name="workerSelectors">
/// A collection of worker selectors that will be applied if this allocation is
/// selected.
/// </param>
/// <exception cref="ArgumentNullException"> <paramref name="workerSelectors"/> is null. </exception>
public WorkerWeightedAllocation(double weight, IEnumerable<RouterWorkerSelector> workerSelectors)
{
Argument.AssertNotNull(workerSelectors, nameof(workerSelectors));
Weight = weight;
WorkerSelectors = workerSelectors.ToList();
}
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("weight"u8);
writer.WriteNumberValue(Weight);
writer.WritePropertyName("workerSelectors"u8);
writer.WriteStartArray();
foreach (var item in WorkerSelectors)
{
writer.WriteObjectValue(item);
}
writer.WriteEndArray();
writer.WriteEndObject();
}
}
}