public final class RestartableMongoClient extends java.lang.Object implements MongoClient
The MongoClient GORM creates for a connection. It is a stable handle on a driver client that it builds only when it is needed, and that it can close and build again without the handle itself changing.
The driver connects as soon as a client exists: creating one starts the monitors that open
sockets to every server it was given. So this builds its driver client the first time it is
used, or when start() asks for it, and not before. A datastore built while an
application context refreshes therefore holds no socket until its lifecycle starts it, which is
what lets the process be checkpointed with CRaC as the context refreshes
(spring.context.checkpoint=onRefresh).
stop() closes the driver client, which releases every socket it held, and the handle
refuses to be used until start() builds a new one. Whatever holds the handle - the
mongo bean, a service it was injected into, a Spring Data MongoDatabaseFactory -
goes on working after a checkpoint and restore without being told anything. A
MongoDatabase, ClientSession or other object obtained from the handle belongs to
the driver client it came from, so it is closed with it.
close() is final: the driver client is closed and the handle cannot be started again.
| Constructor and description |
|---|
RestartableMongoClient(java.lang.String name, java.util.function.Supplier<MongoClient> clientFactory)
|
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
appendMetadata(MongoDriverInformation mongoDriverInformation) |
|
public ClientBulkWriteResult |
bulkWrite(java.util.List<? extends ClientNamespacedWriteModel> models) |
|
public ClientBulkWriteResult |
bulkWrite(java.util.List<? extends ClientNamespacedWriteModel> models, ClientBulkWriteOptions options) |
|
public ClientBulkWriteResult |
bulkWrite(ClientSession clientSession, java.util.List<? extends ClientNamespacedWriteModel> models) |
|
public ClientBulkWriteResult |
bulkWrite(ClientSession clientSession, java.util.List<? extends ClientNamespacedWriteModel> models, ClientBulkWriteOptions options) |
|
public void |
close()Closes the driver client for good. |
|
public ClusterDescription |
getClusterDescription() |
|
public CodecRegistry |
getCodecRegistry() |
|
public MongoDatabase |
getDatabase(java.lang.String databaseName) |
|
public java.lang.String |
getName()
|
|
public ReadConcern |
getReadConcern() |
|
public ReadPreference |
getReadPreference() |
|
public java.lang.Long |
getTimeout(java.util.concurrent.TimeUnit timeUnit) |
|
public WriteConcern |
getWriteConcern() |
|
public boolean |
isConnected()
|
|
public MongoIterable<java.lang.String> |
listDatabaseNames() |
|
public MongoIterable<java.lang.String> |
listDatabaseNames(ClientSession clientSession) |
|
public ListDatabasesIterable<Document> |
listDatabases() |
|
public ListDatabasesIterable<Document> |
listDatabases(ClientSession clientSession) |
<TResult> |
public ListDatabasesIterable<TResult> |
listDatabases(java.lang.Class<TResult> resultClass) |
<TResult> |
public ListDatabasesIterable<TResult> |
listDatabases(ClientSession clientSession, java.lang.Class<TResult> resultClass) |
|
public void |
start()Builds the driver client now, unless there already is one. |
|
public ClientSession |
startSession() |
|
public ClientSession |
startSession(ClientSessionOptions options) |
|
public void |
stop()Closes the driver client, which releases its sockets, and refuses every use of the handle until start() builds a new one. |
|
public java.lang.String |
toString() |
|
public ChangeStreamIterable<Document> |
watch() |
<TResult> |
public ChangeStreamIterable<TResult> |
watch(java.lang.Class<TResult> resultClass) |
|
public ChangeStreamIterable<Document> |
watch(java.util.List<? extends Bson> pipeline) |
<TResult> |
public ChangeStreamIterable<TResult> |
watch(java.util.List<? extends Bson> pipeline, java.lang.Class<TResult> resultClass) |
|
public ChangeStreamIterable<Document> |
watch(ClientSession clientSession) |
<TResult> |
public ChangeStreamIterable<TResult> |
watch(ClientSession clientSession, java.lang.Class<TResult> resultClass) |
|
public ChangeStreamIterable<Document> |
watch(ClientSession clientSession, java.util.List<? extends Bson> pipeline) |
<TResult> |
public ChangeStreamIterable<TResult> |
watch(ClientSession clientSession, java.util.List<? extends Bson> pipeline, java.lang.Class<TResult> resultClass) |
|
public MongoCluster |
withCodecRegistry(CodecRegistry codecRegistry) |
|
public MongoCluster |
withReadConcern(ReadConcern readConcern) |
|
public MongoCluster |
withReadPreference(ReadPreference readPreference) |
|
public MongoCluster |
withTimeout(long timeout, java.util.concurrent.TimeUnit timeUnit) |
|
public MongoCluster |
withWriteConcern(WriteConcern writeConcern) |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
name - the name of the connection the client is for, which is what its messages nameclientFactory - builds a driver client each time one is neededCloses the driver client for good. Closing again does nothing.
Builds the driver client now, unless there already is one. A handle that stop() stopped is usable again from here on.
Closes the driver client, which releases its sockets, and refuses every use of the handle until start() builds a new one. Stopping a handle that was never used builds nothing.