Skip to content

Commit e012113

Browse files
committed
JAVA-682: Updated WriteConcern Java doc
1 parent b4d0a6e commit e012113

File tree

1 file changed

+60
-25
lines changed

1 file changed

+60
-25
lines changed

src/main/com/mongodb/WriteConcern.java

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,62 +25,98 @@
2525
import java.util.Map;
2626

2727
/**
28-
* <p>WriteConcern control the write behavior for with various options, as well as exception raising on error conditions.</p>
29-
*
28+
* <p>WriteConcern control the acknowledgment of write operations with various options.
3029
* <p>
3130
* <b>w</b>
3231
* <ul>
33-
* <li>-1 = don't even report network errors </li>
34-
* <li> 0 = default, don't call getLastError by default </li>
35-
* <li> 1 = basic, call getLastError, but don't wait for slaves</li>
36-
* <li> 2+= wait for slaves </li>
32+
* <li>-1 = Don't even report network errors </li>
33+
* <li> 0 = Don't wait for acknowledgement from the server </li>
34+
* <li> 1 = Wait for acknowledgement, but don't wait for secondaries to replicate</li>
35+
* <li> 2+= Wait for one or more secondaries to also acknowledge </li>
3736
* </ul>
3837
* <b>wtimeout</b> how long to wait for slaves before failing
3938
* <ul>
40-
* <li>0 = indefinite </li>
41-
* <li>> 0 = ms to wait </li>
39+
* <li>0: indefinite </li>
40+
* <li>greater than 0: ms to wait </li>
4241
* </ul>
4342
* </p>
44-
* <p><b>fsync</b> force fsync to disk </p>
45-
*
43+
* <p>
44+
* Other options:
45+
* <ul>
46+
* <li><b>j</b>: wait for group commit to journal</li>
47+
* <li><b>fsync</b>: force fsync to disk</li>
48+
* </ul>
4649
* @dochub databases
4750
*/
4851
public class WriteConcern implements Serializable {
4952

5053
private static final long serialVersionUID = 1884671104750417011L;
5154

52-
/** No exceptions are raised, even for network issues */
55+
/**
56+
* Write operations that use this write concern will wait for acknowledgement from the primary server before returning.
57+
* Exceptions are raised for network issues, and server errors.
58+
* @since 2.10.0
59+
*/
60+
public final static WriteConcern ACKNOWLEDGED = new WriteConcern(1);
61+
/**
62+
* Write operations that use this write concern will return as soon as the message is written to the socket.
63+
* Exceptions are raised for network issues, but not server errors.
64+
* @since 2.10.0
65+
*/
66+
public final static WriteConcern UNACKNOWLEDGED = new WriteConcern(0);
67+
68+
/**
69+
* No exceptions are raised, even for network issues.
70+
*/
5371
public final static WriteConcern NONE = new WriteConcern(-1);
5472

55-
/** Exceptions are raised for network issues, but not server errors */
73+
/**
74+
* Write operations that use this write concern will return as soon as the message is written to the socket.
75+
* Exceptions are raised for network issues, but not server errors.
76+
* <p>
77+
* This field has been superseded by {@code WriteConcern.UNACKNOWLEDGED}, and may be deprecated in a future release.
78+
* @see WriteConcern#UNACKNOWLEDGED
79+
*/
5680
public final static WriteConcern NORMAL = new WriteConcern(0);
5781

58-
/** Exceptions are raised for network issues, and server errors; waits on a server for the write operation */
82+
/**
83+
* Write operations that use this write concern will wait for acknowledgement from the primary server before returning.
84+
* Exceptions are raised for network issues, and server errors.
85+
* <p>
86+
* This field has been superseded by {@code WriteConcern.ACKNOWLEDGED}, and may be deprecated in a future release.
87+
* @see WriteConcern#ACKNOWLEDGED
88+
*/
5989
public final static WriteConcern SAFE = new WriteConcern(1);
6090

61-
/** Exceptions are raised for network issues, but not server errors */
62-
public final static WriteConcern UNACKNOWLEDGED = new WriteConcern(0);
63-
64-
/** Exceptions are raised for network issues, and server errors; waits on a server for the write operation */
65-
public final static WriteConcern ACKNOWLEDGED = new WriteConcern(1);
66-
67-
/** Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation */
91+
/**
92+
* Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation.
93+
*/
6894
public final static WriteConcern MAJORITY = new Majority();
6995

70-
/** Exceptions are raised for network issues, and server errors; the write operation waits for the server to flush the data to disk*/
96+
/**
97+
* Exceptions are raised for network issues, and server errors; the write operation waits for the server to flush
98+
* the data to disk.
99+
*/
71100
public final static WriteConcern FSYNC_SAFE = new WriteConcern(true);
72101

73-
/** Exceptions are raised for network issues, and server errors; the write operation waits for the server to group commit to the journal file on disk*/
102+
/**
103+
* Exceptions are raised for network issues, and server errors; the write operation waits for the server to
104+
* group commit to the journal file on disk.
105+
*/
74106
public final static WriteConcern JOURNAL_SAFE = new WriteConcern( 1, 0, false, true );
75107

76-
/** Exceptions are raised for network issues, and server errors; waits for at least 2 servers for the write operation*/
108+
/**
109+
* Exceptions are raised for network issues, and server errors; waits for at least 2 servers for the write operation.
110+
*/
77111
public final static WriteConcern REPLICAS_SAFE = new WriteConcern(2);
78112

79113
// map of the constants from above for use by fromString
80114
private static Map<String, WriteConcern> _namedConcerns = null;
81115

82116
/**
83-
* Default constructor keeping all options as default
117+
* Default constructor keeping all options as default. Be careful using this constructor, as it's equivalent to
118+
* {@code WriteConcern.UNACKNOWLEDGED}, so writes may be lost without any errors being reported.
119+
* @see WriteConcern#UNACKNOWLEDGED
84120
*/
85121
public WriteConcern(){
86122
this(0);
@@ -241,7 +277,6 @@ public WriteConcern( String w , int wtimeout , boolean fsync, boolean j, boolean
241277
public BasicDBObject getCommand() {
242278
BasicDBObject _command = new BasicDBObject( "getlasterror" , 1 );
243279

244-
245280
if (_w instanceof Integer && ((Integer) _w > 1) || (_w instanceof String)){
246281
_command.put( "w" , _w );
247282
}

0 commit comments

Comments
 (0)