Skip to content

Commit 020698b

Browse files
committed
Simplify CommandMessage.isResponseExpected
1 parent 77ff590 commit 020698b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import static com.mongodb.ReadPreference.primary;
4646
import static com.mongodb.ReadPreference.primaryPreferred;
4747
import static com.mongodb.assertions.Assertions.assertFalse;
48+
import static com.mongodb.assertions.Assertions.assertTrue;
4849
import static com.mongodb.assertions.Assertions.notNull;
4950
import static com.mongodb.connection.ClusterConnectionMode.LOAD_BALANCED;
5051
import static com.mongodb.connection.ClusterConnectionMode.SINGLE;
@@ -112,6 +113,7 @@ public final class CommandMessage extends RequestMessage {
112113
this.payloadFieldNameValidator = payloadFieldNameValidator;
113114
this.clusterConnectionMode = notNull("clusterConnectionMode", clusterConnectionMode);
114115
this.serverApi = serverApi;
116+
assertTrue(useOpMsg() || responseExpected);
115117
}
116118

117119
/**
@@ -187,7 +189,11 @@ private String getSequenceIdentifier(final ByteBuf byteBuf) {
187189
}
188190

189191
boolean isResponseExpected() {
190-
return !useOpMsg() || requireOpMsgResponse();
192+
if (responseExpected) {
193+
return true;
194+
} else {
195+
return payload != null && payload.isOrdered() && payload.hasAnotherSplit();
196+
}
191197
}
192198

193199
MongoNamespace getNamespace() {
@@ -240,7 +246,7 @@ protected EncodingMetadata encodeMessageBodyWithMetadata(final BsonOutput bsonOu
240246

241247
private int getOpMsgFlagBits() {
242248
int flagBits = 0;
243-
if (!requireOpMsgResponse()) {
249+
if (!isResponseExpected()) {
244250
flagBits = 1 << 1;
245251
}
246252
if (exhaustAllowed) {
@@ -249,14 +255,6 @@ private int getOpMsgFlagBits() {
249255
return flagBits;
250256
}
251257

252-
private boolean requireOpMsgResponse() {
253-
if (responseExpected) {
254-
return true;
255-
} else {
256-
return payload != null && payload.isOrdered() && payload.hasAnotherSplit();
257-
}
258-
}
259-
260258
private boolean isDirectConnectionToReplicaSetMember() {
261259
return clusterConnectionMode == SINGLE
262260
&& getSettings().getServerType() != SHARD_ROUTER

0 commit comments

Comments
 (0)