Serializable
WriteConcern.Majority
@Immutable public class WriteConcern extends Object implements 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 | Description |
---|---|---|
static class |
WriteConcern.Majority |
Deprecated.
|
Modifier and Type | Field | 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 | 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(String w) |
Construct an instance with the given tag set-based value for w.
|
WriteConcern(String w,
int wTimeoutMS,
boolean fsync,
boolean journal) |
Deprecated.
|
Modifier and Type | Method | Description |
---|---|---|
BsonDocument |
asDocument() |
Gets this write concern as a document.
|
boolean |
callGetLastError() |
Deprecated.
Prefer
isAcknowledged() |
boolean |
equals(Object o) |
|
boolean |
fsync() |
Deprecated.
Prefer
getJournal() |
boolean |
getFsync() |
Deprecated.
Prefer
getJournal() |
boolean |
getJ() |
Deprecated.
Prefer
getJournal() |
Boolean |
getJournal() |
Gets the journal property.
|
int |
getW() |
Gets the w value as an integer.
|
Object |
getWObject() |
Gets the w value.
|
String |
getWString() |
Gets the w parameter as a String.
|
int |
getWtimeout() |
Deprecated.
Prefer
getWTimeout(TimeUnit) |
Integer |
getWTimeout(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.
|
String |
toString() |
|
static WriteConcern |
valueOf(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(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(String w) |
Constructs a new WriteConcern from the current one and the specified tag-set based value for w
|
WriteConcern |
withWTimeout(long wTimeout,
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(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(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 Object getWObject()
public int getW()
IllegalStateException
- if w is null or not an integerpublic String getWString()
IllegalStateException
- if w is null or not a String@Nullable public Integer getWTimeout(TimeUnit timeUnit)
timeUnit
- the non-null time unit for the result@Deprecated public int getWtimeout()
getWTimeout(TimeUnit)
public 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(String name)
name
- the name of the WriteConcernWriteConcern instance
public WriteConcern withW(int w)
w
- number of servers to ensure write propagation to before acknowledgment, which must be >= 0
public WriteConcern withW(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(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, 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