code.onehippo.org is currently readonly. We are migrating to code.bloomreach.com, please continue working there on Monday 14/12. See: https://docs.bloomreach.com/display/engineering/GitLab

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; ...@@ -39,12 +39,12 @@ import org.onehippo.cms7.services.SingletonService;
* <code> * <code>
* <pre> * <pre>
* public void run() { * public void run() {
* boolean locked = false; * try (LockResource ignore = lockManager.lock(key)){
* try {
* try (LockResource lock = lockManager.lock(key)){
* // Do work * // Do work
* } catch (AlreadyLockedException e) {
* log.info("'{}' is already locked", key, e);
* } catch (LockException 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> * </pre>
...@@ -58,9 +58,11 @@ import org.onehippo.cms7.services.SingletonService; ...@@ -58,9 +58,11 @@ import org.onehippo.cms7.services.SingletonService;
* lockManager.lock(key); * lockManager.lock(key);
* locked = true; * locked = true;
* // Do work * // Do work
* } catch (AlreadyLockedException e) {
* log.info("'{}' is already locked", key, e);
* } catch (LockException 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);
* } finally { * }finally {
* if (locked) { * if (locked) {
* lockManager.unlock(key); * lockManager.unlock(key);
* } * }
...@@ -70,12 +72,13 @@ import org.onehippo.cms7.services.SingletonService; ...@@ -70,12 +72,13 @@ import org.onehippo.cms7.services.SingletonService;
* </code> * </code>
* </p> * </p>
* <p> * <p>
* Note that when a {@code key} is already locked, the invocation of {@link #lock(String) #lock(key)} directly results * Note that when {@code key} is already locked by another {@link Thread} or other cluster node,
* in an {@link AlreadyLockedException} : This is thus <strong>different</strong> than * the invocation of {@link #lock(String) #lock(key)} directly results in an {@link AlreadyLockedException} :
* {@link java.util.concurrent.locks.ReentrantLock} behavior. If you need similar behavior to {@link ReentrantLock#lock()} * This is thus <strong>different</strong> than {@link ReentrantLock#lock()} behavior (which blocks until the lock is acquired).
* but then <strong>cluster wide</strong>, you can use {@link LockManagerUtils#waitForLock(LockManager, String, long)} * If you need similar behavior to {@link ReentrantLock#lock()} but then <strong>cluster wide</strong>, you can use
* and if you need the cluster wide equivalent of {@link java.util.concurrent.locks.ReentrantLock#tryLock(long, TimeUnit)} * {@link LockManagerUtils#waitForLock(LockManager, String, long)} and if you need the cluster wide equivalent
* you can use {@link LockManagerUtils#waitForLock(LockManager, String, long, long)}. * of {@link java.util.concurrent.locks.ReentrantLock#tryLock(long, TimeUnit)} you can use
* {@link LockManagerUtils#waitForLock(LockManager, String, long, long)}.
* </p> * </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