K - public class ColumnPrefixDistributedRowLock<K> extends java.lang.Object implements DistributedRowLock
ColumnPrefixDistributedRowLock lock = new ColumnPrefixDistributedRowLock(keyspace, columnFamily, "KeyBeingLocked");
try {
lock.acquire();
}
finally {
lock.release();
}
Read, Modify, Write. The read, modify, write piggybacks on top of the lock calls.
ColumnPrefixDistributedRowLock lock = new ColumnPrefixDistributedRowLock(keyspace, columnFamily, "KeyBeingLocked");
MutationBatch m = keyspace.prepareMutationBatch();
try {
ColumnMap columns = lock.acquireLockAndReadRow();
m.withRow("KeyBeingLocked")
.putColumn("SomeColumnBeingUpdated", );
lock.releaseWithMutation(m);
}
catch (Exception e) {
lock.release();
}
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_LOCK_PREFIX |
static java.util.concurrent.TimeUnit |
DEFAULT_OPERATION_TIMEOUT_UNITS |
static int |
LOCK_TIMEOUT |
| Constructor and Description |
|---|
ColumnPrefixDistributedRowLock(com.netflix.astyanax.Keyspace keyspace,
com.netflix.astyanax.model.ColumnFamily<K,java.lang.String> columnFamily,
K key) |
| Modifier and Type | Method and Description |
|---|---|
void |
acquire()
Try to take the lock.
|
com.netflix.astyanax.model.ColumnMap<java.lang.String> |
acquireLockAndReadRow()
Take the lock and return the row data columns.
|
ColumnPrefixDistributedRowLock<K> |
expireLockAfter(long timeout,
java.util.concurrent.TimeUnit unit)
Time for failed locks.
|
ColumnPrefixDistributedRowLock<K> |
failOnStaleLock(boolean failOnStaleLock)
When set to true the operation will fail if a stale lock is detected
|
java.lang.String |
fillLockMutation(com.netflix.astyanax.MutationBatch m,
java.lang.Long time,
java.lang.Integer ttl)
Fill a mutation with the lock column.
|
void |
fillReleaseMutation(com.netflix.astyanax.MutationBatch m,
boolean excludeCurrentLock)
Fill a mutation that will release the locks.
|
com.netflix.astyanax.model.ConsistencyLevel |
getConsistencyLevel() |
com.netflix.astyanax.model.ColumnMap<java.lang.String> |
getDataColumns() |
K |
getKey() |
com.netflix.astyanax.Keyspace |
getKeyspace() |
java.lang.String |
getLockColumn() |
java.lang.String |
getLockId() |
java.lang.String |
getPrefix() |
int |
getRetryCount() |
java.util.Map<java.lang.String,java.lang.Long> |
readLockColumns()
Return a mapping of existing lock columns and their expiration times
|
long |
readTimeoutValue(com.netflix.astyanax.model.Column<?> column)
Read the expiration time from the column value
|
void |
release()
Release the lock by releasing this and any other stale lock columns
|
java.util.Map<java.lang.String,java.lang.Long> |
releaseAllLocks()
Release all locks.
|
java.util.Map<java.lang.String,java.lang.Long> |
releaseExpiredLocks()
Release all expired locks for this key.
|
java.util.Map<java.lang.String,java.lang.Long> |
releaseLocks(boolean force)
Delete locks columns.
|
void |
releaseWithMutation(com.netflix.astyanax.MutationBatch m)
Release using the provided mutation.
|
boolean |
releaseWithMutation(com.netflix.astyanax.MutationBatch m,
boolean force) |
void |
verifyLock(long curTimeInMicros)
Verify that the lock was acquired.
|
ColumnPrefixDistributedRowLock<K> |
withBackoff(com.netflix.astyanax.retry.RetryPolicy policy) |
ColumnPrefixDistributedRowLock<K> |
withColumnPrefix(java.lang.String prefix)
Specify the prefix that uniquely distinguishes the lock columns from data
column
|
ColumnPrefixDistributedRowLock<K> |
withConsistencyLevel(com.netflix.astyanax.model.ConsistencyLevel consistencyLevel)
Modify the consistency level being used.
|
ColumnPrefixDistributedRowLock<K> |
withDataColumns(boolean flag)
If true the first read will also fetch all the columns in the row as
opposed to just the lock columns.
|
ColumnPrefixDistributedRowLock<K> |
withLockId(java.lang.String lockId)
Override the autogenerated lock column.
|
ColumnPrefixDistributedRowLock<K> |
withTtl(java.lang.Integer ttl)
This is the TTL on the lock column being written, as opposed to expireLockAfter which
is written as the lock column value.
|
ColumnPrefixDistributedRowLock<K> |
withTtl(java.lang.Integer ttl,
java.util.concurrent.TimeUnit units) |
public static final int LOCK_TIMEOUT
public static final java.util.concurrent.TimeUnit DEFAULT_OPERATION_TIMEOUT_UNITS
public static final java.lang.String DEFAULT_LOCK_PREFIX
public ColumnPrefixDistributedRowLock<K> withConsistencyLevel(com.netflix.astyanax.model.ConsistencyLevel consistencyLevel)
consistencyLevel - public ColumnPrefixDistributedRowLock<K> withColumnPrefix(java.lang.String prefix)
prefix - public ColumnPrefixDistributedRowLock<K> withDataColumns(boolean flag)
flag - public ColumnPrefixDistributedRowLock<K> withLockId(java.lang.String lockId)
lockId - public ColumnPrefixDistributedRowLock<K> failOnStaleLock(boolean failOnStaleLock)
failOnStaleLock - public ColumnPrefixDistributedRowLock<K> expireLockAfter(long timeout, java.util.concurrent.TimeUnit unit)
timeout - unit - public ColumnPrefixDistributedRowLock<K> withTtl(java.lang.Integer ttl)
ttl - public ColumnPrefixDistributedRowLock<K> withTtl(java.lang.Integer ttl, java.util.concurrent.TimeUnit units)
public ColumnPrefixDistributedRowLock<K> withBackoff(com.netflix.astyanax.retry.RetryPolicy policy)
public void acquire()
throws java.lang.Exception
acquire in interface DistributedRowLockjava.lang.Exceptionpublic com.netflix.astyanax.model.ColumnMap<java.lang.String> acquireLockAndReadRow()
throws java.lang.Exception
java.lang.Exceptionpublic void verifyLock(long curTimeInMicros)
throws java.lang.Exception,
BusyLockException,
StaleLockException
curTimeInMicros - BusyLockExceptionjava.lang.ExceptionStaleLockExceptionpublic void release()
throws java.lang.Exception
release in interface DistributedRowLockjava.lang.Exceptionpublic void releaseWithMutation(com.netflix.astyanax.MutationBatch m)
throws java.lang.Exception
m - java.lang.Exceptionpublic boolean releaseWithMutation(com.netflix.astyanax.MutationBatch m,
boolean force)
throws java.lang.Exception
java.lang.Exceptionpublic java.util.Map<java.lang.String,java.lang.Long> readLockColumns()
throws java.lang.Exception
java.lang.Exceptionpublic java.util.Map<java.lang.String,java.lang.Long> releaseAllLocks()
throws java.lang.Exception
java.lang.Exceptionpublic java.util.Map<java.lang.String,java.lang.Long> releaseExpiredLocks()
throws java.lang.Exception
java.lang.Exceptionpublic java.util.Map<java.lang.String,java.lang.Long> releaseLocks(boolean force)
throws java.lang.Exception
force - - Force delete of non expired locks as welljava.lang.Exceptionpublic java.lang.String fillLockMutation(com.netflix.astyanax.MutationBatch m,
java.lang.Long time,
java.lang.Integer ttl)
m - time - ttl - public long readTimeoutValue(com.netflix.astyanax.model.Column<?> column)
column - public void fillReleaseMutation(com.netflix.astyanax.MutationBatch m,
boolean excludeCurrentLock)
m - public com.netflix.astyanax.model.ColumnMap<java.lang.String> getDataColumns()
public K getKey()
public com.netflix.astyanax.Keyspace getKeyspace()
public com.netflix.astyanax.model.ConsistencyLevel getConsistencyLevel()
public java.lang.String getLockColumn()
public java.lang.String getLockId()
public java.lang.String getPrefix()
public int getRetryCount()