Skip to content

Commit 3984340

Browse files
committed
JAVA-649: Using connectTimeout from MongoOptions of the Mongo instance for all the timeouts in ReplicaSetStatus, MongosStatus, and DynamicConnectionStagtus
1 parent 7e614ec commit 3984340

File tree

3 files changed

+35
-37
lines changed

3 files changed

+35
-37
lines changed

src/main/com/mongodb/DynamicConnectionStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public CommandResult update() {
181181
private synchronized ConnectionStatus getConnectionStatus() {
182182
if (connectionStatus == null) {
183183
try {
184-
wait(_mongoOptions.connectTimeout);
184+
wait(_mongo.getMongoOptions().getConnectTimeout());
185185
} catch (InterruptedException e) {
186186
throw new MongoInterruptedException("Interrupted while waiting for next update to dynamic status", e);
187187
}

src/main/com/mongodb/MongosStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private synchronized Node getPreferred() {
119119
if (preferred == null) {
120120
try {
121121
synchronized (this) {
122-
wait();
122+
wait(_mongo.getMongoOptions().getConnectTimeout());
123123
}
124124
} catch (InterruptedException e) {
125125
throw new MongoInterruptedException("Interrupted while waiting for next update to mongos status", e);

src/main/com/mongodb/ReplicaSetStatus.java

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -124,41 +124,39 @@ boolean hasServerUp() {
124124
// Simple abstraction over a volatile ReplicaSet reference that starts as null. The get method blocks until members
125125
// is not null. The set method notifies all, thus waking up all getters.
126126
@ThreadSafe
127-
static class ReplicaSetHolder {
128-
private volatile ReplicaSet members;
129-
130-
// blocks until replica set is set, or a timeout occurs
131-
synchronized ReplicaSet get() {
132-
while (members == null) {
133-
try {
134-
wait(ReplicaSetStatus.mongoOptionsDefaults.socketTimeout);
135-
}
136-
catch (InterruptedException e) {
137-
throw new MongoInterruptedException("Interrupted while waiting for next update to replica set status", e);
138-
}
139-
}
140-
return members;
141-
}
142-
143-
// set the replica set to a non-null value and notifies all threads waiting.
144-
synchronized void set(ReplicaSet members) {
145-
if (members == null) {
146-
throw new IllegalArgumentException("members can not be null");
147-
}
148-
149-
this.members = members;
150-
notifyAll();
151-
}
152-
153-
// blocks until the replica set is set again
154-
synchronized void waitForNextUpdate() {
155-
try {
156-
wait(ReplicaSetStatus.mongoOptionsDefaults.socketTimeout);
157-
}
158-
catch (InterruptedException e) {
159-
throw new MongoInterruptedException("Interrupted while waiting for next update to replica set status", e);
160-
}
161-
}
127+
class ReplicaSetHolder {
128+
private volatile ReplicaSet members;
129+
130+
// blocks until replica set is set, or a timeout occurs
131+
synchronized ReplicaSet get() {
132+
while (members == null) {
133+
try {
134+
wait(_mongo.getMongoOptions().getConnectTimeout());
135+
} catch (InterruptedException e) {
136+
throw new MongoInterruptedException("Interrupted while waiting for next update to replica set status", e);
137+
}
138+
}
139+
return members;
140+
}
141+
142+
// set the replica set to a non-null value and notifies all threads waiting.
143+
synchronized void set(ReplicaSet members) {
144+
if (members == null) {
145+
throw new IllegalArgumentException("members can not be null");
146+
}
147+
148+
this.members = members;
149+
notifyAll();
150+
}
151+
152+
// blocks until the replica set is set again
153+
synchronized void waitForNextUpdate() {
154+
try {
155+
wait(_mongo.getMongoOptions().getConnectTimeout());
156+
} catch (InterruptedException e) {
157+
throw new MongoInterruptedException("Interrupted while waiting for next update to replica set status", e);
158+
}
159+
}
162160

163161
public synchronized void close() {
164162
this.members = null;

0 commit comments

Comments
 (0)