public class SqlHaLockManager extends Object implements IHaLockManager
SUBSYSTEM VARCHAR(40) NOT NULL PRIMARY KEY, NODE_NAME VARCHAR(40) NOT NULL, LOCK_TIME BIGINT NOT NULL, UNLOCK_TIME BIGINT NOT NULL, STATUS INT NOT NULL
Modifier and Type | Field and Description |
---|---|
static int |
STATUS_LOCKED |
static int |
STATUS_NO_LOCK |
static int |
STATUS_UNLOCKED |
Constructor and Description |
---|
SqlHaLockManager()
Create a new lock manage instance.
|
Modifier and Type | Method and Description |
---|---|
IHaLock |
doLock() |
protected org.clazzes.util.sql.ha.SqlHaLockManager.SqlHaLock |
fetchAndLock(JDBCTransaction txn) |
String |
getConnectionThreadLocalKey() |
DataSource |
getDataSource() |
String |
getNodeName() |
String |
getSubSystem() |
String |
getTableName() |
void |
initialize()
Initialize this lock manager after setting all configuration properties.
|
protected JDBCTransaction |
openTransaction() |
void |
setConnectionThreadLocalKey(String connectionThreadLocalKey) |
void |
setDataSource(DataSource dataSource)
Set the configured data source.
|
void |
setNodeName(String nodeName)
Set the node name to report to the locking DB table.
|
void |
setSubSystem(String subSystem) |
void |
setTableName(String tableName)
Set the name of the DB table used for locking.
|
protected long |
updateStatus(JDBCTransaction txn,
int status) |
public static final int STATUS_NO_LOCK
public static final int STATUS_UNLOCKED
public static final int STATUS_LOCKED
public SqlHaLockManager()
setDataSource(DataSource)
, setNodeName(String)
,
setSubSystem(String)
, setTableName(String)
and
finally initialize()
.
If the table name is not configured, this instance is disabled
and return null
locks in doLock()
public void initialize() throws SQLException
Initialize this lock manager after setting all configuration properties. This function checks, whether there is a row in the lock table for the given subsystem and creates such a row, is it is not present.
This function only works, if a datasource has been configured using
setDataSource(DataSource)
.
SQLException
- Upon DB errors.protected long updateStatus(JDBCTransaction txn, int status) throws SQLException
SQLException
protected org.clazzes.util.sql.ha.SqlHaLockManager.SqlHaLock fetchAndLock(JDBCTransaction txn) throws SQLException
SQLException
protected JDBCTransaction openTransaction() throws SQLException
SQLException
public IHaLock doLock() throws SQLException
doLock
in interface IHaLockManager
null
, this lock manager
is disabled.SQLException
public String getSubSystem()
getSubSystem
in interface IHaLockManager
public String getNodeName()
getNodeName
in interface IHaLockManager
public void setNodeName(String nodeName)
null
or empty,
the result of InetAddress.getLocalHost().getHostName()
is used or if this fails a random UUID is used.nodeName
- The configured node name or null
or
an empty string to use an auto-configured node name.public void setSubSystem(String subSystem)
subSystem
- The subsystem used for locking.public void setDataSource(DataSource dataSource)
initialize()
,
if a thread local key for the JDBC connection is provided via
setConnectionThreadLocalKey(String)
.dataSource
- The SQL data source to use for this lock manager.public DataSource getDataSource()
public void setConnectionThreadLocalKey(String connectionThreadLocalKey)
connectionThreadLocalKey
- A thread local key to fetch database connections
from. The database connection is presumably bound to the local thread
by a JdbcTransactionInterceptor
instance. If not set,
create a connection from the provided data source.public String getConnectionThreadLocalKey()
public String getTableName()
public void setTableName(String tableName)
SUBSYSTEM VARCHAR(40) NOT NULL PRIMARY KEY, NODE_NAME VARCHAR(40) NOT NULL, LOCK_TIME BIGINT NOT NULL, UNLOCK_TIME BIGINT NOT NULL, STATUS INT NOT NULL
tableName
- The name of the database table to use. If
set to null
, this instance is disabled.Copyright © 2017 Clazzes.org. All rights reserved.