Class JdbcOrphanLockAwareIdempotentRepository
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.processor.idempotent.jdbc.AbstractJdbcMessageIdRepository
org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository
org.apache.camel.processor.idempotent.jdbc.JdbcOrphanLockAwareIdempotentRepository
- All Implemented Interfaces:
AutoCloseable,org.apache.camel.Service,org.apache.camel.ShutdownableService,org.apache.camel.spi.IdempotentRepository,org.apache.camel.StatefulService,org.apache.camel.SuspendableService
public class JdbcOrphanLockAwareIdempotentRepository
extends JdbcMessageIdRepository
implements org.apache.camel.ShutdownableService
Implementation of
AbstractJdbcMessageIdRepository which handles orphan locks resulting from jvm crash.
When an instance of the application acquires a lock on the idempotent repository, the lock attributes are added to a
HashSet. While the lock is help by the instance, the instance keeps updating the createdAt column with the current
timestamp indicating the instance holding the lock is active.
A lock is granted to an instance if either the entry for the lock attributes do not exists in the
CAMEL_MESSAGEPROCESSED table or if in case the instance holding the lock has crashed. This is determined if the
timestamp on the createdAt column is more than the lockMaxAge.-
Field Summary
Fields inherited from class org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository
DEFAULT_CLEAR_STRING, DEFAULT_CREATE_STRING, DEFAULT_DELETE_STRING, DEFAULT_INSERT_STRING, DEFAULT_QUERY_STRING, DEFAULT_TABLE_EXISTS_STRING, DEFAULT_TABLENAMEFields inherited from class org.apache.camel.processor.idempotent.jdbc.AbstractJdbcMessageIdRepository
dataSource, jdbcTemplate, log, processorName, transactionTemplateFields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING -
Constructor Summary
ConstructorsConstructorDescriptionJdbcOrphanLockAwareIdempotentRepository(DataSource dataSource, String processorName, org.apache.camel.CamelContext camelContext) JdbcOrphanLockAwareIdempotentRepository(DataSource dataSource, org.springframework.transaction.support.TransactionTemplate transactionTemplate, String processorName, org.apache.camel.CamelContext camelContext) JdbcOrphanLockAwareIdempotentRepository(org.apache.camel.CamelContext camelContext) JdbcOrphanLockAwareIdempotentRepository(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, org.springframework.transaction.support.TransactionTemplate transactionTemplate, org.apache.camel.CamelContext camelContext) -
Method Summary
Modifier and TypeMethodDescriptionprotected intdelete()Operations that deletes all the rowsprotected intOperations that deletes the key if it existsprotected voiddoInit()protected voidlonglongSet<org.apache.camel.processor.idempotent.jdbc.JdbcOrphanLockAwareIdempotentRepository.ProcessorNameAndMessageId>protected intOperation that inserts the key if it does not already existprotected intqueryForInt(String key) Operation that returns the number of rows, if any, for the specified keyvoidsetLockKeepAliveIntervalMillis(long lockKeepAliveIntervalMillis) voidsetLockMaxAgeMillis(long lockMaxAgeMillis) voidsetUpdateTimestampQuery(String updateTimestampQuery) Methods inherited from class org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository
doStart, getClearString, getCreateString, getDeleteString, getInsertString, getQueryString, getTableExistsString, getTableName, isCreateTableIfNotExists, setClearString, setCreateString, setCreateTableIfNotExists, setDeleteString, setInsertString, setQueryString, setTableExistsString, setTableNameMethods inherited from class org.apache.camel.processor.idempotent.jdbc.AbstractJdbcMessageIdRepository
add, clear, confirm, contains, createTransactionTemplate, doStop, getDataSource, getJdbcTemplate, getProcessorName, getTransactionTemplate, remove, setDataSource, setJdbcTemplate, setProcessorName, setTransactionTemplateMethods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.camel.spi.IdempotentRepository
add, confirm, contains, removeMethods inherited from interface org.apache.camel.Service
build, close, init, start, stopMethods inherited from interface org.apache.camel.ShutdownableService
shutdownMethods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspendingMethods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Constructor Details
-
JdbcOrphanLockAwareIdempotentRepository
public JdbcOrphanLockAwareIdempotentRepository(org.apache.camel.CamelContext camelContext) -
JdbcOrphanLockAwareIdempotentRepository
public JdbcOrphanLockAwareIdempotentRepository(DataSource dataSource, String processorName, org.apache.camel.CamelContext camelContext) -
JdbcOrphanLockAwareIdempotentRepository
public JdbcOrphanLockAwareIdempotentRepository(DataSource dataSource, org.springframework.transaction.support.TransactionTemplate transactionTemplate, String processorName, org.apache.camel.CamelContext camelContext) -
JdbcOrphanLockAwareIdempotentRepository
public JdbcOrphanLockAwareIdempotentRepository(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, org.springframework.transaction.support.TransactionTemplate transactionTemplate, org.apache.camel.CamelContext camelContext)
-
-
Method Details
-
queryForInt
Description copied from class:AbstractJdbcMessageIdRepositoryOperation that returns the number of rows, if any, for the specified key- Overrides:
queryForIntin classJdbcMessageIdRepository- Parameters:
key- the key- Returns:
- int number of rows
-
delete
Description copied from class:AbstractJdbcMessageIdRepositoryOperations that deletes the key if it exists- Overrides:
deletein classJdbcMessageIdRepository- Parameters:
key- the key- Returns:
- int number of rows deleted
-
insert
Description copied from class:AbstractJdbcMessageIdRepositoryOperation that inserts the key if it does not already exist- Overrides:
insertin classJdbcMessageIdRepository- Parameters:
key- the key- Returns:
- int number of rows inserted
-
doInit
- Overrides:
doInitin classJdbcMessageIdRepository- Throws:
Exception
-
doShutdown
- Overrides:
doShutdownin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
delete
protected int delete()Description copied from class:AbstractJdbcMessageIdRepositoryOperations that deletes all the rows- Overrides:
deletein classJdbcMessageIdRepository- Returns:
- int number of rows deleted
-
getProcessorNameMessageIdSet
public Set<org.apache.camel.processor.idempotent.jdbc.JdbcOrphanLockAwareIdempotentRepository.ProcessorNameAndMessageId> getProcessorNameMessageIdSet() -
getUpdateTimestampQuery
-
setUpdateTimestampQuery
-
getLockMaxAgeMillis
public long getLockMaxAgeMillis() -
setLockMaxAgeMillis
public void setLockMaxAgeMillis(long lockMaxAgeMillis) -
getLockKeepAliveIntervalMillis
public long getLockKeepAliveIntervalMillis() -
setLockKeepAliveIntervalMillis
public void setLockKeepAliveIntervalMillis(long lockKeepAliveIntervalMillis)
-