Class ScottyDBStorage

    • Constructor Detail

      • ScottyDBStorage

        public ScottyDBStorage()
    • Method Detail

      • setClocksAllowedDeltaMSec

        public void setClocksAllowedDeltaMSec​(int clocksAllowedDeltaMSec)
      • setClocksCheckIntervalSeconds

        public void setClocksCheckIntervalSeconds​(int clocksCheckIntervalSeconds)
      • setCheckDbConsistencyAtStartup

        public void setCheckDbConsistencyAtStartup​(boolean checkDbConsistencyAtStartup)
      • setTransactionController

        public void setTransactionController​(TransactionController transactionController)
      • run

        protected <T> T run​(DatabaseTransaction<T> txn)
                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setBatcher

        public void setBatcher​(Batcher batcher)
      • setDeleteStaleResponsesIntervalMsec

        public void setDeleteStaleResponsesIntervalMsec​(long deleteStaleResponsesIntervalMsec)
        Sets the time period after which early responses without a corresponding wait-call are removed from the database.
        Parameters:
        deleteStaleResponsesIntervalMsec - time period in milliseconds
      • setWaitForEnqueueMSec

        public void setWaitForEnqueueMSec​(int waitForEnqueueMSec)
      • insert

        public void insert​(Workflow<?> wf,
                           Acknowledge ack)
                    throws java.lang.Exception
        Description copied from interface: ScottyDBStorageInterface
        Inserts a new workflow to the underlying database. The implementation may execute the inserts outside the callers context. The completion will be signalled through the Acknowledge object.
        Specified by:
        insert in interface ScottyDBStorageInterface
        Parameters:
        wf - workflow to be inserted
        ack - acknowledgment to notify about success or exception.
        Throws:
        DuplicateIdException - If a workflow with the same id as the id of wf is already stored in the database.
        java.lang.Exception - For all kinds of other exceptions like losing database connection
      • insert

        public void insert​(java.util.List<Workflow<?>> wfs,
                           Acknowledge ack)
                    throws java.lang.Exception
        Description copied from interface: ScottyDBStorageInterface
        Inserts a list of new workflows to the underlying database. The implementation may execute the inserts outside the callers context. The completion will be signalled through the Acknowledge object.
        Specified by:
        insert in interface ScottyDBStorageInterface
        Parameters:
        wfs - workflows to be inserted
        ack - acknowledgment to notify about success or exception.
        Throws:
        DuplicateIdException - If a workflow with the same id as the id of wf is already stored in the database.
        java.lang.Exception - For all kinds of other exceptions like losing database connection
      • dequeue

        public java.util.List<Workflow<?>> dequeue​(java.lang.String ppoolId,
                                                   int max)
                                            throws java.lang.Exception
        Description copied from interface: ScottyDBStorageInterface
        Dequeues up to max Workflow instances for the specified processor pool from the database. It dequeues only such workflow instances that need further processing, e.g. when a response arrived or a timeout occured.
        Specified by:
        dequeue in interface ScottyDBStorageInterface
        Parameters:
        ppoolId - the processor pool id of the processor pool to which the workflows shall be dequeued
        max - maximum number of workflows which shall be dequeud by this call
        Returns:
        List of workflows dequeued from database storage
        Throws:
        java.lang.Exception - Any exception which could happen in this procedure like losing database connection.
      • notify

        public void notify​(java.util.List<Response<?>> response,
                           Acknowledge ack)
                    throws java.lang.Exception
        Description copied from interface: ScottyDBStorageInterface
        Asynchronous service to add a list of Responses to the database.
        Specified by:
        notify in interface ScottyDBStorageInterface
        Parameters:
        response - the list of responses for which each holds the correlation ID (required to know which workflow is to be waken up if all wait- conditions are met) and the data which shall be provided to the workflow
        ack - An Acknowledge which is notified after a successful operation run or about the exception which occured otherwise.
        Throws:
        java.lang.Exception - Any exception which could happen in this procedure like losing database connection.
      • insert

        public void insert​(Workflow<?> wf,
                           java.sql.Connection con)
                    throws java.lang.Exception
        Description copied from interface: ScottyDBStorageInterface
        Inserts a new workflow to the underlying database using the provided connection. It is up to the caller commit or rollback and close the connection.
        Specified by:
        insert in interface ScottyDBStorageInterface
        Parameters:
        wf - workflow to be inserted
        con - Connection object on which insertion shall happen. With connection as parameter, the caller get full commit/rollback control and can thus make use of stronger insertion guarantees than possible with using Acknowledgments only.
        Throws:
        DuplicateIdException - If a workflow with the same id as the id of wf is already stored in the database.
        java.lang.Exception - For all kinds of other exceptions like losing database connection
      • insert

        public void insert​(java.util.List<Workflow<?>> wfs,
                           java.sql.Connection con)
                    throws java.lang.Exception
        Description copied from interface: ScottyDBStorageInterface
        Inserts a list of new workflows to the underlying database using the provided connection. It is up to the caller commit or rollback and close the connection.
        Specified by:
        insert in interface ScottyDBStorageInterface
        Parameters:
        wfs - workflows to be inserted
        con - Connection object on which insertion shall happen. With connection as parameter, the caller get full commit/rollback control and can thus make use of stronger insertion guarantees than possible with using Acknowledgments only.
        Throws:
        DuplicateIdException - If a workflow with the same id as the id of wf is already stored in the database.
        java.lang.Exception - For all kinds of other exceptions like losing database connection
      • restart

        public void restart​(java.lang.String workflowInstanceId)
                     throws java.lang.Exception
        Description copied from interface: ScottyDBStorageInterface
        Triggers the restart of a failed workflow instance, i.e. resubmitting the given workflow in DBProcessingState.INVALID or DBProcessingState.ERROR to the queue to (re-)start from last stored execution point.
        Specified by:
        restart in interface ScottyDBStorageInterface
        Parameters:
        workflowInstanceId - workflow id of broken workflow
        Throws:
        java.lang.Exception - Any Exception like losing database connection.
      • deleteBroken

        public void deleteBroken​(java.lang.String workflowInstanceId)
                          throws java.lang.Exception
        Description copied from interface: ScottyDBStorageInterface
        Deletes a broken workflow from the system (i.e. from all tables)
        Specified by:
        deleteBroken in interface ScottyDBStorageInterface
        Parameters:
        workflowInstanceId - workflow id of broken workflow
        Throws:
        java.lang.Exception - when the delete operation fails
      • deleteWaiting

        public void deleteWaiting​(java.lang.String workflowInstanceId)
                           throws java.lang.Exception
        Specified by:
        deleteWaiting in interface ScottyDBStorageInterface
        Throws:
        java.lang.Exception
      • deleteFiltered

        public void deleteFiltered​(org.copperengine.management.model.WorkflowInstanceFilter filter)
                            throws java.lang.Exception
        Specified by:
        deleteFiltered in interface ScottyDBStorageInterface
        Throws:
        java.lang.Exception
      • setRemoveWhenFinished

        public void setRemoveWhenFinished​(boolean removeWhenFinished)
        Specified by:
        setRemoveWhenFinished in interface ScottyDBStorageInterface
        Parameters:
        removeWhenFinished - If true (default), finished workflow instances are removed from the database.
      • notify

        public void notify​(java.util.List<Response<?>> responses,
                           java.sql.Connection c)
                    throws java.lang.Exception
        Description copied from interface: ScottyDBStorageInterface
        Synchronous service to add a list of Responses to the database using a provided database connection.
        Specified by:
        notify in interface ScottyDBStorageInterface
        Parameters:
        responses - the responses for which each holds the correlation ID (required to know which workflow is to be waken up if all wait- conditions are met) and the data which shall be provided to the workflow
        c - Connection object on which notify shall happen. With connection as parameter, the caller get full commit/rollback control and can thus make use of stronger notification-guarantees than possible with using Acknowledgments only.
        Throws:
        java.lang.Exception - Any exception which could happen in this procedure like losing database connection.
      • error

        public void error​(Workflow<?> w,
                          java.lang.Throwable t,
                          Acknowledge callback)
        Description copied from interface: ScottyDBStorageInterface
        Marks a workflow instance as failed in the database. It may me triggered again later when the error cause has been solved using the restart method.
        Specified by:
        error in interface ScottyDBStorageInterface
        Parameters:
        w - The workflow which shall be marked as erroneous
        t - The Throwable which lead the workflow get into this error state.
        callback - callback which notifies about success or error within this operation after it finished.
      • registerCallback

        public void registerCallback​(RegisterCall rc,
                                     Acknowledge callback)
                              throws java.lang.Exception
        Description copied from interface: ScottyDBStorageInterface
        Writes a workflow instance that is waiting for one or more asynchronous response back to database.
        Specified by:
        registerCallback in interface ScottyDBStorageInterface
        Parameters:
        rc - class for holding information about the workflow which shall be updated in its processing state. Holds the workflow itself but also more data like the correlation IDs to wait upon and more. All data required for the database update is stored in here.
        callback - Callback which is called on success or error after this operation finished.
        Throws:
        java.lang.Exception - Any unexpected Exception like losing database connection.
      • notify

        public void notify​(Response<?> response,
                           Acknowledge callback)
                    throws java.lang.Exception
        Description copied from interface: ScottyDBStorageInterface
        Asynchronous service to add a Response to the database. Regarding to our best practices, this method should be called from "outside COPPER" from some user implemented adapter.
        Specified by:
        notify in interface ScottyDBStorageInterface
        Parameters:
        response - the response which holds the correlation ID (required to know which workflow is to be waken up if all wait- conditions are met) and the data which shall be provided to the workflow
        callback - An Acknowledge which is notified after a successful operation run or about the exception which occured otherwise.
        Throws:
        java.lang.Exception - Any exception which could happen in this procedure like losing database connection.
      • getBatcherMXBean

        public org.copperengine.management.BatcherMXBean getBatcherMXBean()
        Specified by:
        getBatcherMXBean in interface org.copperengine.management.ScottyDBStorageMXBean
      • getDatabaseDialectMXBean

        public org.copperengine.management.DatabaseDialectMXBean getDatabaseDialectMXBean()
        Specified by:
        getDatabaseDialectMXBean in interface org.copperengine.management.ScottyDBStorageMXBean
      • getDescription

        public java.lang.String getDescription()
        Specified by:
        getDescription in interface org.copperengine.management.DBStorageMXBean
      • read

        public Workflow<?> read​(java.lang.String workflowInstanceId)
                         throws java.lang.Exception
        Specified by:
        read in interface ScottyDBStorageInterface
        Throws:
        java.lang.Exception
      • queryAllActive

        public java.util.List<Workflow<?>> queryAllActive​(java.lang.String className,
                                                          int max)
                                                   throws java.lang.Exception
        Description copied from interface: ScottyDBStorageInterface
        Query all active workflowinstances from the backing storage
        Specified by:
        queryAllActive in interface ScottyDBStorageInterface
        Parameters:
        className - optional - className of the active workflow instances
        max - limits the number of Workflow instances to read
        Returns:
        list of deserialized workflow instance
        Throws:
        java.lang.Exception - Any Exception like losing database connection.
      • queryQueueSize

        public int queryQueueSize​(java.lang.String processorPoolId)
                           throws java.lang.Exception
        Specified by:
        queryQueueSize in interface ScottyDBStorageInterface
        Throws:
        java.lang.Exception
      • queryObjectState

        public java.lang.String queryObjectState​(java.lang.String id)
                                          throws java.lang.Exception
        Specified by:
        queryObjectState in interface ScottyDBStorageInterface
        Throws:
        java.lang.Exception
      • queryWorkflowInstances

        public java.util.List<Workflow<?>> queryWorkflowInstances​(org.copperengine.management.model.WorkflowInstanceFilter filter)
                                                           throws java.lang.Exception
        Specified by:
        queryWorkflowInstances in interface ScottyDBStorageInterface
        Throws:
        java.lang.Exception
      • countWorkflowInstances

        public int countWorkflowInstances​(org.copperengine.management.model.WorkflowInstanceFilter filter)
                                   throws java.lang.Exception
        Specified by:
        countWorkflowInstances in interface ScottyDBStorageInterface
        Throws:
        java.lang.Exception
      • queryAuditTrailInstances

        public java.util.List<org.copperengine.management.model.AuditTrailInfo> queryAuditTrailInstances​(org.copperengine.management.model.AuditTrailInstanceFilter filter)
                                                                                                  throws java.lang.Exception
        Specified by:
        queryAuditTrailInstances in interface ScottyDBStorageInterface
        Throws:
        java.lang.Exception
      • countAuditTrailInstances

        public int countAuditTrailInstances​(org.copperengine.management.model.AuditTrailInstanceFilter filter)
                                     throws java.lang.Exception
        Specified by:
        countAuditTrailInstances in interface ScottyDBStorageInterface
        Throws:
        java.lang.Exception