Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.quartz.impl.jdbcjobstore
Class JTANonClusteredSemaphore

    java.lang.Object
      org.quartz.impl.jdbcjobstore.JTANonClusteredSemaphore

All Implemented Interfaces:
  Semaphore

    public class JTANonClusteredSemaphore

extends Object
implements Semaphore

Provides in memory thread/resource locking that is JTA ``Transaction`` aware. It is most appropriate for use when using ``JobStoreCMT`` without clustering.

This `Semaphore` implementation is not Quartz cluster safe.

When a lock is obtained/released but there is no active JTA ``Transaction``, then this `Semaphore` operates just like ``SimpleSemaphore``.

By default, this class looks for the ``TransactionManager`` in JNDI under name "java:TransactionManager". If this is not where your Application Server registers it, you can modify the JNDI lookup location using the "transactionManagerJNDIName" property.

IMPORTANT: This Semaphore implementation is currently experimental. It has been tested a limited amount on JBoss 4.0.3SP1. If you do choose to use it, any feedback would be most appreciated!

See Also:
  `SimpleSemaphore`

Field Summary
`static String` | `DEFAULT_TRANSACTION_MANANGER_LOCATION`

Constructor Summary
`JTANonClusteredSemaphore()`

Method Summary
`protected org.slf4j.Logger` | `getLog()`
`protected Transaction` | `getTransaction()` Helper method to get the current ``Transaction`` from the ``TransactionManager`` in JNDI.
`boolean` | `isLockOwner(Connection conn, String lockName)` Determine whether the calling thread owns a lock on the identified resource.
`boolean` | `obtainLock(Connection conn, String lockName)` Grants a lock on the identified resource to the calling thread (blocking until it is available).
`void` | `releaseLock(Connection conn, String lockName)` Release the lock on the identified resource if it is held by the calling thread, unless currently in a JTA transaction.
`protected void` | `releaseLock(String lockName, boolean fromSynchronization)` Release the lock on the identified resource if it is held by the calling thread, unless currently in a JTA transaction.
`boolean` | `requiresConnection()` This Semaphore implementation does not use the database.
`void` | `setTransactionManagerJNDIName(String transactionManagerJNDIName)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_TRANSACTION_MANANGER_LOCATION

    public static final String DEFAULT_TRANSACTION_MANANGER_LOCATION

See Also:
  Constant Field Values

Constructor Detail

### JTANonClusteredSemaphore

    public JTANonClusteredSemaphore()

Method Detail

### getLog

    protected org.slf4j.Logger getLog()

### setTransactionManagerJNDIName

    public void setTransactionManagerJNDIName(String transactionManagerJNDIName)

### obtainLock

    public boolean obtainLock(Connection conn,
                              String lockName)
                       throws LockException

  Grants a lock on the identified resource to the calling thread (blocking until it is available).

  Specified by:
    `obtainLock` in interface `Semaphore`
  Parameters:
    `conn` - Database connection used to establish lock. Can be null if ``Semaphore.requiresConnection()`` returns false.
  Returns:
    true if the lock was obtained.
  Throws:
    `LockException`

### getTransaction

    protected Transaction getTransaction()
                                  throws LockException

  Helper method to get the current ``Transaction`` from the ``TransactionManager`` in JNDI.

  Returns:
    The current ``Transaction``, null if not currently in a transaction.
  Throws:
    `LockException`

### releaseLock

    public void releaseLock(Connection conn,
                            String lockName)
                     throws LockException

  Release the lock on the identified resource if it is held by the calling thread, unless currently in a JTA transaction.

  Specified by:
    `releaseLock` in interface `Semaphore`
  Parameters:
    `conn` - Database connection used to establish lock. Can be null if ``Semaphore.requiresConnection()`` returns false.
  Throws:
    `LockException`

### releaseLock

    protected void releaseLock(String lockName,
                               boolean fromSynchronization)
                        throws LockException

  Release the lock on the identified resource if it is held by the calling thread, unless currently in a JTA transaction.

  Parameters:
    `fromSynchronization` - True if this method is being invoked from ``Synchronization`` notified of the enclosing transaction having completed.
  Throws:
    `LockException` - Thrown if there was a problem accessing the JTA `Transaction`. Only relevant if `fromSynchronization` is false.

### isLockOwner

    public boolean isLockOwner(Connection conn,
                               String lockName)

  Determine whether the calling thread owns a lock on the identified resource.

  Specified by:
    `isLockOwner` in interface `Semaphore`
  Parameters:
    `conn` - Database connection used to establish lock. Can be null if ``Semaphore.requiresConnection()`` returns false.

### requiresConnection

    public boolean requiresConnection()

  This Semaphore implementation does not use the database.

  Specified by:
    `requiresConnection` in interface `Semaphore`
  See Also:
    `Semaphore.isLockOwner(Connection, String)`, `Semaphore.obtainLock(Connection, String)`, `Semaphore.releaseLock(Connection, String)`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright 2001-2012, Terracotta, Inc.