1111import io .nats .client .api .StreamConfiguration ;
1212import io .synadia .counter .Counter ;
1313import io .synadia .counter .CounterEntryResponse ;
14- import io .synadia .counter .CounterValueResponse ;
1514
1615import java .math .BigInteger ;
1716import java .util .concurrent .LinkedBlockingQueue ;
@@ -98,37 +97,20 @@ public static void main(String[] args) throws Exception {
9897 }
9998
10099 // ----------------------------------------------------------------------------------------------------
101- System .out .println ("\n 4.1: getMultiple(\" cs.A\" , \" cs.B\" , \" cs.C\" ) - Get the CounterValueResponse objects for multiple subjects. Maybe to total them up?\" " );
102- LinkedBlockingQueue <CounterValueResponse > vResponses = counter .getMultiple ("cs.A" , "cs.B" , "cs.C" );
103- BigInteger total = BigInteger .ZERO ;
104- CounterValueResponse vr = vResponses .poll (1 , TimeUnit .SECONDS );
105- while (vr != null && vr .isValue ()) {
106- System .out .println (" " + vr );
107- total = total .add (vr .getValue ());
108- vr = vResponses .poll (10 , TimeUnit .MILLISECONDS );
109- }
110- System .out .println (" " + vr + " -> No more values." );
111- System .out .println (" Values totaled: " + total );
112-
113- System .out .println ("\n 4.2: getEntries(\" cs.A\" , \" cs.B\" , \" cs.C\" ) - Get the CounterEntryResponse objects for multiple subjects." );
100+ System .out .println ("\n 4.1: getEntries(\" cs.A\" , \" cs.B\" , \" cs.C\" ) - Get the CounterEntryResponse objects for multiple subjects." );
114101 LinkedBlockingQueue <CounterEntryResponse > eResponses = counter .getEntries ("cs.A" , "cs.B" , "cs.C" );
102+ BigInteger total = BigInteger .ZERO ;
115103 CounterEntryResponse er = eResponses .poll (1 , TimeUnit .SECONDS );
116104 while (er != null && er .isEntry ()) {
117105 System .out .println (" " + er );
106+ // the entry response has a method to simplify getting the value
107+ total = total .add (er .getValue ());
118108 er = eResponses .poll (10 , TimeUnit .MILLISECONDS );
119109 }
120110 System .out .println (" " + er + " -> No more entries." );
111+ System .out .println (" Values totaled: " + total );
121112
122- System .out .println ("\n 4.3: getMultiple(\" cs.*\" ) - Get the CounterValueResponse objects for wildcard subject(s)." );
123- vResponses = counter .getMultiple ("cs.*" );
124- vr = vResponses .poll (1 , TimeUnit .SECONDS );
125- while (vr != null && vr .isValue ()) {
126- System .out .println (" " + vr );
127- vr = vResponses .poll (10 , TimeUnit .MILLISECONDS );
128- }
129- System .out .println (" " + vr + " -> No more values." );
130-
131- System .out .println ("\n 4.4: getEntries(\" cs.*\" ) - Get CounterEntryResponse objects for wildcard subject(s)." );
113+ System .out .println ("\n 4.2: getEntries(\" cs.*\" ) - Get CounterEntryResponse objects for wildcard subject(s)." );
132114 eResponses = counter .getEntries ("cs.*" );
133115 er = eResponses .poll (1 , TimeUnit .SECONDS );
134116 while (er != null && er .isEntry ()) {
@@ -162,16 +144,7 @@ public static void main(String[] args) throws Exception {
162144 System .out .println (" get(\" cs.did-not-exist\" ) -> " + counter .get ("cs.did-not-exist" ));
163145
164146 // ----------------------------------------------------------------------------------------------------
165- System .out .println ("\n 6.1: getMultiple(\" cs.no-counters\" , \" cs.also-counters\" ) - getMultiple but no subjects have counters." );
166- vResponses = counter .getMultiple ("cs.no-counters" , "cs.also-counters" );
167- vr = vResponses .poll (1 , TimeUnit .SECONDS );
168- while (vr != null && vr .isValue ()) {
169- System .out .println (" " + er );
170- vr = vResponses .poll (10 , TimeUnit .MILLISECONDS );
171- }
172- System .out .println (" " + vr );
173-
174- System .out .println ("\n 6.2: getEntries(\" cs.no-counters\" , \" cs.also-counters\" ) - getEntries but no subjects have counters." );
147+ System .out .println ("\n 6.1: getEntries(\" cs.no-counters\" , \" cs.also-counters\" ) - getEntries but no subjects have counters." );
175148 eResponses = counter .getEntries ("cs.no-counters" , "cs.also-counters" );
176149 er = eResponses .poll (1 , TimeUnit .SECONDS );
177150 while (er != null && er .isEntry ()) {
@@ -181,16 +154,7 @@ public static void main(String[] args) throws Exception {
181154 System .out .println (" " + er );
182155
183156 // ----------------------------------------------------------------------------------------------------
184- System .out .println ("\n 7.1: getMultiple(\" no-counters\" , \" cs.A\" , \" cs.B\" , \" cs.C\" ) - getMultiple when some subjects have counters." );
185- vResponses = counter .getMultiple ("cs.no-counters" , "cs.A" , "cs.B" , "cs.C" );
186- vr = vResponses .poll (1 , TimeUnit .SECONDS );
187- while (vr != null && vr .isValue ()) {
188- System .out .println (" " + vr );
189- vr = vResponses .poll (10 , TimeUnit .MILLISECONDS );
190- }
191- System .out .println (" " + vr + " -> No more values." );
192-
193- System .out .println ("\n 7.2: getEntries(\" no-counters\" , \" cs.A\" , \" cs.B\" , \" cs.C\" ) - getEntries when some subjects have counters." );
157+ System .out .println ("\n 7.1: getEntries(\" no-counters\" , \" cs.A\" , \" cs.B\" , \" cs.C\" ) - getEntries when some subjects have counters." );
194158 eResponses = counter .getEntries ("cs.no-counters" , "cs.A" , "cs.B" , "cs.C" );
195159 er = eResponses .poll (1 , TimeUnit .SECONDS );
196160 while (er != null && er .isEntry ()) {
0 commit comments