Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1543)

Delta Between Two Patch Sets: Src/GoogleApis/Apis/Http/ExponentialBackOffInitializer.cs

Issue 13412046: Reimplement OAuth2 library - Step 1 (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Left Patch Set: minor Created 10 years, 6 months ago
Right Patch Set: minor Created 10 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 Copyright 2013 Google Inc 2 Copyright 2013 Google Inc
3 3
4 Licensed under the Apache License, Version 2.0 (the "License"); 4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License. 5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at 6 You may obtain a copy of the License at
7 7
8 http://www.apache.org/licenses/LICENSE-2.0 8 http://www.apache.org/licenses/LICENSE-2.0
9 9
10 Unless required by applicable law or agreed to in writing, software 10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS, 11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and 13 See the License for the specific language governing permissions and
14 limitations under the License. 14 limitations under the License.
15 */ 15 */
16 16
17 using System; 17 using System;
18 using System.Collections.Generic; 18 using System.Collections.Generic;
19 using System.Linq; 19 using System.Linq;
20 using System.Text; 20 using System.Text;
21 21
22 namespace Google.Apis.Http 22 namespace Google.Apis.Http
23 { 23 {
24 /// <summary>· 24 /// <summary>·
25 /// Indicates if exponential back-off is used automatically on exception in a service request and\or when 503· 25 /// Indicates if exponential back-off is used automatically on exceptions in a service requests and\or when 503·
class 2013/09/16 23:47:29 Consider: Indicates if exponential back-off is us
peleyal 2013/09/17 15:53:40 Done.
26 /// response is returned form the server. 26 /// responses is returned form the server.
27 /// </summary> 27 /// </summary>
28 [Flags] 28 [Flags]
29 public enum ExponentialBackOffPolicy 29 public enum ExponentialBackOffPolicy
30 { 30 {
31 None = 0, 31 None = 0,
32 Exception = 1, 32 Exception = 1,
33 UnsuccessfulResponse503 = 2 33 UnsuccessfulResponse503 = 2
34 } 34 }
35 35
36 /// <summary> 36 /// <summary>
37 /// An initializer which adds exponential back-off as exception handler and\ or unsuccessful response handler by 37 /// An initializer which adds exponential back-off as exception handler and\ or unsuccessful response handler by
38 /// the given <seealso cref="ExponentialBackOffPolicy"/>. 38 /// the given <seealso cref="ExponentialBackOffPolicy"/>.
39 /// </summary> 39 /// </summary>
40 public class ExponentialBackOffInitializer : IConfigurableHttpClientInitiali zer 40 public class ExponentialBackOffInitializer : IConfigurableHttpClientInitiali zer
41 { 41 {
42 /// <summary>Gets or sets the used back-off policy.</summary>
42 private ExponentialBackOffPolicy Policy { get; set; } 43 private ExponentialBackOffPolicy Policy { get; set; }
class 2013/09/16 23:47:29 Missing <summary>
peleyal 2013/09/17 15:53:40 Done.
44
45 /// <summary>Gets or sets the back-off handler creation function.</summa ry>
43 private Func<BackOffHandler> CreateBackOff { get; set; } 46 private Func<BackOffHandler> CreateBackOff { get; set; }
44 47
45 /// <summary> 48 /// <summary>
46 /// Constructs a new back-off initializer with the given policy and back -off handler create function. 49 /// Constructs a new back-off initializer with the given policy and back -off handler create function.
47 /// </summary> 50 /// </summary>
48 public ExponentialBackOffInitializer(ExponentialBackOffPolicy policy, Fu nc<BackOffHandler> createBackOff) 51 public ExponentialBackOffInitializer(ExponentialBackOffPolicy policy, Fu nc<BackOffHandler> createBackOff)
49 { 52 {
50 Policy = policy; 53 Policy = policy;
51 CreateBackOff = createBackOff; 54 CreateBackOff = createBackOff;
52 } 55 }
53 56
54 public void Initialize(ConfigurableHttpClient httpClient) 57 public void Initialize(ConfigurableHttpClient httpClient)
55 { 58 {
56 var backOff = CreateBackOff(); 59 var backOff = CreateBackOff();
57 60
58 // add exception handler and\or unsuccessful response handler 61 // Add exception handler and\or unsuccessful response handler.
59 if ((Policy & ExponentialBackOffPolicy.Exception) == ExponentialBack OffPolicy.Exception) 62 if ((Policy & ExponentialBackOffPolicy.Exception) == ExponentialBack OffPolicy.Exception)
60 { 63 {
61 httpClient.MessageHandler.ExceptionHandlers.Add(backOff); 64 httpClient.MessageHandler.ExceptionHandlers.Add(backOff);
62 } 65 }
63 66
64 if ((Policy & ExponentialBackOffPolicy.UnsuccessfulResponse503) == 67 if ((Policy & ExponentialBackOffPolicy.UnsuccessfulResponse503) ==
65 ExponentialBackOffPolicy.UnsuccessfulResponse503) 68 ExponentialBackOffPolicy.UnsuccessfulResponse503)
66 { 69 {
67 httpClient.MessageHandler.UnsuccessfulResponseHandlers.Add(backO ff); 70 httpClient.MessageHandler.UnsuccessfulResponseHandlers.Add(backO ff);
68 } 71 }
69 } 72 }
70 } 73 }
71 74
72 } 75 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b