Package nl.vpro.domain.media
Class MediaObjectLocker
- java.lang.Object
-
- nl.vpro.domain.media.MediaObjectLocker
-
public class MediaObjectLocker extends Object
Tool to make sure that the 'authority' related dropboxes and other services don't run at the same time for the same mid.It may be better to (also) introduce more decent hibernate locking (MSE-3751)
This basically wraps
ObjectLocker
, but keeps a separate map of locked objects, dedicated to media identifiablesAlso, it defines some annotations (for use with
MediaObjectLockerAspect
, to facilitate locking via annotation), and some utility methods.- Since:
- 5.5
- Author:
- Michiel Meeuwissen
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
MediaObjectLocker.AssertNoMidLock
static interface
MediaObjectLocker.Mid
Adding this annotation of a method with aString
orMediaIdentifiable
argument will 'lock' the identifier, and will make sure that no other code doing the same will run simultaneously.static interface
MediaObjectLocker.Sid
LikeMediaObjectLocker.Mid
, but now fornl.vpro.domain.subtitles.SubtitlesId
-
Constructor Summary
Constructors Constructor Description MediaObjectLocker()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertNoMidLock(String description)
static <T> T
executeInNewTransactionWithCorrelationLock(@NonNull DoAsTransactionService transactionService, @NonNull Trusted user, MediaIdentifiable.Correlation correlation, @NonNull String reason, @NonNull Callable<T> callable)
Run in a new transaction, but before that lock the mid.static <T> T
executeInNewTransactionWithCorrelationLock(@NonNull TransactionService transactionService, MediaIdentifiable.Correlation correlation, @NonNull String reason, @NonNull Callable<T> callable)
Run in a new transaction, but before that lock the mid.static <T> T
executeInNewTransactionWithMidLock(@NonNull DoAsTransactionService transactionService, @NonNull Trusted user, String mid, @NonNull String reason, @NonNull Callable<T> callable)
Run in a new transaction, but before that lock the mid.static <T> T
executeInNewTransactionWithMidLock(@NonNull TransactionService transactionService, String mid, @NonNull String reason, @NonNull Callable<T> callable)
Run in a new transaction, but before that lock the mid.static <T> T
getWithMidLock(String mid, @NonNull String reason, @NonNull Supplier<T> callable)
static <T> T
withCorrelationLock(@NonNull MediaIdentifiable.Correlation lock, @NonNull String reason, @NonNull Callable<T> callable)
static <T> T
withCorrelationLock(@NonNull MediaIdentifiable lockHolder, @NonNull String reason, @NonNull Callable<T> callable)
Locks the givenMediaIdentifiable
on itsMediaIdentifiable.getCorrelation()
static void
withMidLock(String mid, @NonNull String reason, @NonNull Runnable runnable)
static <T> T
withMidLock(String mid, @NonNull String reason, @NonNull Callable<T> callable)
-
-
-
Method Detail
-
assertNoMidLock
public static void assertNoMidLock(String description)
-
executeInNewTransactionWithMidLock
public static <T> T executeInNewTransactionWithMidLock(@NonNull TransactionService transactionService, String mid, @NonNull String reason, @NonNull Callable<T> callable)
Run in a new transaction, but before that lock the mid.Make sure not to be in a transaction already.
-
executeInNewTransactionWithCorrelationLock
public static <T> T executeInNewTransactionWithCorrelationLock(@NonNull TransactionService transactionService, MediaIdentifiable.Correlation correlation, @NonNull String reason, @NonNull Callable<T> callable)
Run in a new transaction, but before that lock the mid.Make sure not to be in a transaction already.
- Since:
- 7.1
-
executeInNewTransactionWithMidLock
public static <T> T executeInNewTransactionWithMidLock(@NonNull DoAsTransactionService transactionService, @NonNull Trusted user, String mid, @NonNull String reason, @NonNull Callable<T> callable)
Run in a new transaction, but before that lock the mid.Make sure not to be in a transaction already.
-
executeInNewTransactionWithCorrelationLock
public static <T> T executeInNewTransactionWithCorrelationLock(@NonNull DoAsTransactionService transactionService, @NonNull Trusted user, MediaIdentifiable.Correlation correlation, @NonNull String reason, @NonNull Callable<T> callable)
Run in a new transaction, but before that lock the mid.Make sure not to be in a transaction already.
- Since:
- 7.1
-
getWithMidLock
public static <T> T getWithMidLock(String mid, @NonNull String reason, @NonNull Supplier<T> callable)
-
withMidLock
public static void withMidLock(String mid, @NonNull String reason, @NonNull Runnable runnable)
-
withMidLock
public static <T> T withMidLock(String mid, @NonNull String reason, @NonNull Callable<T> callable)
-
withCorrelationLock
public static <T> T withCorrelationLock(@NonNull MediaIdentifiable.Correlation lock, @NonNull String reason, @NonNull Callable<T> callable)
-
withCorrelationLock
public static <T> T withCorrelationLock(@NonNull MediaIdentifiable lockHolder, @NonNull String reason, @NonNull Callable<T> callable)
Locks the givenMediaIdentifiable
on itsMediaIdentifiable.getCorrelation()
-
-