11using System ;
22using System . Text ;
33using Adaptive . Aeron . LogBuffer ;
4+ using static Adaptive . Aeron . LogBuffer . FrameDescriptor ;
45
56namespace Adaptive . Aeron
67{
@@ -25,7 +26,6 @@ public class ChannelUriStringBuilder
2526 private string _tags ;
2627 private string _alias ;
2728 private bool ? _reliable ;
28- private bool ? _sparse ;
2929 private int ? _ttl ;
3030 private int ? _mtu ;
3131 private int ? _termLength ;
@@ -34,6 +34,7 @@ public class ChannelUriStringBuilder
3434 private int ? _termOffset ;
3535 private int ? _sessionId ;
3636 private long ? _linger ;
37+ private bool ? _sparse ;
3738 private bool _isSessionIdTagged ;
3839
3940 /// <summary>
@@ -277,30 +278,6 @@ public ChannelUriStringBuilder Reliable(bool? isReliable)
277278 return _reliable ;
278279 }
279280
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-
304281 /// <summary>
305282 /// Set the Time To Live (TTL) for a multicast datagram. Valid values are 0-255 for the number of hops the datagram
306283 /// can progress along.
@@ -345,7 +322,7 @@ public ChannelUriStringBuilder Mtu(int? mtu)
345322 throw new ArgumentException ( "MTU not in range 32-65504: " + mtu ) ;
346323 }
347324
348- if ( ( mtu & ( FrameDescriptor . FRAME_ALIGNMENT - 1 ) ) != 0 )
325+ if ( ( mtu & ( FRAME_ALIGNMENT - 1 ) ) != 0 )
349326 {
350327 throw new ArgumentException ( "MTU not a multiple of FRAME_ALIGNMENT: mtu=" + mtu ) ;
351328 }
@@ -454,7 +431,7 @@ public ChannelUriStringBuilder TermOffset(int? termOffset)
454431 throw new ArgumentException ( "term offset not in range 0-1g: " + termOffset ) ;
455432 }
456433
457- if ( 0 != ( termOffset & ( FrameDescriptor . FRAME_ALIGNMENT - 1 ) ) )
434+ if ( 0 != ( termOffset & ( FRAME_ALIGNMENT - 1 ) ) )
458435 {
459436 throw new ArgumentException ( "term offset not multiple of FRAME_ALIGNMENT: " + termOffset ) ;
460437 }
@@ -525,6 +502,29 @@ public ChannelUriStringBuilder Linger(long? lingerNs)
525502 return _linger ;
526503 }
527504
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+
528528 /// <summary>
529529 /// Set the tags for a channel used by a publication or subscription. Tags can be used to identify or tag a
530530 /// channel so that a configuration can be referenced and reused.
@@ -606,6 +606,11 @@ public string Alias()
606606 /// <returns> this for a fluent API. </returns>
607607 public ChannelUriStringBuilder InitialPosition ( long position , int initialTermId , int termLength )
608608 {
609+ if ( position < 0 || 0 != ( position & ( FRAME_ALIGNMENT - 1 ) ) )
610+ {
611+ throw new ArgumentException ( "invalid position: " + position ) ;
612+ }
613+
609614 int bitsToShift = LogBufferDescriptor . PositionBitsToShift ( termLength ) ;
610615
611616 _initialTermId = initialTermId ;
@@ -657,21 +662,6 @@ public string Build()
657662 _sb . Append ( Aeron . Context . MDC_CONTROL_MODE_PARAM_NAME ) . Append ( '=' ) . Append ( _controlMode ) . Append ( '|' ) ;
658663 }
659664
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-
675665 if ( null != _mtu )
676666 {
677667 _sb . Append ( Aeron . Context . MTU_LENGTH_PARAM_NAME ) . Append ( '=' ) . Append ( _mtu . Value ) . Append ( '|' ) ;
@@ -703,6 +693,16 @@ public string Build()
703693 _sb . Append ( Aeron . Context . SESSION_ID_PARAM_NAME ) . Append ( '=' ) . Append ( PrefixTag ( _isSessionIdTagged , _sessionId . Value ) ) . Append ( '|' ) ;
704694 }
705695
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+
706706 if ( null != _linger )
707707 {
708708 _sb . Append ( Aeron . Context . LINGER_PARAM_NAME ) . Append ( '=' ) . Append ( _linger . Value ) . Append ( '|' ) ;
@@ -712,6 +712,11 @@ public string Build()
712712 {
713713 _sb . Append ( Aeron . Context . ALIAS_PARAM_NAME ) . Append ( '=' ) . Append ( _alias ) . Append ( '|' ) ;
714714 }
715+
716+ if ( null != _sparse )
717+ {
718+ _sb . Append ( Aeron . Context . SPARSE_PARAM_NAME ) . Append ( '=' ) . Append ( _sparse ) . Append ( '|' ) ;
719+ }
715720
716721 char lastChar = _sb [ _sb . Length - 1 ] ;
717722 if ( lastChar == '|' || lastChar == '?' )
0 commit comments