@Beta public final class JdbcSemaphore extends Object implements AutoCloseable, Semaphore
Constructor and Description |
---|
JdbcSemaphore(DataSource dataSource,
SemaphoreTablesDesc semTableDesc,
String semaphoreName,
int nrPermits,
int jdbcTimeoutSeconds,
boolean strictReservations) |
JdbcSemaphore(DataSource dataSource,
SemaphoreTablesDesc semTableDesc,
String semaphoreName,
int nrPermits,
int jdbcTimeoutSeconds,
boolean strictReservations,
int acquirePollMillis) |
JdbcSemaphore(DataSource dataSource,
String semaphoreName,
int nrPermits) |
JdbcSemaphore(DataSource dataSource,
String semaphoreName,
int nrPermits,
boolean strict)
create a JDBC Semaphore.
|
Modifier and Type | Method and Description |
---|---|
int |
availablePermits() |
void |
close() |
protected void |
finalize() |
List<OwnerPermits> |
getDeadOwnerPermits(int wishPermits) |
int |
getJdbcTimeoutSeconds() |
void |
increasePermits(int nrPermits) |
boolean |
isIsHealthy() |
int |
permitsOwned() |
void |
reducePermits(int nrPermits) |
void |
registerJmx() |
void |
release(int nrReservations)
release a number of permits.
|
void |
releaseAll() |
int |
releaseDeadOwnerPermits(int wishPermits)
Attempts to release permits for this semaphore owned by dead owners.
|
int |
removeDeadHeartBeatAndNotOwnerRows(long timeoutSeconds) |
String |
toString() |
int |
totalPermits() |
boolean |
tryAcquire(int nrPermits,
long deadlineNanos) |
void |
unregisterJmx() |
void |
updatePermits(int nrPermits) |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
release, toSemaphore
acquire, acquire, tryAcquire, tryAcquire
public JdbcSemaphore(DataSource dataSource, String semaphoreName, int nrPermits) throws InterruptedException, SQLException
dataSource
- the jdbc data source with the Semaphores table. Please be sensible, no "test on borrow" pools.semaphoreName
- number of initial permits, if semaphore already exists the existing nr of permits is kept.nrPermits
- the number of initial permits.InterruptedException
SQLException
public JdbcSemaphore(DataSource dataSource, String semaphoreName, int nrPermits, boolean strict) throws InterruptedException, SQLException
dataSource
- the data source to use for sync.semaphoreName
- the semaphore name.nrPermits
- number of initial permits.strict
- if true, if semaphore already exists and the total permits is different that param nrPermits an
IllegalArgumentException will be thrown.InterruptedException
SQLException
public JdbcSemaphore(DataSource dataSource, SemaphoreTablesDesc semTableDesc, String semaphoreName, int nrPermits, int jdbcTimeoutSeconds, boolean strictReservations) throws InterruptedException, SQLException
InterruptedException
SQLException
public JdbcSemaphore(DataSource dataSource, SemaphoreTablesDesc semTableDesc, String semaphoreName, int nrPermits, int jdbcTimeoutSeconds, boolean strictReservations, int acquirePollMillis) throws InterruptedException, SQLException
InterruptedException
SQLException
public void registerJmx()
public void unregisterJmx()
@CheckReturnValue public boolean tryAcquire(int nrPermits, long deadlineNanos) throws InterruptedException
tryAcquire
in interface PermitSupplier
InterruptedException
public void release(int nrReservations)
Semaphore
public void releaseAll()
public int availablePermits() throws SQLException, InterruptedException
SQLException
InterruptedException
public int permitsOwned() throws SQLException, InterruptedException
SQLException
InterruptedException
public int totalPermits() throws SQLException, InterruptedException
SQLException
InterruptedException
@Nonnull public List<OwnerPermits> getDeadOwnerPermits(int wishPermits) throws SQLException, InterruptedException
SQLException
InterruptedException
@CheckReturnValue public int releaseDeadOwnerPermits(int wishPermits) throws InterruptedException, SQLException
wishPermits
- - How many permits we would like to get released.SQLException
- - something went wrong with the db.InterruptedException
- - thrown if thread is interrupted.public void updatePermits(int nrPermits) throws SQLException, InterruptedException
SQLException
InterruptedException
public void reducePermits(int nrPermits) throws SQLException, InterruptedException
SQLException
InterruptedException
public void increasePermits(int nrPermits) throws SQLException, InterruptedException
SQLException
InterruptedException
public int removeDeadHeartBeatAndNotOwnerRows(long timeoutSeconds) throws SQLException, InterruptedException
SQLException
InterruptedException
public void close()
close
in interface AutoCloseable
protected void finalize() throws Throwable
public int getJdbcTimeoutSeconds()
public boolean isIsHealthy()
Copyright © 2018 SPF4J. All rights reserved.