Skip to content

Commit

Permalink
Made a few methods public, so we can try out a 'delayed' release.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Nov 22, 2024
1 parent 21935fb commit f39b69e
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private ObjectLocker() {
*/
static final Map<Serializable, LockHolder<Serializable>> LOCKED_OBJECTS = new ConcurrentHashMap<>();


public static final BiPredicate<Serializable, Serializable> CLASS_EQUALS = (o1, o2) -> Objects.equals(o1.getClass(), o2.getClass());
static boolean strictlyOne;
static boolean monitor;

Expand Down Expand Up @@ -129,7 +129,7 @@ public static <T> T withKeyLock(
Serializable id,
@NonNull String reason,
@NonNull Callable<T> callable) {
return withObjectLock(id, reason, callable, ObjectLocker.LOCKED_OBJECTS, (o1, o2) -> Objects.equals(o1.getClass(), o2.getClass()));
return withObjectLock(id, reason, callable, ObjectLocker.LOCKED_OBJECTS, CLASS_EQUALS);
}

public static <T> T withKeyLock(
Expand All @@ -143,7 +143,7 @@ public static <T> T withKeyLock(
consumer,
callable,
ObjectLocker.LOCKED_OBJECTS,
(o1, o2) -> Objects.equals(o1.getClass(), o2.getClass())
CLASS_EQUALS
);
}

Expand All @@ -158,6 +158,8 @@ public static <T> T withKeyLock(
}




/**
* @param key The key to lock on
* @param reason A description for the reason of locking, which can be used in logging or exceptions
Expand Down Expand Up @@ -194,10 +196,16 @@ public static <T, K extends Serializable> T withObjectLock(
}
}

public static <K extends Serializable> LockHolderCloser<Serializable> acquireLock(
final Serializable key,
final @NonNull String reason,
final @NonNull Map<Serializable, LockHolder<Serializable>> locks) throws InterruptedException {
return acquireLock(key, reason, locks, CLASS_EQUALS);
}


@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
private static <K extends Serializable> LockHolderCloser<K> acquireLock(
public static <K extends Serializable> LockHolderCloser<K> acquireLock(
final K key,
final @NonNull String reason,
final @NonNull Map<K, LockHolder<K>> locks,
Expand Down Expand Up @@ -442,7 +450,7 @@ public void disable(boolean interrupt) {
}
}

private static class LockHolderCloser<K extends Serializable> implements AutoCloseable {
public static class LockHolderCloser<K extends Serializable> implements AutoCloseable {
@Getter
final LockHolder<K> lockHolder;

Expand Down

0 comments on commit f39b69e

Please sign in to comment.