Package org.copperengine.core.persistent
Class ScottyDBStorage
- java.lang.Object
-
- org.copperengine.core.persistent.ScottyDBStorage
-
- All Implemented Interfaces:
ScottyDBStorageInterface
,org.copperengine.management.DBStorageMXBean
,org.copperengine.management.ScottyDBStorageMXBean
public class ScottyDBStorage extends java.lang.Object implements ScottyDBStorageInterface, org.copperengine.management.ScottyDBStorageMXBean
Implementation of theScottyDBStorageInterface
.
-
-
Constructor Summary
Constructors Constructor Description ScottyDBStorage()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
countAuditTrailInstances(org.copperengine.management.model.AuditTrailInstanceFilter filter)
int
countWorkflowInstances(org.copperengine.management.model.WorkflowInstanceFilter filter)
void
deleteBroken(java.lang.String workflowInstanceId)
Deletes a broken workflow from the system (i.e.void
deleteFiltered(org.copperengine.management.model.WorkflowInstanceFilter filter)
void
deleteWaiting(java.lang.String workflowInstanceId)
java.util.List<Workflow<?>>
dequeue(java.lang.String ppoolId, int max)
Dequeues up tomax
Workflow instances for the specified processor pool from the database.void
error(Workflow<?> w, java.lang.Throwable t, Acknowledge callback)
Marks a workflow instance as failed in the database.void
finish(Workflow<?> w, Acknowledge callback)
Marks a workflow instance as finished or removes it from the underlying database.org.copperengine.management.BatcherMXBean
getBatcherMXBean()
org.copperengine.management.DatabaseDialectMXBean
getDatabaseDialectMXBean()
java.lang.String
getDescription()
void
insert(java.util.List<Workflow<?>> wfs, java.sql.Connection con)
Inserts a list of new workflows to the underlying database using the provided connection.void
insert(java.util.List<Workflow<?>> wfs, Acknowledge ack)
Inserts a list of new workflows to the underlying database.void
insert(Workflow<?> wf, java.sql.Connection con)
Inserts a new workflow to the underlying database using the provided connection.void
insert(Workflow<?> wf, Acknowledge ack)
Inserts a new workflow to the underlying database.void
notify(java.util.List<Response<?>> responses, java.sql.Connection c)
Synchronous service to add a list ofResponse
s to the database using a provided database connection.void
notify(java.util.List<Response<?>> response, Acknowledge ack)
Asynchronous service to add a list ofResponse
s to the database.void
notify(Response<?> response, Acknowledge callback)
Asynchronous service to add aResponse
to the database.java.util.List<Workflow<?>>
queryAllActive(java.lang.String className, int max)
Query all active workflowinstances from the backing storagejava.util.List<org.copperengine.management.model.AuditTrailInfo>
queryAuditTrailInstances(org.copperengine.management.model.AuditTrailInstanceFilter filter)
java.lang.String
queryAuditTrailMessage(long id)
java.lang.String
queryObjectState(java.lang.String id)
int
queryQueueSize(java.lang.String processorPoolId)
java.util.List<Workflow<?>>
queryWorkflowInstances(org.copperengine.management.model.WorkflowInstanceFilter filter)
Workflow<?>
read(java.lang.String workflowInstanceId)
void
registerCallback(RegisterCall rc, Acknowledge callback)
Writes a workflow instance that is waiting for one or more asynchronous response back to database.void
restart(java.lang.String workflowInstanceId)
Triggers the restart of a failed workflow instance, i.e.void
restartAll()
void
restartFiltered(org.copperengine.management.model.WorkflowInstanceFilter filter)
Triggers the restart of all failed workflow instances.protected <T> T
run(DatabaseTransaction<T> txn)
void
setBatcher(Batcher batcher)
void
setCheckDbConsistencyAtStartup(boolean checkDbConsistencyAtStartup)
void
setClocksAllowedDeltaMSec(int clocksAllowedDeltaMSec)
void
setClocksCheckIntervalSeconds(int clocksCheckIntervalSeconds)
void
setDeleteStaleResponsesIntervalMsec(long deleteStaleResponsesIntervalMsec)
Sets the time period after which early responses without a corresponding wait-call are removed from the database.void
setDialect(DatabaseDialect dialect)
void
setRemoveWhenFinished(boolean removeWhenFinished)
void
setTransactionController(TransactionController transactionController)
void
setWaitForEnqueueMSec(int waitForEnqueueMSec)
void
shutdown()
Shutdown the servicevoid
startup()
Startup the service
-
-
-
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)
-
setDialect
public void setDialect(DatabaseDialect dialect)
-
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 interfaceScottyDBStorageInterface
- Parameters:
wf
- workflow to be insertedack
- 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 interfaceScottyDBStorageInterface
- Parameters:
wfs
- workflows to be insertedack
- 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 tomax
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 interfaceScottyDBStorageInterface
- Parameters:
ppoolId
- the processor pool id of the processor pool to which the workflows shall be dequeuedmax
- 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 ofResponse
s to the database.- Specified by:
notify
in interfaceScottyDBStorageInterface
- 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 workflowack
- AnAcknowledge
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.
-
startup
public void startup()
Description copied from interface:ScottyDBStorageInterface
Startup the service- Specified by:
startup
in interfaceScottyDBStorageInterface
-
shutdown
public void shutdown()
Description copied from interface:ScottyDBStorageInterface
Shutdown the service- Specified by:
shutdown
in interfaceScottyDBStorageInterface
-
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 interfaceScottyDBStorageInterface
- Parameters:
wf
- workflow to be insertedcon
- 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 interfaceScottyDBStorageInterface
- Parameters:
wfs
- workflows to be insertedcon
- 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 interfaceScottyDBStorageInterface
- Parameters:
workflowInstanceId
- workflow id of broken workflow- Throws:
java.lang.Exception
- Any Exception like losing database connection.
-
restartFiltered
public void restartFiltered(org.copperengine.management.model.WorkflowInstanceFilter filter) throws java.lang.Exception
Description copied from interface:ScottyDBStorageInterface
Triggers the restart of all failed workflow instances. See alsoScottyDBStorageInterface.restart(String)
- Specified by:
restartFiltered
in interfaceScottyDBStorageInterface
- Parameters:
filter
- the WorkflowInstanceFilter- Throws:
java.lang.Exception
- Any Exception like losing database connection.
-
restartAll
public void restartAll() throws java.lang.Exception
- Specified by:
restartAll
in interfaceScottyDBStorageInterface
- Throws:
java.lang.Exception
-
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 interfaceScottyDBStorageInterface
- 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 interfaceScottyDBStorageInterface
- Throws:
java.lang.Exception
-
deleteFiltered
public void deleteFiltered(org.copperengine.management.model.WorkflowInstanceFilter filter) throws java.lang.Exception
- Specified by:
deleteFiltered
in interfaceScottyDBStorageInterface
- Throws:
java.lang.Exception
-
setRemoveWhenFinished
public void setRemoveWhenFinished(boolean removeWhenFinished)
- Specified by:
setRemoveWhenFinished
in interfaceScottyDBStorageInterface
- 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 ofResponse
s to the database using a provided database connection.- Specified by:
notify
in interfaceScottyDBStorageInterface
- 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 workflowc
- 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 therestart
method.- Specified by:
error
in interfaceScottyDBStorageInterface
- Parameters:
w
- The workflow which shall be marked as erroneoust
- 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 interfaceScottyDBStorageInterface
- 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 aResponse
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 interfaceScottyDBStorageInterface
- 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 workflowcallback
- AnAcknowledge
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.
-
finish
public void finish(Workflow<?> w, Acknowledge callback)
Description copied from interface:ScottyDBStorageInterface
Marks a workflow instance as finished or removes it from the underlying database. (Depending on howAbstractSqlDialect.setRemoveWhenFinished(boolean)
is set. Default is to delete).- Specified by:
finish
in interfaceScottyDBStorageInterface
- Parameters:
w
- workflow instance which finishedcallback
- which is called after operation succeeded or an Exception occurred.
-
getBatcherMXBean
public org.copperengine.management.BatcherMXBean getBatcherMXBean()
- Specified by:
getBatcherMXBean
in interfaceorg.copperengine.management.ScottyDBStorageMXBean
-
getDatabaseDialectMXBean
public org.copperengine.management.DatabaseDialectMXBean getDatabaseDialectMXBean()
- Specified by:
getDatabaseDialectMXBean
in interfaceorg.copperengine.management.ScottyDBStorageMXBean
-
getDescription
public java.lang.String getDescription()
- Specified by:
getDescription
in interfaceorg.copperengine.management.DBStorageMXBean
-
read
public Workflow<?> read(java.lang.String workflowInstanceId) throws java.lang.Exception
- Specified by:
read
in interfaceScottyDBStorageInterface
- 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 interfaceScottyDBStorageInterface
- Parameters:
className
- optional - className of the active workflow instancesmax
- 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 interfaceScottyDBStorageInterface
- Throws:
java.lang.Exception
-
queryObjectState
public java.lang.String queryObjectState(java.lang.String id) throws java.lang.Exception
- Specified by:
queryObjectState
in interfaceScottyDBStorageInterface
- 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 interfaceScottyDBStorageInterface
- Throws:
java.lang.Exception
-
countWorkflowInstances
public int countWorkflowInstances(org.copperengine.management.model.WorkflowInstanceFilter filter) throws java.lang.Exception
- Specified by:
countWorkflowInstances
in interfaceScottyDBStorageInterface
- 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 interfaceScottyDBStorageInterface
- Throws:
java.lang.Exception
-
queryAuditTrailMessage
public java.lang.String queryAuditTrailMessage(long id) throws java.lang.Exception
- Specified by:
queryAuditTrailMessage
in interfaceScottyDBStorageInterface
- Throws:
java.lang.Exception
-
countAuditTrailInstances
public int countAuditTrailInstances(org.copperengine.management.model.AuditTrailInstanceFilter filter) throws java.lang.Exception
- Specified by:
countAuditTrailInstances
in interfaceScottyDBStorageInterface
- Throws:
java.lang.Exception
-
-