Skip to content

Commit 019798d

Browse files
committed
JAVA-370: in mongo.close(), the sockets used for checking replica servers status are left open
Map Reduce: ability to add extra options, and always use "out" as object to be consistent
1 parent 5350ba8 commit 019798d

File tree

3 files changed

+58
-37
lines changed

3 files changed

+58
-37
lines changed

src/main/com/mongodb/MapReduceCommand.java

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -225,57 +225,67 @@ public void setOutputDB(String outputDB) {
225225
this._outputDB = outputDB;
226226
}
227227

228+
228229

229230
public DBObject toDBObject() {
230-
BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
231-
232-
builder.add("mapreduce", _input)
233-
.add("map", _map)
234-
.add("reduce", _reduce)
235-
.add("verbose", _verbose);
236-
237-
if (_outputType == OutputType.REPLACE && _outputDB == null) {
238-
builder.add("out", _outputTarget);
239-
} else {
240-
BasicDBObject out = new BasicDBObject();
241-
switch(_outputType) {
242-
case INLINE:
243-
out.put("inline", 1);
244-
break;
245-
case REPLACE:
246-
out.put("replace", _outputTarget);
247-
break;
248-
case MERGE:
249-
out.put("merge", _outputTarget);
250-
break;
251-
case REDUCE:
252-
out.put("reduce", _outputTarget);
253-
break;
254-
}
255-
if (_outputDB != null)
256-
out.put("db", _outputDB);
257-
builder.add("out", out);
231+
BasicDBObject cmd = new BasicDBObject();
232+
233+
cmd.put("mapreduce", _input);
234+
cmd.put("map", _map);
235+
cmd.put("reduce", _reduce);
236+
cmd.put("verbose", _verbose);
237+
238+
BasicDBObject out = new BasicDBObject();
239+
switch(_outputType) {
240+
case INLINE:
241+
out.put("inline", 1);
242+
break;
243+
case REPLACE:
244+
out.put("replace", _outputTarget);
245+
break;
246+
case MERGE:
247+
out.put("merge", _outputTarget);
248+
break;
249+
case REDUCE:
250+
out.put("reduce", _outputTarget);
251+
break;
258252
}
253+
if (_outputDB != null)
254+
out.put("db", _outputDB);
255+
cmd.put("out", out);
259256

260257
if (_query != null)
261-
builder.add("query", _query);
258+
cmd.put("query", _query);
262259

263260
if (_finalize != null)
264-
builder.add( "finalize", _finalize );
261+
cmd.put( "finalize", _finalize );
265262

266263
if (_sort != null)
267-
builder.add("sort", _sort);
264+
cmd.put("sort", _sort);
268265

269266
if (_limit > 0)
270-
builder.add("limit", _limit);
267+
cmd.put("limit", _limit);
271268

272269
if (_scope != null)
273-
builder.add("scope", _scope);
270+
cmd.put("scope", _scope);
274271

275-
276-
return builder.get();
272+
if (_extra != null) {
273+
cmd.putAll(_extra);
274+
}
275+
276+
return cmd;
277277
}
278278

279+
public void addExtraOption(String name, Object value) {
280+
if (_extra == null)
281+
_extra = new BasicDBObject();
282+
_extra.put(name, value);
283+
}
284+
285+
public DBObject getExtraOptions() {
286+
return _extra;
287+
}
288+
279289
public String toString() {
280290
return toDBObject().toString();
281291
}
@@ -292,4 +302,5 @@ public String toString() {
292302
int _limit;
293303
Map<String, Object> _scope;
294304
Boolean _verbose = true;
305+
DBObject _extra;
295306
}

src/main/com/mongodb/MapReduceOutput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public class MapReduceOutput {
1010

1111
@SuppressWarnings("unchecked")
12-
MapReduceOutput( DBCollection from , DBObject cmd, BasicDBObject raw ){
12+
public MapReduceOutput( DBCollection from , DBObject cmd, BasicDBObject raw ){
1313
_raw = raw;
1414
_cmd = cmd;
1515

src/main/com/mongodb/ReplicaSetStatus.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ public String toString(){
249249
return buf.toString();
250250
}
251251

252+
public void close() {
253+
_port.close();
254+
_port = null;
255+
}
256+
252257
final ServerAddress _addr;
253258
final Set<String> _names = Collections.synchronizedSet( new HashSet<String>() );
254259
DBPort _port; // we have our own port so we can set different socket options and don't have to owrry about the pool
@@ -388,7 +393,12 @@ void printStatus(){
388393
}
389394

390395
void close(){
391-
_closed = true;
396+
if (!_closed) {
397+
_closed = true;
398+
for (int i = 0; i < _all.size(); i++) {
399+
_all.get(i).close();
400+
}
401+
}
392402
}
393403

394404
/**

0 commit comments

Comments
 (0)