@Immutable public class WriteConcern extends java.lang.Object implements java.io.Serializable
Controls the acknowledgment of write operations with various options.
w
wtimeout
- how long to wait for secondaries to acknowledge before failing
Other options:
journal
: If true block until write operations have been committed to the journal. Cannot be used in combination with
fsync
. Prior to MongoDB 2.6 this option was ignored if the server was running without journaling. Starting with MongoDB 2.6
write operations will fail with an exception if this option is used when the server is running without journaling.Modifier and Type | Class and Description |
---|---|
static class |
WriteConcern.Majority
Deprecated.
|
Modifier and Type | Field and Description |
---|---|
static WriteConcern |
ACKNOWLEDGED
Write operations that use this write concern will wait for acknowledgement, using the default write concern configured on the server.
|
static WriteConcern |
FSYNC_SAFE
Deprecated.
Prefer
JOURNALED |
static WriteConcern |
FSYNCED
Deprecated.
Prefer
JOURNALED |
static WriteConcern |
JOURNAL_SAFE
Deprecated.
Prefer
JOURNALED |
static WriteConcern |
JOURNALED
Write operations wait for the server to group commit to the journal file on disk.
|
static WriteConcern |
MAJORITY
Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation.
|
static WriteConcern |
NORMAL
Deprecated.
Prefer
UNACKNOWLEDGED |
static WriteConcern |
REPLICA_ACKNOWLEDGED
Deprecated.
Prefer WriteConcern#W2
|
static WriteConcern |
REPLICAS_SAFE
Deprecated.
Prefer
W2 |
static WriteConcern |
SAFE
Deprecated.
Prefer
ACKNOWLEDGED |
static WriteConcern |
UNACKNOWLEDGED
Write operations that use this write concern will return as soon as the message is written to the socket.
|
static WriteConcern |
W1
Write operations that use this write concern will wait for acknowledgement from a single member.
|
static WriteConcern |
W2
Write operations that use this write concern will wait for acknowledgement from two members.
|
static WriteConcern |
W3
Write operations that use this write concern will wait for acknowledgement from three members.
|
Constructor and Description |
---|
WriteConcern()
Deprecated.
Prefer
UNACKNOWLEDGED |
WriteConcern(boolean fsync)
Deprecated.
prefer
JOURNALED or withJournal(Boolean) |
WriteConcern(int w)
Construct an instance with the given integer-based value for w.
|
WriteConcern(int w,
int wTimeoutMS)
Constructs an instance with the given integer-based value for w and the given value for wTimeoutMS.
|
WriteConcern(int w,
int wTimeoutMS,
boolean fsync)
Deprecated.
|
WriteConcern(int w,
int wTimeoutMS,
boolean fsync,
boolean journal)
Deprecated.
|
WriteConcern(java.lang.String w)
Construct an instance with the given tag set-based value for w.
|
WriteConcern(java.lang.String w,
int wTimeoutMS,
boolean fsync,
boolean journal)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
BsonDocument |
asDocument()
Gets this write concern as a document.
|
boolean |
callGetLastError()
Deprecated.
Prefer
isAcknowledged() |
boolean |
equals(java.lang.Object o) |
boolean |
fsync()
Deprecated.
Prefer
getJournal() |
boolean |
getFsync()
Deprecated.
Prefer
getJournal() |
boolean |
getJ()
Deprecated.
Prefer
getJournal() |
java.lang.Boolean |
getJournal()
Gets the journal property.
|
int |
getW()
Gets the w value as an integer.
|
java.lang.Object |
getWObject()
Gets the w value.
|
java.lang.String |
getWString()
Gets the w parameter as a String.
|
int |
getWtimeout()
Deprecated.
Prefer
getWTimeout(TimeUnit) |
java.lang.Integer |
getWTimeout(java.util.concurrent.TimeUnit timeUnit)
Gets the wTimeout in the given time unit.
|
int |
hashCode() |
boolean |
isAcknowledged()
Returns true if this write concern indicates that write operations must be acknowledged.
|
boolean |
isServerDefault()
Gets whether this write concern indicates that the server's default write concern will be used.
|
static WriteConcern.Majority |
majorityWriteConcern(int wtimeout,
boolean fsync,
boolean j)
Deprecated.
|
java.lang.String |
toString() |
static WriteConcern |
valueOf(java.lang.String name)
Gets the WriteConcern constants by name (matching is done case insensitively).
|
WriteConcern |
withFsync(boolean fsync)
Deprecated.
Prefer
withJournal(Boolean) |
WriteConcern |
withJ(boolean journal)
Deprecated.
Prefer
withJournal(Boolean) |
WriteConcern |
withJournal(java.lang.Boolean journal)
Constructs a new WriteConcern from the current one and the specified journal value
|
WriteConcern |
withW(int w)
Constructs a new WriteConcern from the current one and the specified integer-based value for w
|
WriteConcern |
withW(java.lang.String w)
Constructs a new WriteConcern from the current one and the specified tag-set based value for w
|
WriteConcern |
withWTimeout(long wTimeout,
java.util.concurrent.TimeUnit timeUnit)
Constructs a new WriteConcern from the current one and the specified wTimeout in the given time unit.
|
public static final WriteConcern ACKNOWLEDGED
public static final WriteConcern W1
public static final WriteConcern W2
public static final WriteConcern W3
public static final WriteConcern UNACKNOWLEDGED
@Deprecated public static final WriteConcern FSYNCED
JOURNALED
public static final WriteConcern JOURNALED
@Deprecated public static final WriteConcern REPLICA_ACKNOWLEDGED
@Deprecated public static final WriteConcern NORMAL
UNACKNOWLEDGED
Write operations that use this write concern will return as soon as the message is written to the socket. Exceptions are raised for network issues, but not server errors.
This field has been superseded by WriteConcern.UNACKNOWLEDGED
, and may be deprecated in a future release.
UNACKNOWLEDGED
@Deprecated public static final WriteConcern SAFE
ACKNOWLEDGED
Write operations that use this write concern will wait for acknowledgement from the primary server before returning. Exceptions are raised for network issues, and server errors.
This field has been superseded by WriteConcern.ACKNOWLEDGED
, and may be deprecated in a future release.
ACKNOWLEDGED
public static final WriteConcern MAJORITY
@Deprecated public static final WriteConcern FSYNC_SAFE
JOURNALED
Exceptions are raised for network issues, and server errors; the write operation waits for the server to flush the data to disk.
This field has been superseded by WriteConcern.FSYNCED
, and may be deprecated in a future release.
FSYNCED
@Deprecated public static final WriteConcern JOURNAL_SAFE
JOURNALED
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.
This field has been superseded by WriteConcern.JOURNALED
, and may be deprecated in a future release.
@Deprecated public static final WriteConcern REPLICAS_SAFE
W2
Exceptions are raised for network issues, and server errors; waits for at least 2 servers for the write operation.
This field has been superseded by WriteConcern.REPLICA_ACKNOWLEDGED
, and may be deprecated in a future release.
W2
@Deprecated public WriteConcern()
UNACKNOWLEDGED
WriteConcern#UNACKNOWLEDGED
UNACKNOWLEDGED
public WriteConcern(int w)
w
- number of servers to ensure write propagation to before acknowledgment, which must be >= 0
public WriteConcern(java.lang.String w)
public WriteConcern(int w, int wTimeoutMS)
w
- the w value, which must be >= 0wTimeoutMS
- the wTimeout in milliseconds, which must be >= 0@Deprecated public WriteConcern(boolean fsync)
JOURNALED
or withJournal(Boolean)
fsync
- whether or not to fsync@Deprecated public WriteConcern(int w, int wTimeoutMS, boolean fsync)
withW(int)
, withWTimeout(long, TimeUnit)
, withJournal(Boolean)
w
- the w value, which must be >= 0wTimeoutMS
- the wTimeout in milliseconds, which must be >= 0fsync
- whether or not to fsync@Deprecated public WriteConcern(int w, int wTimeoutMS, boolean fsync, boolean journal)
withW(int)
, withWTimeout(long, TimeUnit)
, withJournal(Boolean)
w
- the w value, which must be >= 0wTimeoutMS
- the wTimeout in milliseconds, which must be >= 0fsync
- whether or not to fsyncjournal
- whether writes should wait for a journaling group commit@Deprecated public WriteConcern(java.lang.String w, int wTimeoutMS, boolean fsync, boolean journal)
withW(String)
, withWTimeout(long, TimeUnit)
, withJournal(Boolean)
w
- the w value, which must be non-nullwTimeoutMS
- the wTimeout in milliseconds, which must be >= 0fsync
- whether or not to fsyncjournal
- whether writes should wait for a journaling group commitpublic java.lang.Object getWObject()
public int getW()
java.lang.IllegalStateException
- if w is null or not an integerpublic java.lang.String getWString()
java.lang.IllegalStateException
- if w is null or not a Stringpublic java.lang.Integer getWTimeout(java.util.concurrent.TimeUnit timeUnit)
timeUnit
- the non-null time unit for the result@Deprecated public int getWtimeout()
getWTimeout(TimeUnit)
public java.lang.Boolean getJournal()
@Deprecated public boolean getJ()
getJournal()
@Deprecated public boolean getFsync()
getJournal()
@Deprecated public boolean fsync()
getJournal()
@Deprecated public boolean callGetLastError()
isAcknowledged()
public boolean isServerDefault()
public BsonDocument asDocument()
w <= 0
public boolean isAcknowledged()
public static WriteConcern valueOf(java.lang.String name)
name
- the name of the WriteConcernWriteConcern instance
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public WriteConcern withW(int w)
w
- number of servers to ensure write propagation to before acknowledgment, which must be >= 0
public WriteConcern withW(java.lang.String w)
w
- tag set, or "majority", representing the servers to ensure write propagation to before acknowledgment. Do not use string
representation of integer values for wwithW(int)
@Deprecated public WriteConcern withFsync(boolean fsync)
withJournal(Boolean)
fsync
- true if the write concern needs to include fsyncpublic WriteConcern withJournal(java.lang.Boolean journal)
journal
- true if journalling is required for acknowledgement, false if not, or null if unspecified@Deprecated public WriteConcern withJ(boolean journal)
withJournal(Boolean)
journal
- true if journalling is required for acknowledgementpublic WriteConcern withWTimeout(long wTimeout, java.util.concurrent.TimeUnit timeUnit)
wTimeout
- the wTimeout, which must be >= 0 and <= Integer.MAX_VALUE after conversion to millisecondstimeUnit
- the non-null time unit to apply to wTimeout@Deprecated public static WriteConcern.Majority majorityWriteConcern(int wtimeout, boolean fsync, boolean j)
MAJORITY
, withWTimeout(long, TimeUnit)
, withJournal(Boolean)
wtimeout
- timeout for write operationfsync
- whether or not to fsyncj
- whether writes should wait for a journal group commit