-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathQueueingServiceExtensions.cs
More file actions
869 lines (790 loc) · 48.5 KB
/
Copy pathQueueingServiceExtensions.cs
File metadata and controls
869 lines (790 loc) · 48.5 KB
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
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
namespace net.openstack.Core.Synchronous
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using net.openstack.Core.Collections;
using net.openstack.Core.Domain;
using net.openstack.Core.Domain.Queues;
using CancellationToken = System.Threading.CancellationToken;
using IQueueingService = net.openstack.Core.Providers.IQueueingService;
using JObject = Newtonsoft.Json.Linq.JObject;
using JsonSerializationException = Newtonsoft.Json.JsonSerializationException;
using WebException = System.Net.WebException;
/// <summary>
/// Provides extension methods to allow synchronous calls to the methods in <see cref="IQueueingService"/>.
/// </summary>
/// <threadsafety static="true" instance="false"/>
/// <preliminary/>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static class QueueingServiceExtensions
{
#region Base endpoints
/// <summary>
/// Gets the home document describing the operations supported by the service.
/// </summary>
/// <param name="queueingService">The queueing service instance.</param>
/// <returns>A <see cref="HomeDocument"/> object describing the operations supported by the service.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Get_Home_Document">Get Home Document (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static HomeDocument GetHome(this IQueueingService queueingService)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.GetHomeAsync(CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Checks the queueing service node status.
/// </summary>
/// <param name="queueingService">The queueing service instance.</param>
/// <returns>
/// If the service is available, the operation will complete successfully. If the service
/// is unavailable due to a storage driver failure or some other error, the operation will
/// fail and the exception will contain the reason for the failure.
/// </returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/wiki/Marconi/specs/api/v1#Check_Node_Health">Check Node Health (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static void GetNodeHealth(this IQueueingService queueingService)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
queueingService.GetNodeHealthAsync(CancellationToken.None).Wait();
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
#endregion Base endpoints
#region Queues
/// <summary>
/// Creates a queue, if it does not already exist.
/// </summary>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <returns><see langword="true"/> if the queue was created by the call, or <see langword="false"/> if the queue already existed.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="queueName"/> is <see langword="null"/>.</exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Create_Queue">Create Queue (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static bool CreateQueue(this IQueueingService queueingService, QueueName queueName)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.CreateQueueAsync(queueName, CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Gets a list of queues.
/// </summary>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="marker">The name of the last queue in the previous list. The resulting collection of queues will start with the first queue <em>after</em> this value, when sorted using <see cref="StringComparer.Ordinal"/>. If this value is <see langword="null"/>, the list starts at the beginning.</param>
/// <param name="limit">The maximum number of queues to return. If this value is <see langword="null"/>, a provider-specific default value is used.</param>
/// <param name="detailed"><see langword="true"/> to return detailed information about each queue; otherwise, <see langword="false"/>.</param>
/// <returns><placeholder>placeholder</placeholder></returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#List_Queues">List Queues (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static ReadOnlyCollectionPage<CloudQueue> ListQueues(this IQueueingService queueingService, QueueName marker, int? limit, bool detailed)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.ListQueuesAsync(marker, limit, detailed, CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Checks for the existence of a queue with a particular name.
/// </summary>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <returns><see langword="true"/> if queue with the specified name exists; otherwise, <see langword="false"/>.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="queueName"/> is <see langword="null"/>.</exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Checking_Queue_Existence">Checking Queue Existence (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static bool QueueExists(this IQueueingService queueingService, QueueName queueName)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.QueueExistsAsync(queueName, CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Deletes a queue.
/// </summary>
/// <remarks>
/// The queue will be deleted whether or not it is empty, even if one or more messages in the queue is currently claimed.
/// </remarks>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="queueName"/> is <see langword="null"/>.</exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Delete_Queue">Delete Queue (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static void DeleteQueue(this IQueueingService queueingService, QueueName queueName)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
queueingService.DeleteQueueAsync(queueName, CancellationToken.None).Wait();
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
#endregion
#region Queue metadata
/// <summary>
/// Sets the metadata associated with a queue.
/// </summary>
/// <typeparam name="T">The type of data to associate with the queue.</typeparam>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="metadata">The metadata to associate with the queue.</param>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="queueName"/> is <see langword="null"/>.</exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Set_Queue_Metadata">Set Queue Metadata (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static void SetQueueMetadata<T>(this IQueueingService queueingService, QueueName queueName, T metadata)
where T : class
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
queueingService.SetQueueMetadataAsync(queueName, metadata, CancellationToken.None).Wait();
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Gets the metadata associated with a queue.
/// </summary>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <returns>A <see cref="JObject"/> object containing the metadata associated with the queue.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="queueName"/> is <see langword="null"/>.</exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Get_Queue_Metadata">Get Queue Metadata (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static JObject GetQueueMetadata(this IQueueingService queueingService, QueueName queueName)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.GetQueueMetadataAsync(queueName, CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Gets the metadata associated with a queue, as a strongly-typed object.
/// </summary>
/// <typeparam name="T">The type of metadata associated with the queue.</typeparam>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <returns>A deserialized object of type <typeparamref name="T"/> representing the metadata associated with the queue.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="queueName"/> is <see langword="null"/>.</exception>
/// <exception cref="JsonSerializationException">If an error occurs while deserializing the metadata.</exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Get_Queue_Metadata">Get Queue Metadata (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static T GetQueueMetadata<T>(this IQueueingService queueingService, QueueName queueName)
where T : class
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.GetQueueMetadataAsync<T>(queueName, CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Gets statistics for a queue.
/// </summary>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <returns>A <see cref="QueueStatistics"/> object containing statistics for the queue.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="queueName"/> is <see langword="null"/>.</exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Get_Queue_Stats">Get Queue Stats (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static QueueStatistics GetQueueStatistics(this IQueueingService queueingService, QueueName queueName)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.GetQueueStatisticsAsync(queueName, CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
#endregion Queue metadata
#region Messages
/// <summary>
/// Gets a list of messages currently in a queue.
/// </summary>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="marker">The identifier of the message list page to return. This is obtained from <see cref="QueuedMessageList.NextPageId"/>. If this value is <see langword="null"/>, the list starts at the beginning.</param>
/// <param name="limit">The maximum number of messages to return. If this value is <see langword="null"/>, a provider-specific default value is used.</param>
/// <param name="echo"><see langword="true"/> to include messages created by the current client; otherwise, <see langword="false"/>.</param>
/// <param name="includeClaimed"><see langword="true"/> to include claimed messages; otherwise <see langword="false"/> to return only unclaimed messages.</param>
/// <returns>A collection of <see cref="QueuedMessage"/> objects describing the messages in the queue.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="queueName"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#List_Messages">List Messages (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static QueuedMessageList ListMessages(this IQueueingService queueingService, QueueName queueName, QueuedMessageListId marker, int? limit, bool echo, bool includeClaimed)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.ListMessagesAsync(queueName, marker, limit, echo, includeClaimed, CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Gets detailed information about a specific queued message.
/// </summary>
/// <remarks>
/// This method will return information for the specified message regardless of the
/// <literal>Client-ID</literal> or claim associated with the message.
/// </remarks>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="messageId">The message ID. This is obtained from <see cref="QueuedMessage.Id">QueuedMessage.Id</see>.</param>
/// <returns>A <see cref="QueuedMessage"/> object containing detailed information about the specified message.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">
/// If <paramref name="queueName"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <para>If <paramref name="messageId"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Get_a_Specific_Message">Get a Specific Message (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static QueuedMessage GetMessage(this IQueueingService queueingService, QueueName queueName, MessageId messageId)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.GetMessageAsync(queueName, messageId, CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Get messages from a queue.
/// </summary>
/// <remarks>
/// This method will return information for the specified message regardless of the
/// <literal>Client-ID</literal> or claim associated with the message.
/// </remarks>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="messageIds">The message IDs of messages to get.</param>
/// <returns>A collection of <see cref="QueuedMessage"/> objects containing detailed information about the specified messages.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">
/// If <paramref name="queueName"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <para>If <paramref name="messageIds"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="ArgumentException">
/// If <paramref name="messageIds"/> contains a <see langword="null"/> value.
/// </exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Get_a_Set_of_Messages_by_ID">Get a Set of Messages by ID (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static ReadOnlyCollection<QueuedMessage> GetMessages(this IQueueingService queueingService, QueueName queueName, IEnumerable<MessageId> messageIds)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.GetMessagesAsync(queueName, messageIds, CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Posts messages to a queue.
/// </summary>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="messages">The messages to post.</param>
/// <returns>A <see cref="MessagesEnqueued"/> object representing the result of the operation.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">
/// If <paramref name="queueName"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <para>If <paramref name="messages"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="ArgumentException">
/// If <paramref name="messages"/> contains a <see langword="null"/> value.
/// </exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Post_Message.28s.29">Post Message(s) (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static MessagesEnqueued PostMessages(this IQueueingService queueingService, QueueName queueName, IEnumerable<Message> messages)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.PostMessagesAsync(queueName, messages, CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Posts messages to a queue.
/// </summary>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="messages">The messages to post.</param>
/// <returns>A <see cref="MessagesEnqueued"/> object representing the result of the operation.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">
/// If <paramref name="queueName"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <para>If <paramref name="messages"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="ArgumentException">
/// If <paramref name="messages"/> contains a <see langword="null"/> value.
/// </exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Post_Message.28s.29">Post Message(s) (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static MessagesEnqueued PostMessages(this IQueueingService queueingService, QueueName queueName, params Message[] messages)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.PostMessagesAsync(queueName, CancellationToken.None, messages).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Posts messages to a queue.
/// </summary>
/// <typeparam name="T">The class modeling the JSON representation of the messages to post in the queue.</typeparam>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="messages">The messages to post.</param>
/// <returns>A <see cref="MessagesEnqueued"/> object representing the result of the operation.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">
/// If <paramref name="queueName"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <para>If <paramref name="messages"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="ArgumentException">
/// If <paramref name="messages"/> contains a <see langword="null"/> value.
/// </exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Post_Message.28s.29">Post Message(s) (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static MessagesEnqueued PostMessages<T>(this IQueueingService queueingService, QueueName queueName, IEnumerable<Message<T>> messages)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.PostMessagesAsync(queueName, messages, CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Posts messages to a queue.
/// </summary>
/// <typeparam name="T">The class modeling the JSON representation of the messages to post in the queue.</typeparam>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="messages">The messages to post.</param>
/// <returns>A <see cref="MessagesEnqueued"/> object representing the result of the operation.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">
/// If <paramref name="queueName"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <para>If <paramref name="messages"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="ArgumentException">
/// If <paramref name="messages"/> contains a <see langword="null"/> value.
/// </exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Post_Message.28s.29">Post Message(s) (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static MessagesEnqueued PostMessages<T>(this IQueueingService queueingService, QueueName queueName, params Message<T>[] messages)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.PostMessagesAsync(queueName, CancellationToken.None, messages).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Deletes a message from a queue.
/// </summary>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="messageId">The ID of the message to delete. This is obtained from <see cref="QueuedMessage.Id">QueuedMessage.Id</see>.</param>
/// <param name="claim">The claim for the message. If this value is <see langword="null"/>, the delete operation will fail if the message is claimed. If this value is non-<see langword="null"/>, the delete operation will fail if the message is not claimed by the specified claim.</param>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">
/// If <paramref name="queueName"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <para>If <paramref name="messageId"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Delete_Message">Delete Message (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static void DeleteMessage(this IQueueingService queueingService, QueueName queueName, MessageId messageId, Claim claim)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
queueingService.DeleteMessageAsync(queueName, messageId, claim, CancellationToken.None).Wait();
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Deletes messages from a queue.
/// </summary>
/// <remarks>
/// <note type="warning">
/// This method deletes messages from a queue whether or not they are currently claimed.
/// </note>
/// </remarks>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="messageIds">The IDs of messages to delete. These are obtained from <see cref="QueuedMessage.Id">QueuedMessage.Id</see>.</param>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">
/// If <paramref name="queueName"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <para>If <paramref name="messageIds"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="ArgumentException">
/// If <paramref name="messageIds"/> contains a <see langword="null"/> value.
/// </exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Delete_a_Set_of_Messages_by_ID">Delete a Set of Messages by ID (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static void DeleteMessages(this IQueueingService queueingService, QueueName queueName, IEnumerable<MessageId> messageIds)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
queueingService.DeleteMessagesAsync(queueName, messageIds, CancellationToken.None).Wait();
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
#endregion Messages
#region Claims
/// <summary>
/// Claim messages from a queue.
/// </summary>
/// <remarks>
/// When the claim is no longer required, the code should call <see cref="Claim.DisposeAsync"/>
/// or <see cref="Claim.Dispose()"/> to ensure the following actions are taken.
/// <list type="bullet">
/// <item>Messages which are part of this claim which were not processed are made available to other nodes.</item>
/// <item>The claim resource is cleaned up without waiting for the time-to-live to expire.</item>
/// </list>
///
/// <para>Messages which are not deleted before the claim is released will be eligible for
/// reclaiming by another process.</para>
/// </remarks>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="limit">The maximum number of messages to claim. If this value is <see langword="null"/>, a provider-specific default value is used.</param>
/// <param name="timeToLive">The time to wait before the server automatically releases the claim.</param>
/// <param name="gracePeriod">The time to wait, after the time-to-live for the claim expires, before the server allows the claimed messages to be deleted due to the individual message's time-to-live expiring.</param>
/// <returns>A <see cref="Claim"/> object representing the claim.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="queueName"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">
/// If <paramref name="limit"/> is less than or equal to 0.
/// <para>-or-</para>
/// <para>If <paramref name="timeToLive"/> is negative or <see cref="TimeSpan.Zero"/>.</para>
/// <para>-or-</para>
/// <para>If <paramref name="gracePeriod"/> is negative.</para>
/// </exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Claim_Messages">Claim Messages (OpenStack Marconi API v1 Blueprint)</seealso>
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static Claim ClaimMessage(this IQueueingService queueingService, QueueName queueName, int? limit, TimeSpan timeToLive, TimeSpan gracePeriod)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.ClaimMessageAsync(queueName, limit, timeToLive, gracePeriod, CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Gets detailed information about the current state of a claim.
/// </summary>
/// <remarks>
/// <note type="caller">Use <see cref="Claim.RefreshAsync"/> instead of calling this method directly.</note>
/// </remarks>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="claim">The claim to query.</param>
/// <returns>A <see cref="Claim"/> object representing the claim.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">
/// If <paramref name="queueName"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <para>If <paramref name="claim"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Query_Claim">Query Claim (OpenStack Marconi API v1 Blueprint)</seealso>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static Claim QueryClaim(this IQueueingService queueingService, QueueName queueName, Claim claim)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
return queueingService.QueryClaimAsync(queueName, claim, CancellationToken.None).Result;
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Renews a claim, by updating the time-to-live and resetting the age of the claim to zero.
/// </summary>
/// <remarks>
/// <note type="caller">Use <see cref="Claim.RenewAsync"/> instead of calling this method directly.</note>
/// </remarks>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="claim">The claim to renew.</param>
/// <param name="timeToLive">The updated time-to-live for the claim.</param>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">
/// If <paramref name="queueName"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <para>If <paramref name="claim"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="timeToLive"/> is negative.</exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Update_Claim">Update Claim (OpenStack Marconi API v1 Blueprint)</seealso>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static void UpdateClaim(this IQueueingService queueingService, QueueName queueName, Claim claim, TimeSpan timeToLive)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
queueingService.UpdateClaimAsync(queueName, claim, timeToLive, CancellationToken.None).Wait();
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
/// <summary>
/// Immediately release a claim, making any (remaining, non-deleted) messages associated
/// with the claim available to other workers.
/// </summary>
/// <remarks>
/// <note type="caller">Use <see cref="Claim.DisposeAsync"/> instead of calling this method directly.</note>
/// </remarks>
/// <param name="queueingService">The queueing service instance.</param>
/// <param name="queueName">The queue name.</param>
/// <param name="claim">The claim to release.</param>
/// <exception cref="ArgumentNullException">If <paramref name="queueingService"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">
/// If <paramref name="queueName"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <para>If <paramref name="claim"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="WebException">If the REST request does not return successfully.</exception>
/// <seealso href="https://wiki.openstack.org/w/index.php?title=Marconi/specs/api/v1#Release_Claim">Release Claim (OpenStack Marconi API v1 Blueprint)</seealso>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("These synchronous wrappers should not be used. For more information, see http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx.")]
public static void ReleaseClaim(this IQueueingService queueingService, QueueName queueName, Claim claim)
{
if (queueingService == null)
throw new ArgumentNullException("queueingService");
try
{
queueingService.ReleaseClaimAsync(queueName, claim, CancellationToken.None).Wait();
}
catch (AggregateException ex)
{
ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
if (innerExceptions.Count == 1)
throw innerExceptions[0];
throw;
}
}
#endregion
}
}