public final class RestartableMongoClient extends java.lang.Object implements com.mongodb.client.MongoClient
The com.mongodb.client.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
com.mongodb.client.MongoDatabase, com.mongodb.client.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<com.mongodb.client.MongoClient> clientFactory)
|
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
appendMetadata(com.mongodb.MongoDriverInformation mongoDriverInformation) |
|
public com.mongodb.client.model.bulk.ClientBulkWriteResult |
bulkWrite(java.util.List<? extends com.mongodb.client.model.bulk.ClientNamespacedWriteModel> models) |
|
public com.mongodb.client.model.bulk.ClientBulkWriteResult |
bulkWrite(java.util.List<? extends com.mongodb.client.model.bulk.ClientNamespacedWriteModel> models, com.mongodb.client.model.bulk.ClientBulkWriteOptions options) |
|
public com.mongodb.client.model.bulk.ClientBulkWriteResult |
bulkWrite(com.mongodb.client.ClientSession clientSession, java.util.List<? extends com.mongodb.client.model.bulk.ClientNamespacedWriteModel> models) |
|
public com.mongodb.client.model.bulk.ClientBulkWriteResult |
bulkWrite(com.mongodb.client.ClientSession clientSession, java.util.List<? extends com.mongodb.client.model.bulk.ClientNamespacedWriteModel> models, com.mongodb.client.model.bulk.ClientBulkWriteOptions options) |
|
public void |
close()Closes the driver client for good. |
|
public com.mongodb.connection.ClusterDescription |
getClusterDescription() |
|
public org.bson.codecs.configuration.CodecRegistry |
getCodecRegistry() |
|
public com.mongodb.client.MongoDatabase |
getDatabase(java.lang.String databaseName) |
|
public java.lang.String |
getName()
|
|
public com.mongodb.ReadConcern |
getReadConcern() |
|
public com.mongodb.ReadPreference |
getReadPreference() |
|
public java.lang.Long |
getTimeout(java.util.concurrent.TimeUnit timeUnit) |
|
public com.mongodb.WriteConcern |
getWriteConcern() |
|
public boolean |
isConnected()
|
|
public com.mongodb.client.MongoIterable<java.lang.String> |
listDatabaseNames() |
|
public com.mongodb.client.MongoIterable<java.lang.String> |
listDatabaseNames(com.mongodb.client.ClientSession clientSession) |
|
public com.mongodb.client.ListDatabasesIterable<org.bson.Document> |
listDatabases() |
|
public com.mongodb.client.ListDatabasesIterable<org.bson.Document> |
listDatabases(com.mongodb.client.ClientSession clientSession) |
<TResult> |
public com.mongodb.client.ListDatabasesIterable<TResult> |
listDatabases(java.lang.Class<TResult> resultClass) |
<TResult> |
public com.mongodb.client.ListDatabasesIterable<TResult> |
listDatabases(com.mongodb.client.ClientSession clientSession, java.lang.Class<TResult> resultClass) |
|
public void |
start()Builds the driver client now, unless there already is one. |
|
public com.mongodb.client.ClientSession |
startSession() |
|
public com.mongodb.client.ClientSession |
startSession(com.mongodb.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 com.mongodb.client.ChangeStreamIterable<org.bson.Document> |
watch() |
<TResult> |
public com.mongodb.client.ChangeStreamIterable<TResult> |
watch(java.lang.Class<TResult> resultClass) |
|
public com.mongodb.client.ChangeStreamIterable<org.bson.Document> |
watch(java.util.List<? extends org.bson.conversions.Bson> pipeline) |
<TResult> |
public com.mongodb.client.ChangeStreamIterable<TResult> |
watch(java.util.List<? extends org.bson.conversions.Bson> pipeline, java.lang.Class<TResult> resultClass) |
|
public com.mongodb.client.ChangeStreamIterable<org.bson.Document> |
watch(com.mongodb.client.ClientSession clientSession) |
<TResult> |
public com.mongodb.client.ChangeStreamIterable<TResult> |
watch(com.mongodb.client.ClientSession clientSession, java.lang.Class<TResult> resultClass) |
|
public com.mongodb.client.ChangeStreamIterable<org.bson.Document> |
watch(com.mongodb.client.ClientSession clientSession, java.util.List<? extends org.bson.conversions.Bson> pipeline) |
<TResult> |
public com.mongodb.client.ChangeStreamIterable<TResult> |
watch(com.mongodb.client.ClientSession clientSession, java.util.List<? extends org.bson.conversions.Bson> pipeline, java.lang.Class<TResult> resultClass) |
|
public com.mongodb.client.MongoCluster |
withCodecRegistry(org.bson.codecs.configuration.CodecRegistry codecRegistry) |
|
public com.mongodb.client.MongoCluster |
withReadConcern(com.mongodb.ReadConcern readConcern) |
|
public com.mongodb.client.MongoCluster |
withReadPreference(com.mongodb.ReadPreference readPreference) |
|
public com.mongodb.client.MongoCluster |
withTimeout(long timeout, java.util.concurrent.TimeUnit timeUnit) |
|
public com.mongodb.client.MongoCluster |
withWriteConcern(com.mongodb.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.