Class MainDriver<R extends io.vena.bosk.StateTreeNode>
- All Implemented Interfaces:
io.vena.bosk.BoskDriver<R>,MongoDriver<R>
MongoDriver.factory(com.mongodb.MongoClientSettings, io.vena.bosk.drivers.mongo.MongoDriverSettings, io.vena.bosk.drivers.mongo.BsonPlugin).
This class implements the fault tolerance framework in cooperation with ChangeReceiver.
It's mostly exception handling code and diagnostics.
The actual database interactions used to implement the BoskDriver methods,
as well as most interactions with the downstream driver,
are delegated to a FormatDriver object that can be swapped out dynamically
as the database evolves.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.vena.bosk.drivers.mongo.MongoDriver
MongoDriver.MongoDriverFactory<RR extends io.vena.bosk.StateTreeNode> -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMainDriver(io.vena.bosk.Bosk<R> bosk, com.mongodb.MongoClientSettings clientSettings, MongoDriverSettings driverSettings, BsonPlugin bsonPlugin, io.vena.bosk.BoskDriver<R> downstream) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Frees up resources used by this driver and leaves it unusable.voidflush()initialRoot(Type rootType) voidDeserializes and re-serializes the entire bosk contents, thus updating the database to match the current serialized format.<T> voidsubmitConditionalDeletion(io.vena.bosk.Reference<T> target, io.vena.bosk.Reference<io.vena.bosk.Identifier> precondition, io.vena.bosk.Identifier requiredValue) <T> voidsubmitConditionalReplacement(io.vena.bosk.Reference<T> target, T newValue, io.vena.bosk.Reference<io.vena.bosk.Identifier> precondition, io.vena.bosk.Identifier requiredValue) <T> voidsubmitDeletion(io.vena.bosk.Reference<T> target) <T> voidsubmitInitialization(io.vena.bosk.Reference<T> target, T newValue) <T> voidsubmitReplacement(io.vena.bosk.Reference<T> target, T newValue) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.vena.bosk.BoskDriver
submitReplacement
-
Field Details
-
COLLECTION_NAME
- See Also:
-
MANIFEST_ID
public static final org.bson.BsonString MANIFEST_ID
-
-
Constructor Details
-
MainDriver
public MainDriver(io.vena.bosk.Bosk<R> bosk, com.mongodb.MongoClientSettings clientSettings, MongoDriverSettings driverSettings, BsonPlugin bsonPlugin, io.vena.bosk.BoskDriver<R> downstream)
-
-
Method Details
-
initialRoot
public R initialRoot(Type rootType) throws io.vena.bosk.exceptions.InvalidTypeException, InterruptedException, IOException - Specified by:
initialRootin interfaceio.vena.bosk.BoskDriver<R extends io.vena.bosk.StateTreeNode>- Throws:
io.vena.bosk.exceptions.InvalidTypeExceptionInterruptedExceptionIOException
-
submitReplacement
public <T> void submitReplacement(io.vena.bosk.Reference<T> target, T newValue) - Specified by:
submitReplacementin interfaceio.vena.bosk.BoskDriver<R extends io.vena.bosk.StateTreeNode>
-
submitConditionalReplacement
public <T> void submitConditionalReplacement(io.vena.bosk.Reference<T> target, T newValue, io.vena.bosk.Reference<io.vena.bosk.Identifier> precondition, io.vena.bosk.Identifier requiredValue) - Specified by:
submitConditionalReplacementin interfaceio.vena.bosk.BoskDriver<R extends io.vena.bosk.StateTreeNode>
-
submitInitialization
public <T> void submitInitialization(io.vena.bosk.Reference<T> target, T newValue) - Specified by:
submitInitializationin interfaceio.vena.bosk.BoskDriver<R extends io.vena.bosk.StateTreeNode>
-
submitDeletion
public <T> void submitDeletion(io.vena.bosk.Reference<T> target) - Specified by:
submitDeletionin interfaceio.vena.bosk.BoskDriver<R extends io.vena.bosk.StateTreeNode>
-
submitConditionalDeletion
public <T> void submitConditionalDeletion(io.vena.bosk.Reference<T> target, io.vena.bosk.Reference<io.vena.bosk.Identifier> precondition, io.vena.bosk.Identifier requiredValue) - Specified by:
submitConditionalDeletionin interfaceio.vena.bosk.BoskDriver<R extends io.vena.bosk.StateTreeNode>
-
flush
- Specified by:
flushin interfaceio.vena.bosk.BoskDriver<R extends io.vena.bosk.StateTreeNode>- Throws:
IOExceptionInterruptedException
-
refurbish
Description copied from interface:MongoDriverDeserializes and re-serializes the entire bosk contents, thus updating the database to match the current serialized format.Used to "upgrade" the database contents for schema evolution.
This method does not simply write the current in-memory bosk contents back into the database, because that would lead to race conditions with other update operations. Instead, in a causally-consistent transaction, it reads the current database state, deserializes it, re-serializes it, and writes it back. This produces predictable results even if done concurrently with other database updates.
This requires the database state to be in good condition at the outset; it can't generally be used to repair corrupted databases unless the corruption is so mild that it doesn't interfere with proper functioning beforehand. It can be expected to evolve the database from that of a supported prior format, but for unsupported formats or other corruption, YMMV.
- Specified by:
refurbishin interfaceMongoDriver<R extends io.vena.bosk.StateTreeNode>- Throws:
IOException
-
close
public void close()Description copied from interface:MongoDriverFrees up resources used by this driver and leaves it unusable.This is done on a best-effort basis. It's more useful for tests than for production code, where there's usually no reason to close a driver.
- Specified by:
closein interfaceMongoDriver<R extends io.vena.bosk.StateTreeNode>
-