1
1
using System ;
2
2
using System . Text ;
3
3
using Adaptive . Aeron . LogBuffer ;
4
+ using static Adaptive . Aeron . LogBuffer . FrameDescriptor ;
4
5
5
6
namespace Adaptive . Aeron
6
7
{
@@ -25,7 +26,6 @@ public class ChannelUriStringBuilder
25
26
private string _tags ;
26
27
private string _alias ;
27
28
private bool ? _reliable ;
28
- private bool ? _sparse ;
29
29
private int ? _ttl ;
30
30
private int ? _mtu ;
31
31
private int ? _termLength ;
@@ -34,6 +34,7 @@ public class ChannelUriStringBuilder
34
34
private int ? _termOffset ;
35
35
private int ? _sessionId ;
36
36
private long ? _linger ;
37
+ private bool ? _sparse ;
37
38
private bool _isSessionIdTagged ;
38
39
39
40
/// <summary>
@@ -277,30 +278,6 @@ public ChannelUriStringBuilder Reliable(bool? isReliable)
277
278
return _reliable ;
278
279
}
279
280
280
- /// <summary>
281
- /// Set to indicate if a term log buffer should be sparse on disk or not. Sparse saves space at the potential
282
- /// expense of latency.
283
- /// </summary>
284
- /// <param name="isSparse"> true if the term buffer log is sparse on disk. </param>
285
- /// <returns> this for a fluent API. </returns>
286
- /// <see cref="Aeron.Context.SPARSE_PARAM_NAME"/>
287
- public ChannelUriStringBuilder Sparse ( bool ? isSparse )
288
- {
289
- _sparse = isSparse ;
290
- return this ;
291
- }
292
-
293
- /// <summary>
294
- /// Get if a term log buffer should be sparse on disk or not. Sparse saves space at the potential expense of latency.
295
- /// </summary>
296
- /// <returns> true if the term buffer log is sparse on disk. </returns>
297
- /// <see cref="Aeron.Context.SPARSE_PARAM_NAME"/>
298
- public bool ? Sparse ( )
299
- {
300
- return _sparse ;
301
- }
302
-
303
-
304
281
/// <summary>
305
282
/// Set the Time To Live (TTL) for a multicast datagram. Valid values are 0-255 for the number of hops the datagram
306
283
/// can progress along.
@@ -345,7 +322,7 @@ public ChannelUriStringBuilder Mtu(int? mtu)
345
322
throw new ArgumentException ( "MTU not in range 32-65504: " + mtu ) ;
346
323
}
347
324
348
- if ( ( mtu & ( FrameDescriptor . FRAME_ALIGNMENT - 1 ) ) != 0 )
325
+ if ( ( mtu & ( FRAME_ALIGNMENT - 1 ) ) != 0 )
349
326
{
350
327
throw new ArgumentException ( "MTU not a multiple of FRAME_ALIGNMENT: mtu=" + mtu ) ;
351
328
}
@@ -454,7 +431,7 @@ public ChannelUriStringBuilder TermOffset(int? termOffset)
454
431
throw new ArgumentException ( "term offset not in range 0-1g: " + termOffset ) ;
455
432
}
456
433
457
- if ( 0 != ( termOffset & ( FrameDescriptor . FRAME_ALIGNMENT - 1 ) ) )
434
+ if ( 0 != ( termOffset & ( FRAME_ALIGNMENT - 1 ) ) )
458
435
{
459
436
throw new ArgumentException ( "term offset not multiple of FRAME_ALIGNMENT: " + termOffset ) ;
460
437
}
@@ -525,6 +502,29 @@ public ChannelUriStringBuilder Linger(long? lingerNs)
525
502
return _linger ;
526
503
}
527
504
505
+ /// <summary>
506
+ /// Set to indicate if a term log buffer should be sparse on disk or not. Sparse saves space at the potential
507
+ /// expense of latency.
508
+ /// </summary>
509
+ /// <param name="isSparse"> true if the term buffer log is sparse on disk. </param>
510
+ /// <returns> this for a fluent API. </returns>
511
+ /// <see cref="Aeron.Context.SPARSE_PARAM_NAME"/>
512
+ public ChannelUriStringBuilder Sparse ( bool ? isSparse )
513
+ {
514
+ _sparse = isSparse ;
515
+ return this ;
516
+ }
517
+
518
+ /// <summary>
519
+ /// Get if a term log buffer should be sparse on disk or not. Sparse saves space at the potential expense of latency.
520
+ /// </summary>
521
+ /// <returns> true if the term buffer log is sparse on disk. </returns>
522
+ /// <see cref="Aeron.Context.SPARSE_PARAM_NAME"/>
523
+ public bool ? Sparse ( )
524
+ {
525
+ return _sparse ;
526
+ }
527
+
528
528
/// <summary>
529
529
/// Set the tags for a channel used by a publication or subscription. Tags can be used to identify or tag a
530
530
/// channel so that a configuration can be referenced and reused.
@@ -606,6 +606,11 @@ public string Alias()
606
606
/// <returns> this for a fluent API. </returns>
607
607
public ChannelUriStringBuilder InitialPosition ( long position , int initialTermId , int termLength )
608
608
{
609
+ if ( position < 0 || 0 != ( position & ( FRAME_ALIGNMENT - 1 ) ) )
610
+ {
611
+ throw new ArgumentException ( "invalid position: " + position ) ;
612
+ }
613
+
609
614
int bitsToShift = LogBufferDescriptor . PositionBitsToShift ( termLength ) ;
610
615
611
616
_initialTermId = initialTermId ;
@@ -657,21 +662,6 @@ public string Build()
657
662
_sb . Append ( Aeron . Context . MDC_CONTROL_MODE_PARAM_NAME ) . Append ( '=' ) . Append ( _controlMode ) . Append ( '|' ) ;
658
663
}
659
664
660
- if ( null != _reliable )
661
- {
662
- _sb . Append ( Aeron . Context . RELIABLE_STREAM_PARAM_NAME ) . Append ( '=' ) . Append ( _reliable ) . Append ( '|' ) ;
663
- }
664
-
665
- if ( null != _sparse )
666
- {
667
- _sb . Append ( Aeron . Context . SPARSE_PARAM_NAME ) . Append ( '=' ) . Append ( _sparse ) . Append ( '|' ) ;
668
- }
669
-
670
- if ( null != _ttl )
671
- {
672
- _sb . Append ( Aeron . Context . TTL_PARAM_NAME ) . Append ( '=' ) . Append ( _ttl . Value ) . Append ( '|' ) ;
673
- }
674
-
675
665
if ( null != _mtu )
676
666
{
677
667
_sb . Append ( Aeron . Context . MTU_LENGTH_PARAM_NAME ) . Append ( '=' ) . Append ( _mtu . Value ) . Append ( '|' ) ;
@@ -703,6 +693,16 @@ public string Build()
703
693
_sb . Append ( Aeron . Context . SESSION_ID_PARAM_NAME ) . Append ( '=' ) . Append ( PrefixTag ( _isSessionIdTagged , _sessionId . Value ) ) . Append ( '|' ) ;
704
694
}
705
695
696
+ if ( null != _ttl )
697
+ {
698
+ _sb . Append ( Aeron . Context . TTL_PARAM_NAME ) . Append ( '=' ) . Append ( _ttl . Value ) . Append ( '|' ) ;
699
+ }
700
+
701
+ if ( null != _reliable )
702
+ {
703
+ _sb . Append ( Aeron . Context . RELIABLE_STREAM_PARAM_NAME ) . Append ( '=' ) . Append ( _reliable ) . Append ( '|' ) ;
704
+ }
705
+
706
706
if ( null != _linger )
707
707
{
708
708
_sb . Append ( Aeron . Context . LINGER_PARAM_NAME ) . Append ( '=' ) . Append ( _linger . Value ) . Append ( '|' ) ;
@@ -712,6 +712,11 @@ public string Build()
712
712
{
713
713
_sb . Append ( Aeron . Context . ALIAS_PARAM_NAME ) . Append ( '=' ) . Append ( _alias ) . Append ( '|' ) ;
714
714
}
715
+
716
+ if ( null != _sparse )
717
+ {
718
+ _sb . Append ( Aeron . Context . SPARSE_PARAM_NAME ) . Append ( '=' ) . Append ( _sparse ) . Append ( '|' ) ;
719
+ }
715
720
716
721
char lastChar = _sb [ _sb . Length - 1 ] ;
717
722
if ( lastChar == '|' || lastChar == '?' )
0 commit comments