16
16
import io .nats .client .support .JsonValue ;
17
17
18
18
import java .time .ZonedDateTime ;
19
+ import java .util .HashMap ;
19
20
import java .util .List ;
21
+ import java .util .Map ;
20
22
21
23
import static io .nats .client .support .ApiConstants .*;
22
24
import static io .nats .client .support .JsonValueUtils .*;
@@ -34,6 +36,7 @@ public class StreamState {
34
36
private final List <Subject > subjects ;
35
37
private final List <Long > deletedStreamSequences ;
36
38
private final LostStreamData lostStreamData ;
39
+ private final Map <String , Long > subjectMap ;
37
40
38
41
StreamState (JsonValue vStreamState ) {
39
42
msgs = readLong (vStreamState , MESSAGES , 0 );
@@ -48,6 +51,11 @@ public class StreamState {
48
51
subjects = Subject .listOf (readValue (vStreamState , SUBJECTS ));
49
52
deletedStreamSequences = readLongList (vStreamState , DELETED );
50
53
lostStreamData = LostStreamData .optionalInstance (readValue (vStreamState , LOST ));
54
+
55
+ subjectMap = new HashMap <>();
56
+ for (Subject s : subjects ) {
57
+ subjectMap .put (s .getName (), s .getCount ());
58
+ }
51
59
}
52
60
53
61
/**
@@ -122,14 +130,22 @@ public long getSubjectCount() {
122
130
}
123
131
124
132
/**
125
- * Get a list of the Subject objects. May be null if the Stream Info request did not ask for subjects
126
- * or if there are no subjects.
133
+ * Get a list of the Subject objects. May be empty, for instance
134
+ * if the Stream Info request did not ask for subjects or if there are no subjects.
127
135
* @return the list of subjects
128
136
*/
129
137
public List <Subject > getSubjects () {
130
138
return subjects ;
131
139
}
132
140
141
+ /**
142
+ * Get a map of subjects instead of a list of Subject objects.
143
+ * @return the map
144
+ */
145
+ public Map <String , Long > getSubjectMap () {
146
+ return subjectMap ;
147
+ }
148
+
133
149
/**
134
150
* Gets the count of deleted messages
135
151
*
0 commit comments