@@ -40,17 +40,10 @@ public final class ReplyHeader {
40
40
*/
41
41
public static final int TOTAL_REPLY_HEADER_LENGTH = REPLY_HEADER_LENGTH + MESSAGE_HEADER_LENGTH ;
42
42
43
- private static final int CURSOR_NOT_FOUND_RESPONSE_FLAG = 1 ;
44
- private static final int QUERY_FAILURE_RESPONSE_FLAG = 2 ;
45
-
46
43
private final int messageLength ;
47
44
private final int requestId ;
48
45
private final int responseTo ;
49
- private final int responseFlags ;
50
- private final long cursorId ;
51
- private final int startingFrom ;
52
- private final int numberReturned ;
53
- private final int opMsgFlagBits ;
46
+ private final boolean hasMoreToCome ;
54
47
55
48
ReplyHeader (final ByteBuf header , final MessageHeader messageHeader ) {
56
49
this (messageHeader .getMessageLength (), messageHeader .getOpCode (), messageHeader , header );
@@ -66,27 +59,23 @@ private ReplyHeader(final int messageLength, final int opCode, final MessageHead
66
59
this .requestId = messageHeader .getRequestId ();
67
60
this .responseTo = messageHeader .getResponseTo ();
68
61
if (opCode == OP_MSG .getValue ()) {
69
- responseFlags = 0 ;
70
- cursorId = 0 ;
71
- startingFrom = 0 ;
72
- numberReturned = 1 ;
73
-
74
- opMsgFlagBits = header .getInt ();
75
- header .get (); // ignore payload type
62
+ int flagBits = header .getInt ();
63
+ hasMoreToCome = (flagBits & (1 << 1 )) != 0 ;
64
+ header .get (); // ignored payload type
76
65
} else if (opCode == OP_REPLY .getValue ()) {
77
66
if (messageLength < TOTAL_REPLY_HEADER_LENGTH ) {
78
- throw new MongoInternalException (format ("The reply message length %d is less than the mimimum message length %d" ,
67
+ throw new MongoInternalException (format ("The reply message length %d is less than the minimum message length %d" ,
79
68
messageLength , TOTAL_REPLY_HEADER_LENGTH ));
80
69
}
70
+ hasMoreToCome = false ;
81
71
82
- responseFlags = header .getInt ();
83
- cursorId = header .getLong ();
84
- startingFrom = header .getInt ();
85
- numberReturned = header .getInt ();
86
- opMsgFlagBits = 0 ;
72
+ header .getInt (); // ignored responseFlags
73
+ header .getLong (); // ignored cursorId
74
+ header .getInt (); // ignored startingFrom
75
+ int numberReturned = header .getInt ();
87
76
88
- if (numberReturned < 0 ) {
89
- throw new MongoInternalException (format ("The reply message number of returned documents, %d, is less than 0 " ,
77
+ if (numberReturned != 1 ) {
78
+ throw new MongoInternalException (format ("The reply message number of returned documents, %d, is expected to be 1 " ,
90
79
numberReturned ));
91
80
}
92
81
} else {
@@ -123,78 +112,7 @@ public int getResponseTo() {
123
112
return responseTo ;
124
113
}
125
114
126
- /**
127
- * Gets additional information about the response.
128
- * <ul>
129
- * <li>0 - <i>CursorNotFound</i>: Set when getMore is called but the cursor id is not valid at the server. Returned with zero
130
- * results.</li>
131
- * <li>1 - <i>QueryFailure</i>: Set when query failed. Results consist of one document containing an "$err" field describing the
132
- * failure.
133
- * <li>2 - <i>ShardConfigStale</i>: Drivers should ignore this. Only mongos will ever see this set, in which case,
134
- * it needs to update config from the server.
135
- * <li>3 - <i>AwaitCapable</i>: Set when the server supports the AwaitData Query option. If it doesn't,
136
- * a client should sleep a little between getMore's of a Tailable cursor. Mongod version 1.6 supports AwaitData and thus always
137
- * sets AwaitCapable.
138
- * <li>4-31 - <i>Reserved</i>: Ignore
139
- * </ul>
140
- *
141
- * @return bit vector - see details above
142
- */
143
- public int getResponseFlags () {
144
- return responseFlags ;
145
- }
146
-
147
- /**
148
- * Gets the cursor ID that this response is a part of. If there are no more documents to fetch from the server, the cursor ID will be 0.
149
- * This cursor ID must be used in any messages used to get more data, and also must be closed by the client when no longer needed.
150
- *
151
- * @return cursor ID to use if the client needs to fetch more from the server
152
- */
153
- public long getCursorId () {
154
- return cursorId ;
155
- }
156
-
157
- /**
158
- * Returns the position in the cursor that is the start point of this reply.
159
- *
160
- * @return where in the cursor this reply is starting
161
- */
162
- public int getStartingFrom () {
163
- return startingFrom ;
164
- }
165
-
166
- /**
167
- * Gets the number of documents to expect in the body of this reply.
168
- *
169
- * @return number of documents in the reply
170
- */
171
- public int getNumberReturned () {
172
- return numberReturned ;
173
- }
174
-
175
- /**
176
- * Gets whether this query was performed with a cursor ID that was not valid on the server.
177
- *
178
- * @return true if this reply indicates the request to get more data was performed with a cursor ID that's not valid on the server
179
- */
180
- public boolean isCursorNotFound () {
181
- return (responseFlags & CURSOR_NOT_FOUND_RESPONSE_FLAG ) == CURSOR_NOT_FOUND_RESPONSE_FLAG ;
182
- }
183
-
184
- /**
185
- * Gets whether the query failed or not.
186
- *
187
- * @return true if this reply indicates the query failed.
188
- */
189
- public boolean isQueryFailure () {
190
- return (responseFlags & QUERY_FAILURE_RESPONSE_FLAG ) == QUERY_FAILURE_RESPONSE_FLAG ;
191
- }
192
-
193
- public int getOpMsgFlagBits () {
194
- return opMsgFlagBits ;
195
- }
196
-
197
115
public boolean hasMoreToCome () {
198
- return ( opMsgFlagBits & ( 1 << 1 )) != 0 ;
116
+ return hasMoreToCome ;
199
117
}
200
118
}
0 commit comments