Class CancellationManager

  • All Implemented Interfaces:
    Disposable

    public final class CancellationManager
    extends java.lang.Object
    implements Disposable
    This is general abstraction to make 5 main functions: 1) Create cancellation point for specific database; Locks global mutex in readLock mode; Locks database-related mutex in readLock mode; 2) Execute exclusive database operation for specific database; Locks global mutex in readLock mode; Locks database-related mutex in writeLock mode; So it is impossible to create new cancellation point or to execute critical section while this lock is acquired; 3) Unregister cancellation point; Does not have locks with other operations; 4) Cancel cancellation points; Does not have locks with other operations; 5) Dispose cancellation manager (for all databases); Locks global mutex in write lock mode; It will be impossible to run all parallel methods during dispose;
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()
      Cancel all registered cancellation points;
      void cancel​(java.lang.String theDatabaseName)
      Cancel all registered cancellation points for the specific database.
      int countCancellationPoint​(java.lang.String db)  
      void dispose()
      Dispose cancellation manager; It cancels all active cancellation points and cleanup all resources;
      <T> T executeExclusiveDatabaseOperation​(java.lang.String theDatabaseName, java.lang.String theProcessDescription, java.lang.Runnable theForceClose, CancellationManager.CheckedFunction<CancellationPoint,​T> theWorker)
      Executes database-critical operation; Creates a cancellation point which may be used to cancel the operation.
      <T> T executeExclusiveDatabaseOperation​(java.lang.String theDatabaseName, java.lang.String theProcessDescription, java.lang.Runnable theForceClose, java.util.concurrent.Callable<T> theWorker)
      Executes database-critical operation; It acquires global lock in shared mode; It acquires local per-db lock in exclusive mode;
      <T> T executeExclusiveDatabaseOperation​(java.lang.String theDatabaseName, java.lang.String theProcessDescription, java.util.concurrent.Callable<T> theWorker)  
      void predisposed()  
      CancellationPoint registerCancellationPoint​(java.lang.String theCancellationMessage, java.lang.String theDatabaseName)
      Register cancellation point with default thrower;
      CancellationPoint registerCancellationPoint​(java.lang.String theCancellationMessage, java.lang.String theDatabaseName, java.util.function.Function<java.lang.String,​? extends java.lang.RuntimeException> theCancellationThrower)
      This method is used to register new cancellation point;
      void registerDatabase​(java.lang.String theDatabaseName)
      Register database in the system;
      void unregisterDatabase​(java.lang.String theDatabaseName)
      De-register database;
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CancellationManager

        public CancellationManager()
      • CancellationManager

        public CancellationManager​(int cancelTimeoutMs,
                                   int databaseLockTimeoutMs,
                                   int disposeTimeoutMs)
    • Method Detail

      • registerCancellationPoint

        public CancellationPoint registerCancellationPoint​(java.lang.String theCancellationMessage,
                                                           java.lang.String theDatabaseName)
        Register cancellation point with default thrower;
        Parameters:
        theCancellationMessage - - the cancellation message;
        theDatabaseName - - the database name;
        Returns:
        created cancellation point;
      • registerCancellationPoint

        public CancellationPoint registerCancellationPoint​(java.lang.String theCancellationMessage,
                                                           java.lang.String theDatabaseName,
                                                           java.util.function.Function<java.lang.String,​? extends java.lang.RuntimeException> theCancellationThrower)
        This method is used to register new cancellation point;
        Parameters:
        theCancellationMessage - - the new cancellation message;
        theDatabaseName - - the database name;
        theCancellationThrower - - the thrower which will be used;
        Returns:
        created cancellation point;
      • registerDatabase

        public void registerDatabase​(java.lang.String theDatabaseName)
        Register database in the system;
        Parameters:
        theDatabaseName - - the database name;
      • unregisterDatabase

        public void unregisterDatabase​(java.lang.String theDatabaseName)
        De-register database;
        Parameters:
        theDatabaseName - - the database name;
      • executeExclusiveDatabaseOperation

        public <T> T executeExclusiveDatabaseOperation​(java.lang.String theDatabaseName,
                                                       java.lang.String theProcessDescription,
                                                       java.lang.Runnable theForceClose,
                                                       java.util.concurrent.Callable<T> theWorker)
        Executes database-critical operation; It acquires global lock in shared mode; It acquires local per-db lock in exclusive mode;
        Parameters:
        theDatabaseName - - the database name;
        theProcessDescription - - the description of process;
        theForceClose - - Callback if not all CPs close after a timeout
        theWorker - - the worked for execution;
        Returns:
        the result of the Worker's call;
      • executeExclusiveDatabaseOperation

        public <T> T executeExclusiveDatabaseOperation​(java.lang.String theDatabaseName,
                                                       java.lang.String theProcessDescription,
                                                       java.lang.Runnable theForceClose,
                                                       CancellationManager.CheckedFunction<CancellationPoint,​T> theWorker)
        Executes database-critical operation; Creates a cancellation point which may be used to cancel the operation. It is not possible to create any new Cancellation Points before this method returns. It acquires global lock in shared mode; It acquires local per-db lock in exclusive mode;
        Parameters:
        theForceClose - callback if there are remaining CPs not closed after a timeout.
        theWorker - the callable which will be executed with the CP
        See Also:
        executeExclusiveDatabaseOperation(String, String, Callable)
      • cancel

        public void cancel()
        Cancel all registered cancellation points;
      • predisposed

        public void predisposed()
      • cancel

        public void cancel​(java.lang.String theDatabaseName)
        Cancel all registered cancellation points for the specific database.
        Parameters:
        theDatabaseName - - the database's name;
      • dispose

        public void dispose()
        Dispose cancellation manager; It cancels all active cancellation points and cleanup all resources;
        Specified by:
        dispose in interface Disposable
      • countCancellationPoint

        public int countCancellationPoint​(java.lang.String db)