-
Notifications
You must be signed in to change notification settings - Fork 164
/
OperationContext.java
726 lines (648 loc) · 29.2 KB
/
OperationContext.java
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
/**
* Copyright Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.microsoft.azure.storage;
import java.net.Proxy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;
import org.slf4j.Logger;
/**
* Represents the current logical operation. A logical operation may have a one-to-many relationship with
* multiple individual physical requests.
*/
public final class OperationContext {
/**
* Name of the {@link org.slf4j.Logger} that will be created by default if logging is enabled and a
* {@link org.slf4j.Logger} has not been specified.
*/
public static final String defaultLoggerName = Logger.ROOT_LOGGER_NAME;
/**
* Indicates whether the client library should produce log entries by default. The default can be overridden to
* enable logging for an individual operation context instance by using {@link #setLoggingEnabled}.
*/
private static boolean enableLoggingByDefault = false;
/**
* Indicates whether the client library should use a proxy by default. The default can be overridden to
* enable proxy for an individual operation context instance by using {@link #setProxy}.
*/
private static Proxy proxyDefault;
/**
* Represents a username to be used by default for a proxy when making a request.
*/
private static String proxyDefaultUsername = null;
/**
* Represents a password to be used by default for a proxy when making a request.
*/
private static String proxyDefaultPassword = null;
/**
* Represents a proxy to be used when making a request.
*/
private Proxy proxy;
/**
* Represents a username for a proxy when making a request.
*/
private String proxyUsername = null;
/**
* Represents a password for a proxy when making a request.
*/
private String proxyPassword = null;
/**
* Represents the operation latency, in milliseconds, from the client's perspective. This may include any potential
* retries.
*/
private long clientTimeInMs;
/**
* The UUID representing the client side trace ID.
*/
private String clientRequestID;
/**
* Indicates whether to enable logging for a given operation context.
*/
private Boolean enableLogging;
/**
* The {@link org.slf4j.Logger} object associated with this operation.
*/
private org.slf4j.Logger logger;
/**
* Represents request results, in the form of an <code>ArrayList</code> object that contains the
* {@link RequestResult} objects, for each physical request that is made.
*/
private final ArrayList<RequestResult> requestResults;
/**
* Represents additional headers on the request, for example, for proxy or logging information.
*/
private HashMap<String, String> userHeaders;
/**
* Represents an event that is triggered before sending a
* request.
*
* @see StorageEvent
* @see StorageEventMultiCaster
* @see SendingRequestEvent
*/
private static StorageEventMultiCaster<SendingRequestEvent, StorageEvent<SendingRequestEvent>> globalSendingRequestEventHandler = new StorageEventMultiCaster<SendingRequestEvent, StorageEvent<SendingRequestEvent>>();
/**
* Represents an event that is triggered when a response is received from the storage service while processing a request
*
* @see StorageEvent
* @see StorageEventMultiCaster
* @see ResponseReceivedEvent
*/
private static StorageEventMultiCaster<ResponseReceivedEvent, StorageEvent<ResponseReceivedEvent>> globalResponseReceivedEventHandler = new StorageEventMultiCaster<ResponseReceivedEvent, StorageEvent<ResponseReceivedEvent>>();
/**
* Represents an event that is triggered when a network error occurs before the HTTP response status and headers are received.
*
* @see StorageEvent
* @see StorageEventMultiCaster
* @see ErrorReceivingResponseEvent
*/
private static StorageEventMultiCaster<ErrorReceivingResponseEvent, StorageEvent<ErrorReceivingResponseEvent>> globalErrorReceivingResponseEventHandler = new StorageEventMultiCaster<ErrorReceivingResponseEvent, StorageEvent<ErrorReceivingResponseEvent>>();
/**
* Represents an event that is triggered when a response received from the service is fully processed.
*
* @see StorageEvent
* @see StorageEventMultiCaster
* @see RequestCompletedEvent
*/
private static StorageEventMultiCaster<RequestCompletedEvent, StorageEvent<RequestCompletedEvent>> globalRequestCompletedEventHandler = new StorageEventMultiCaster<RequestCompletedEvent, StorageEvent<RequestCompletedEvent>>();
/**
* Represents an event that is triggered when a request is retried.
*
* @see StorageEvent
* @see StorageEventMultiCaster
* @see RetryingEvent
*/
private static StorageEventMultiCaster<RetryingEvent, StorageEvent<RetryingEvent>> globalRetryingEventHandler = new StorageEventMultiCaster<RetryingEvent, StorageEvent<RetryingEvent>>();
/**
* Represents an event that is triggered before sending a request.
*
* @see StorageEvent
* @see StorageEventMultiCaster
* @see SendingRequestEvent
*/
private StorageEventMultiCaster<SendingRequestEvent, StorageEvent<SendingRequestEvent>> sendingRequestEventHandler = new StorageEventMultiCaster<SendingRequestEvent, StorageEvent<SendingRequestEvent>>();
/**
* Represents an event that is triggered when a response is received from the storage service while processing a
* request.
*
* @see StorageEvent
* @see StorageEventMultiCaster
* @see ResponseReceivedEvent
*/
private StorageEventMultiCaster<ResponseReceivedEvent, StorageEvent<ResponseReceivedEvent>> responseReceivedEventHandler = new StorageEventMultiCaster<ResponseReceivedEvent, StorageEvent<ResponseReceivedEvent>>();
/**
* Represents an event that is triggered when a network error occurs before the HTTP response status and headers are received.
*
* @see StorageEvent
* @see StorageEventMultiCaster
* @see ErrorReceivingResponseEvent
*/
private StorageEventMultiCaster<ErrorReceivingResponseEvent, StorageEvent<ErrorReceivingResponseEvent>> errorReceivingResponseEventHandler = new StorageEventMultiCaster<ErrorReceivingResponseEvent, StorageEvent<ErrorReceivingResponseEvent>>();
/**
* Represents an event that is triggered when a response received from the service is fully processed.
*
* @see StorageEvent
* @see StorageEventMultiCaster
* @see RequestCompletedEvent
*/
private StorageEventMultiCaster<RequestCompletedEvent, StorageEvent<RequestCompletedEvent>> requestCompletedEventHandler = new StorageEventMultiCaster<RequestCompletedEvent, StorageEvent<RequestCompletedEvent>>();
/**
* Represents an event that is triggered when a response is received from the storage service while processing a
* request.
*
* @see StorageEvent
* @see StorageEventMultiCaster
* @see RetryingEvent
*/
private StorageEventMultiCaster<RetryingEvent, StorageEvent<RetryingEvent>> retryingEventHandler = new StorageEventMultiCaster<RetryingEvent, StorageEvent<RetryingEvent>>();
/**
* Creates an instance of the <code>OperationContext</code> class.
*/
public OperationContext() {
this.clientRequestID = UUID.randomUUID().toString();
this.requestResults = new ArrayList<RequestResult>();
}
/**
* Gets the client side trace ID.
*
* @return A <code>String</code> which represents the client request ID.
*/
public String getClientRequestID() {
return this.clientRequestID;
}
/**
* Gets the operation latency, in milliseconds, from the client's perspective. This may include any potential
* retries.
*
* @return A <code>long</code> which contains the client latency time in milliseconds.
*/
public long getClientTimeInMs() {
return this.clientTimeInMs;
}
/**
* Gets the last request result encountered for the operation.
*
* @return A {@link RequestResult} object which represents the last request result.
*/
public synchronized RequestResult getLastResult() {
if (this.requestResults == null || this.requestResults.size() == 0) {
return null;
}
else {
return this.requestResults.get(this.requestResults.size() - 1);
}
}
/**
* Gets the {@link org.slf4j.Logger} associated with this operation. If the {@link org.slf4j.Logger} object
* associated with this operation is null, this will return the class's default {@link org.slf4j.Logger} object.
*
* @return The {@link org.slf4j.Logger} object associated with this operation,
* or the class's default {@link org.slf4j.Logger} if null.
*/
public org.slf4j.Logger getLogger() {
if (this.logger == null) {
setDefaultLoggerSynchronized();
}
return this.logger;
}
/**
* Gets a proxy which will be used when making a request. Default is <code>null</code>. To set a proxy to use by
* default, use {@link #setDefaultProxy}
*
* @return A {@link java.net.Proxy} to use when making a request.
*/
public Proxy getProxy() {
return this.proxy;
}
/**
* Gets a username for the authenticated proxy which will be used when making a request.
* Default is <code>null</code>. To set a username use {@link #setProxyUsername(String)}
*
* @return A {@link String} to use when making a request.
*/
public String getProxyUsername() {
return proxyUsername != null ? proxyUsername : getDefaultProxyUsername();
}
/**
* Gets the password for the authenticated proxy which will be used when making a request.
* Default is <code>null</code>. To set a password to use {@link #setProxyPassword(String)}
*
* @return A {@link String} to use when making a request.
*/
public String getProxyPassword() {
return proxyPassword != null ? proxyPassword : getDefaultProxyPassword();
}
/**
* Gets any additional headers for the request, for example, for proxy or logging information.
*
* @return A <code>java.util.HashMap</code> which contains the the user headers for the request.
*/
public HashMap<String, String> getUserHeaders() {
return this.userHeaders;
}
/**
* Sets the default logger.
*
* This is in a separate method so that it's synchronized, just in case multiple threads are
* sharing the <code>OperationContext</code>.
*/
private synchronized void setDefaultLoggerSynchronized() {
if (this.logger == null) {
this.logger = org.slf4j.LoggerFactory.getLogger(OperationContext.defaultLoggerName);
}
}
/**
* Returns the set of request results that the current operation has created.
*
* @return An <code>ArrayList</code> object that contains {@link RequestResult} objects that represent
* the request results created by the current operation.
*/
public ArrayList<RequestResult> getRequestResults() {
return this.requestResults;
}
/**
* Reserved for internal use. Appends a {@link RequestResult} object to the internal collection in a synchronized
* manner.
*
* @param requestResult
* A {@link RequestResult} to append.
*/
public synchronized void appendRequestResult(RequestResult requestResult) {
this.requestResults.add(requestResult);
}
/**
* Gets a global event multi-caster that is triggered before sending a request. It allows event listeners to be
* dynamically added and removed.
*
* @return A {@link StorageEventMultiCaster} object for the <code>globalSendingRequestEventHandler</code>.
*/
public static StorageEventMultiCaster<SendingRequestEvent, StorageEvent<SendingRequestEvent>> getGlobalSendingRequestEventHandler() {
return OperationContext.globalSendingRequestEventHandler;
}
/**
* Gets a global event multi-caster that is triggered when a response is received. It allows event listeners to be
* dynamically added and removed.
*
* @return A {@link StorageEventMultiCaster} object for the <code>globalResponseReceivedEventHandler</code>.
*/
public static StorageEventMultiCaster<ResponseReceivedEvent, StorageEvent<ResponseReceivedEvent>> getGlobalResponseReceivedEventHandler() {
return OperationContext.globalResponseReceivedEventHandler;
}
/**
* Gets a global event multi-caster that is triggered when a network error occurs before the HTTP response status and headers are received.
* It allows event listeners to be dynamically added and removed.
*
* @return A {@link StorageEventMultiCaster} object for the <code>globabErrorReceivingResponseEventHandler</code>.
*/
public static StorageEventMultiCaster<ErrorReceivingResponseEvent, StorageEvent<ErrorReceivingResponseEvent>> getGlobalErrorReceivingResponseEventHandler() {
return OperationContext.globalErrorReceivingResponseEventHandler;
}
/**
* Gets a global event multi-caster that is triggered when a request is completed. It allows event listeners to be
* dynamically added and removed.
*
* @return A {@link StorageEventMultiCaster} object for the <code>globalRequestCompletedEventHandler</code>.
*/
public static StorageEventMultiCaster<RequestCompletedEvent, StorageEvent<RequestCompletedEvent>> getGlobalRequestCompletedEventHandler() {
return OperationContext.globalRequestCompletedEventHandler;
}
/**
* Gets a global event multi-caster that is triggered when a request is retried. It allows event listeners to be
* dynamically added and removed.
*
* @return A {@link StorageEventMultiCaster} object for the <code>globalRetryingEventHandler</code>.
*/
public static StorageEventMultiCaster<RetryingEvent, StorageEvent<RetryingEvent>> getGlobalRetryingEventHandler() {
return OperationContext.globalRetryingEventHandler;
}
/**
* Gets an event multi-caster that is triggered before sending a request. It allows event listeners to be
* dynamically added and removed.
*
* @return A {@link StorageEventMultiCaster} object for the <code>sendingRequestEventHandler</code>.
*/
public StorageEventMultiCaster<SendingRequestEvent, StorageEvent<SendingRequestEvent>> getSendingRequestEventHandler() {
return this.sendingRequestEventHandler;
}
/**
* Gets an event multi-caster that is triggered when a response is received. It allows event listeners to be
* dynamically added and removed.
*
* @return A {@link StorageEventMultiCaster} object for the <code>responseReceivedEventHandler</code>.
*/
public StorageEventMultiCaster<ResponseReceivedEvent, StorageEvent<ResponseReceivedEvent>> getResponseReceivedEventHandler() {
return this.responseReceivedEventHandler;
}
/**
* Gets an event multi-caster that is triggered when a network error occurs before the HTTP response status and headers are received.
* It allows event listeners to be dynamically added and removed.
*
* @return A {@link StorageEventMultiCaster} object for the <code>errorReceivingResponseEventHandler</code>.
*/
public StorageEventMultiCaster<ErrorReceivingResponseEvent, StorageEvent<ErrorReceivingResponseEvent>> getErrorReceivingResponseEventHandler() {
return this.errorReceivingResponseEventHandler;
}
/**
* Gets an event multi-caster that is triggered when a request is completed. It allows event listeners to be
* dynamically added and removed.
*
* @return A {@link StorageEventMultiCaster} object for the <code>requestCompletedEventHandler</code>.
*/
public StorageEventMultiCaster<RequestCompletedEvent, StorageEvent<RequestCompletedEvent>> getRequestCompletedEventHandler() {
return this.requestCompletedEventHandler;
}
/**
* Gets an event multi-caster that is triggered when a request is retried. It allows event listeners to be
* dynamically added and removed.
*
* @return A {@link StorageEventMultiCaster} object for the <code>retryingEventHandler</code>.
*/
public StorageEventMultiCaster<RetryingEvent, StorageEvent<RetryingEvent>> getRetryingEventHandler() {
return this.retryingEventHandler;
}
/**
* Reserved for internal use. Initializes the <code>OperationContext</code> in order to begin processing a
* new operation. All operation specific information is erased.
*/
public void initialize() {
this.setClientTimeInMs(0);
this.requestResults.clear();
}
/**
* Indicates whether log entries will be produced for this request.
*
* @return <code>true</code> if logging is enabled; otherwise <code>false</code>.
*/
public boolean isLoggingEnabled() {
if (this.enableLogging == null) {
return enableLoggingByDefault;
}
return this.enableLogging;
}
/**
* Sets the client side request ID.
*
* @param clientRequestID
* A <code>String</code> which contains the client request ID to set.
*/
public void setClientRequestID(final String clientRequestID) {
this.clientRequestID = clientRequestID;
}
/**
* Reserved for internal use. Represents the operation latency, in milliseconds, from the client's perspective. This
* may include any potential retries.
*
* @param clientTimeInMs
* A <code>long</code> which contains the client operation latency in milliseconds.
*/
public void setClientTimeInMs(final long clientTimeInMs) {
this.clientTimeInMs = clientTimeInMs;
}
/**
* Sets the {@link org.slf4j.Logger} for this operation.
*
* @param logger
* The <code>{@link org.slf4j.Logger}</code> to use for this operation.
*/
public void setLogger(final org.slf4j.Logger logger) {
this.logger = logger;
}
/**
* Sets a proxy which will be used when making a request. Default is <code>null</code>. To set a proxy to use by
* default, use {@link #setDefaultProxy}
*
* @param proxy
* A {@link java.net.Proxy} to use when making a request.
*/
public void setProxy(Proxy proxy) {
this.proxy = proxy;
}
/**
* Sets a username for an authenticated proxy which will be used when making a request.
* Default is <code>null</code>.
*
* @param username
* A {@link java.lang.String} to use when making a request.
*/
public void setProxyUsername(final String username) {
this.proxyUsername = username;
}
/**
* Sets a password for an authenticated proxy which will be used when making a request.
* Default is <code>null</code>.
*
* @param password
* A {@link java.lang.String} to use when making a request.
*/
public void setProxyPassword(final String password) {
this.proxyPassword = password;
}
/**
* Sets any additional headers for the request, for example, for proxy or logging information.
*
* @param userHeaders
* A <code>java.util.HashMap</code> which contains any additional headers to set.
*/
public void setUserHeaders(final HashMap<String, String> userHeaders) {
this.userHeaders = userHeaders;
}
/**
* Specifies whether log entries will be produced for this request.
*
* @param loggingEnabled
* <code>true</code> to enable logging; otherwise <code>false</code> to disable logging.
*/
public void setLoggingEnabled(boolean loggingEnabled) {
this.enableLogging = loggingEnabled;
}
/**
* Sets a global event multi-caster that is triggered before sending a request.
*
* @param globalSendingRequestEventHandler
* The {@link StorageEventMultiCaster} object to set for the <code>globalSendingRequestEventHandler</code>.
*/
public static void setGlobalSendingRequestEventHandler(
final StorageEventMultiCaster<SendingRequestEvent, StorageEvent<SendingRequestEvent>> globalSendingRequestEventHandler) {
OperationContext.globalSendingRequestEventHandler = globalSendingRequestEventHandler;
}
/**
* Sets a global event multi-caster that is triggered when a response is received.
*
* @param globalResponseReceivedEventHandler
* The {@link StorageEventMultiCaster} object to set for the <code>globalResponseReceivedEventHandler</code>.
*/
public static void setGlobalResponseReceivedEventHandler(
final StorageEventMultiCaster<ResponseReceivedEvent, StorageEvent<ResponseReceivedEvent>> globalResponseReceivedEventHandler) {
OperationContext.globalResponseReceivedEventHandler = globalResponseReceivedEventHandler;
}
/**
* Sets a global event multi-caster that is triggered when a network error occurs before the HTTP response status and headers are received.
*
* @param globalErrorReceivingResponseEventHandler
* The {@link StorageEventMultiCaster} object to set for the <code>globalErrorReceivingResponseEventHandler</code>.
*/
public static void setGlobalErrorReceivingResponseEventHandler(
final StorageEventMultiCaster<ErrorReceivingResponseEvent, StorageEvent<ErrorReceivingResponseEvent>> globalErrorReceivingResponseEventHandler) {
OperationContext.globalErrorReceivingResponseEventHandler = globalErrorReceivingResponseEventHandler;
}
/**
* Sets a global event multi-caster that is triggered when a request is completed.
*
* @param globalRequestCompletedEventHandler
* The {@link StorageEventMultiCaster} object to set for the <code>globalRequestCompletedEventHandler</code>.
*/
public static void setGlobalRequestCompletedEventHandler(
final StorageEventMultiCaster<RequestCompletedEvent, StorageEvent<RequestCompletedEvent>> globalRequestCompletedEventHandler) {
OperationContext.globalRequestCompletedEventHandler = globalRequestCompletedEventHandler;
}
/**
* Sets a global event multi-caster that is triggered when a request is retried.
*
* @param globalRetryingEventHandler
* The {@link StorageEventMultiCaster} object to set for the <code>globalRetryingEventHandler</code>.
*/
public static void setGlobalRetryingEventHandler(
final StorageEventMultiCaster<RetryingEvent, StorageEvent<RetryingEvent>> globalRetryingEventHandler) {
OperationContext.globalRetryingEventHandler = globalRetryingEventHandler;
}
/**
* Sets an event multi-caster that is triggered before sending a request.
*
* @param sendingRequestEventHandler
* The {@link StorageEventMultiCaster} object to set for the <code>sendingRequestEventHandler</code>.
*/
public void setSendingRequestEventHandler(
final StorageEventMultiCaster<SendingRequestEvent, StorageEvent<SendingRequestEvent>> sendingRequestEventHandler) {
this.sendingRequestEventHandler = sendingRequestEventHandler;
}
/**
* Sets an event multi-caster that is triggered when a response is received.
*
* @param responseReceivedEventHandler
* The {@link StorageEventMultiCaster} object to set for the <code>responseReceivedEventHandler</code>.
*/
public void setResponseReceivedEventHandler(
final StorageEventMultiCaster<ResponseReceivedEvent, StorageEvent<ResponseReceivedEvent>> responseReceivedEventHandler) {
this.responseReceivedEventHandler = responseReceivedEventHandler;
}
/**
* Sets an event multi-caster that is triggered when a network error occurs before the HTTP response status and headers are received.
*
* @param errorReceivingResponseEventHandler
* The {@link StorageEventMultiCaster} object to set for the <code>errorReceivingResponseEventHandler</code>.
*/
public void setErrorReceivingResponseEventHandler(
final StorageEventMultiCaster<ErrorReceivingResponseEvent, StorageEvent<ErrorReceivingResponseEvent>> errorReceivingResponseEventHandler) {
this.errorReceivingResponseEventHandler = errorReceivingResponseEventHandler;
}
/**
* Sets an event multi-caster that is triggered when a request is completed.
*
* @param requestCompletedEventHandler
* The {@link StorageEventMultiCaster} object to set for the <code>requestCompletedEventHandler</code>.
*/
public void setRequestCompletedEventHandler(
final StorageEventMultiCaster<RequestCompletedEvent, StorageEvent<RequestCompletedEvent>> requestCompletedEventHandler) {
this.requestCompletedEventHandler = requestCompletedEventHandler;
}
/**
* Sets an event multi-caster that is triggered when a request is retried.
*
* @param retryingEventHandler
* The {@link StorageEventMultiCaster} object to set for the <code>retryingEventHandler</code>.
*/
public void setRetryingEventHandler(
final StorageEventMultiCaster<RetryingEvent, StorageEvent<RetryingEvent>> retryingEventHandler) {
this.retryingEventHandler = retryingEventHandler;
}
/**
* Indicates whether the client library should produce log entries by default. The default can be overridden
* to enable logging for an individual operation context instance by using {@link #setLoggingEnabled}.
*
* @return
* <code>true</code> if logging is enabled by default; otherwise <code>false</code>.
*/
public static boolean isLoggingEnabledByDefault() {
return enableLoggingByDefault;
}
/**
* Specifies whether the client library should produce log entries by default. The default can be overridden
* to turn on logging for an individual operation context instance by using {@link #setLoggingEnabled}.
*
* @param enableLoggingByDefault
* <code>true</code> if logging should be enabled by default; otherwise <code>false</code> if logging should
* be disabled by default.
*/
public static void setLoggingEnabledByDefault(boolean enableLoggingByDefault) {
OperationContext.enableLoggingByDefault = enableLoggingByDefault;
}
/**
* Gets the default proxy used by the client library if enabled. The default can be overridden
* to enable a proxy for an individual operation context instance by using {@link #setProxy}.
*
* @return The default {@link java.net.Proxy} if set; otherwise <code>null</code>
*/
public static Proxy getDefaultProxy() {
return OperationContext.proxyDefault;
}
/**
* Specifies the proxy the client library should use by default. The default can be overridden
* to turn on a proxy for an individual operation context instance by using {@link #setProxy}.
*
* @param defaultProxy
* The {@link java.net.Proxy} to use by default, or <code>null</code> to not use a proxy.
*/
public static void setDefaultProxy(Proxy defaultProxy) {
OperationContext.proxyDefault = defaultProxy;
}
/**
* Gets a default username for the authenticated proxy which will be used when making a request.
* Default is <code>null</code>. To set a username use {@link #setDefaultProxyUsername(String)}
*
* @return A {@link String} to use when making a request.
*/
public static String getDefaultProxyUsername() {
return OperationContext.proxyDefaultUsername;
}
/**
* Gets the default password for the authenticated proxy which will be used when making a request.
* Default is <code>null</code>. To set a password to use {@link #setProxyPassword(String)}
*
* @return A {@link String} to use when making a request.
*/
public static String getDefaultProxyPassword() {
return OperationContext.proxyDefaultPassword;
}
/**
* Sets a default username for an authenticated proxy which will be used when making a request.
* Default is <code>null</code>.
*
* @param username
* A {@link java.lang.String} to use when making a request.
*/
public static void setDefaultProxyUsername(final String username) {
OperationContext.proxyDefaultUsername = username;
}
/**
* Sets a default password for an authenticated proxy which will be used when making a request.
* Default is <code>null</code>.
*
* @param password
* A {@link java.lang.String} to use when making a request.
*/
public static void setDefaultProxyPassword(final String password) {
OperationContext.proxyDefaultPassword = password;
}
}