Package nl.vpro.domain.media
Class MediaObjectLocker
java.lang.Object
nl.vpro.domain.media.MediaObjectLocker
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 identifiables
Also, 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
Modifier and TypeClassDescriptionstatic @interface
static @interface
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
LikeMediaObjectLocker.Mid
, but now fornl.vpro.domain.subtitles.SubtitlesId
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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)
-
Constructor Details
-
MediaObjectLocker
public MediaObjectLocker()
-
-
Method Details
-
assertNoMidLock
-
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
-
withMidLock
-
withMidLock
-
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()
-