Commit a195137f authored by Ard Schrijvers's avatar Ard Schrijvers

CMS-16 Fix javadoc and use AlreadyLockedException

(cherry picked from commit 66288f41)

CMS-16 use 'ignore' since recognized by idea

(cherry picked from commit 5c36543e)

CMS-16 improve java doc

(cherry picked from commit b0f283d5)

CMS-16 improve java doc

(cherry picked from commit de90f059)
parent 12725f79
......@@ -39,12 +39,12 @@ import org.onehippo.cms7.services.SingletonService;
* <code>
* <pre>
* public void run() {
* boolean locked = false;
* try {
* try (LockResource lock = lockManager.lock(key)){
* try (LockResource ignore = lockManager.lock(key)){
* // Do work
* } catch (AlreadyLockedException e) {
* log.info("'{}' is already locked", key, e);
* } catch (LockException e) {
* log.info("Failed to obtain lock, most likely obtained by other cluster node already", e);
* log.error("Exception while trying to obtain lock, e);
* }
* }
* </pre>
......@@ -58,9 +58,11 @@ import org.onehippo.cms7.services.SingletonService;
* lockManager.lock(key);
* locked = true;
* // Do work
* } catch (AlreadyLockedException e) {
* log.info("'{}' is already locked", key, e);
* } catch (LockException e) {
* log.info("Failed to obtain lock, most likely obtained by other cluster node already", e);
* } finally {
* log.error("Exception while trying to obtain lock, e);
* }finally {
* if (locked) {
* lockManager.unlock(key);
* }
......@@ -70,12 +72,13 @@ import org.onehippo.cms7.services.SingletonService;
* </code>
* </p>
* <p>
* Note that when a {@code key} is already locked, the invocation of {@link #lock(String) #lock(key)} directly results
* in an {@link AlreadyLockedException} : This is thus <strong>different</strong> than
* {@link java.util.concurrent.locks.ReentrantLock} behavior. If you need similar behavior to {@link ReentrantLock#lock()}
* but then <strong>cluster wide</strong>, you can use {@link LockManagerUtils#waitForLock(LockManager, String, long)}
* and if you need the cluster wide equivalent of {@link java.util.concurrent.locks.ReentrantLock#tryLock(long, TimeUnit)}
* you can use {@link LockManagerUtils#waitForLock(LockManager, String, long, long)}.
* Note that when {@code key} is already locked by another {@link Thread} or other cluster node,
* the invocation of {@link #lock(String) #lock(key)} directly results in an {@link AlreadyLockedException} :
* This is thus <strong>different</strong> than {@link ReentrantLock#lock()} behavior (which blocks until the lock is acquired).
* If you need similar behavior to {@link ReentrantLock#lock()} but then <strong>cluster wide</strong>, you can use
* {@link LockManagerUtils#waitForLock(LockManager, String, long)} and if you need the cluster wide equivalent
* of {@link java.util.concurrent.locks.ReentrantLock#tryLock(long, TimeUnit)} you can use
* {@link LockManagerUtils#waitForLock(LockManager, String, long, long)}.
* </p>
*
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment