@@ -24,8 +24,19 @@ namespace OpenCensus.Stats
2424
2525 internal abstract class MutableViewData
2626 {
27- private const long MILLIS_PER_SECOND = 1000L ;
28- private const long NANOS_PER_MILLI = 1000 * 1000 ;
27+ internal static readonly ITagValue UnknownTagValue = null ;
28+
29+ internal static readonly ITimestamp ZeroTimestamp = Timestamp . Create ( 0 , 0 ) ;
30+
31+ private const long MillisPerSecond = 1000L ;
32+ private const long NanosPerMilli = 1000 * 1000 ;
33+
34+ protected MutableViewData ( IView view )
35+ {
36+ this . View = view ;
37+ }
38+
39+ internal IView View { get ; }
2940
3041 private static Func < ISum , MutableAggregation > CreateMutableSum { get ; } = ( s ) => { return MutableSum . Create ( ) ; } ;
3142
@@ -60,46 +71,10 @@ internal abstract class MutableViewData
6071 boxedBucketCounts ) ;
6172 } ;
6273
63- internal static readonly ITagValue UNKNOWN_TAG_VALUE = null ;
64-
65- internal static readonly ITimestamp ZERO_TIMESTAMP = Timestamp . Create ( 0 , 0 ) ;
66-
67- internal IView View { get ; }
68-
69- protected MutableViewData ( IView view )
70- {
71- this . View = view ;
72- }
73-
74- internal static MutableViewData Create ( IView view , ITimestamp start )
75- {
76- return new CumulativeMutableViewData ( view , start ) ;
77- }
78-
79- /** Record double stats with the given tags. */
80- internal abstract void Record ( ITagContext context , double value , ITimestamp timestamp ) ;
81-
82- /** Record long stats with the given tags. */
83- internal void Record ( ITagContext tags , long value , ITimestamp timestamp )
84- {
85- // TODO(songya): shall we check for precision loss here?
86- this . Record ( tags , ( double ) value , timestamp ) ;
87- }
88-
89- /** Convert this {@link MutableViewData} to {@link ViewData}. */
90- internal abstract IViewData ToViewData ( ITimestamp now , StatsCollectionState state ) ;
91-
92- // Clear recorded stats.
93- internal abstract void ClearStats ( ) ;
94-
95- // Resume stats collection, and reset Start Timestamp (for CumulativeMutableViewData), or refresh
96- // bucket list (for InternalMutableViewData).
97- internal abstract void ResumeStatsCollection ( ITimestamp now ) ;
98-
9974 internal static IDictionary < ITagKey , ITagValue > GetTagMap ( ITagContext ctx )
10075 {
10176 if ( ctx is TagContext )
102- {
77+ {
10378 return ( ( TagContext ) ctx ) . Tags ;
10479 }
10580 else
@@ -126,7 +101,7 @@ internal static IList<ITagValue> GetTagValues(IDictionary<ITagKey, ITagValue> ta
126101 if ( ! tags . ContainsKey ( tagKey ) )
127102 {
128103 // replace not found key values by null.
129- tagValues . Add ( UNKNOWN_TAG_VALUE ) ;
104+ tagValues . Add ( UnknownTagValue ) ;
130105 }
131106 else
132107 {
@@ -140,7 +115,7 @@ internal static IList<ITagValue> GetTagValues(IDictionary<ITagKey, ITagValue> ta
140115 // Returns the milliseconds representation of a Duration.
141116 internal static long ToMillis ( IDuration duration )
142117 {
143- return ( duration . Seconds * MILLIS_PER_SECOND ) + ( duration . Nanos / NANOS_PER_MILLI ) ;
118+ return ( duration . Seconds * MillisPerSecond ) + ( duration . Nanos / NanosPerMilli ) ;
144119 }
145120
146121 internal static MutableAggregation CreateMutableAggregation ( IAggregation aggregation )
@@ -172,7 +147,7 @@ internal static IAggregationData CreateAggregationData(MutableAggregation aggreg
172147 {
173148 throw new ArgumentException ( ) ;
174149 } ) ;
175- } ,
150+ } ,
176151 CreateCountData ,
177152 CreateMeanData ,
178153 CreateDistributionData ,
@@ -210,5 +185,30 @@ internal static IDictionary<TagValues, IAggregationData> CreateAggregationMap(ID
210185
211186 return map ;
212187 }
188+
189+ internal static MutableViewData Create ( IView view , ITimestamp start )
190+ {
191+ return new CumulativeMutableViewData ( view , start ) ;
192+ }
193+
194+ /** Record double stats with the given tags. */
195+ internal abstract void Record ( ITagContext context , double value , ITimestamp timestamp ) ;
196+
197+ /** Record long stats with the given tags. */
198+ internal void Record ( ITagContext tags , long value , ITimestamp timestamp )
199+ {
200+ // TODO(songya): shall we check for precision loss here?
201+ this . Record ( tags , ( double ) value , timestamp ) ;
202+ }
203+
204+ /** Convert this {@link MutableViewData} to {@link ViewData}. */
205+ internal abstract IViewData ToViewData ( ITimestamp now , StatsCollectionState state ) ;
206+
207+ // Clear recorded stats.
208+ internal abstract void ClearStats ( ) ;
209+
210+ // Resume stats collection, and reset Start Timestamp (for CumulativeMutableViewData), or refresh
211+ // bucket list (for InternalMutableViewData).
212+ internal abstract void ResumeStatsCollection ( ITimestamp now ) ;
213213 }
214214}
0 commit comments