Class MainDriver<R extends io.vena.bosk.StateTreeNode>

java.lang.Object
io.vena.bosk.drivers.mongo.MainDriver<R>
All Implemented Interfaces:
io.vena.bosk.BoskDriver<R>, MongoDriver<R>

public class MainDriver<R extends io.vena.bosk.StateTreeNode> extends Object implements MongoDriver<R>
This is the driver returned to the user by 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
    Modifier and Type
    Field
    Description
    static final String
     
    static final org.bson.BsonString
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    MainDriver(io.vena.bosk.Bosk<R> bosk, com.mongodb.MongoClientSettings clientSettings, MongoDriverSettings driverSettings, BsonPlugin bsonPlugin, io.vena.bosk.BoskDriver<R> downstream)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Frees up resources used by this driver and leaves it unusable.
    void
     
    initialRoot(Type rootType)
     
    void
    Deserializes and re-serializes the entire bosk contents, thus updating the database to match the current serialized format.
    <T> void
    submitConditionalDeletion(io.vena.bosk.Reference<T> target, io.vena.bosk.Reference<io.vena.bosk.Identifier> precondition, io.vena.bosk.Identifier requiredValue)
     
    <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)
     
    <T> void
    submitDeletion(io.vena.bosk.Reference<T> target)
     
    <T> void
    submitInitialization(io.vena.bosk.Reference<T> target, T newValue)
     
    <T> void
    submitReplacement(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, wait

    Methods inherited from interface io.vena.bosk.BoskDriver

    submitReplacement
  • Field Details

    • COLLECTION_NAME

      public static final String 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:
      initialRoot in interface io.vena.bosk.BoskDriver<R extends io.vena.bosk.StateTreeNode>
      Throws:
      io.vena.bosk.exceptions.InvalidTypeException
      InterruptedException
      IOException
    • submitReplacement

      public <T> void submitReplacement(io.vena.bosk.Reference<T> target, T newValue)
      Specified by:
      submitReplacement in interface io.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:
      submitConditionalReplacement in interface io.vena.bosk.BoskDriver<R extends io.vena.bosk.StateTreeNode>
    • submitInitialization

      public <T> void submitInitialization(io.vena.bosk.Reference<T> target, T newValue)
      Specified by:
      submitInitialization in interface io.vena.bosk.BoskDriver<R extends io.vena.bosk.StateTreeNode>
    • submitDeletion

      public <T> void submitDeletion(io.vena.bosk.Reference<T> target)
      Specified by:
      submitDeletion in interface io.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:
      submitConditionalDeletion in interface io.vena.bosk.BoskDriver<R extends io.vena.bosk.StateTreeNode>
    • flush

      public void flush() throws IOException, InterruptedException
      Specified by:
      flush in interface io.vena.bosk.BoskDriver<R extends io.vena.bosk.StateTreeNode>
      Throws:
      IOException
      InterruptedException
    • refurbish

      public void refurbish() throws IOException
      Description copied from interface: MongoDriver
      Deserializes 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:
      refurbish in interface MongoDriver<R extends io.vena.bosk.StateTreeNode>
      Throws:
      IOException
    • close

      public void close()
      Description copied from interface: MongoDriver
      Frees 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:
      close in interface MongoDriver<R extends io.vena.bosk.StateTreeNode>