-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc88245
commit 216ce4c
Showing
36 changed files
with
757 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lombok.copyableAnnotations += org.springframework.context.annotation.Lazy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
business/src/main/java/com/kevinguanchedarias/owgejava/business/mysql/MysqlLockState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.kevinguanchedarias.owgejava.business.mysql; | ||
|
||
import lombok.experimental.UtilityClass; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@UtilityClass | ||
public class MysqlLockState { | ||
private static final InheritableThreadLocal<Set<String>> LOCKED_IDS_FOR_CURRENT_THREAD = new InheritableThreadLocal<>(); | ||
|
||
public static void addAll(List<String> ids) { | ||
get().addAll(ids); | ||
} | ||
|
||
public static void removeAll(List<String> id) { | ||
id.forEach(get()::remove); | ||
} | ||
|
||
public static void clear() { | ||
LOCKED_IDS_FOR_CURRENT_THREAD.remove(); | ||
} | ||
|
||
public static Set<String> get() { | ||
Set<String> instance; | ||
if ((instance = LOCKED_IDS_FOR_CURRENT_THREAD.get()) == null) { | ||
instance = new HashSet<>(); | ||
LOCKED_IDS_FOR_CURRENT_THREAD.set(instance); | ||
} | ||
return instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ss/src/main/java/com/kevinguanchedarias/owgejava/business/user/UserPlanetLockService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.kevinguanchedarias.owgejava.business.user; | ||
|
||
import com.kevinguanchedarias.owgejava.business.AsyncRunnerBo; | ||
import com.kevinguanchedarias.owgejava.business.planet.PlanetLockUtilService; | ||
import com.kevinguanchedarias.owgejava.entity.UserStorage; | ||
import com.kevinguanchedarias.owgejava.repository.PlanetRepository; | ||
import jakarta.annotation.Resource; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Lazy; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Propagation; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
/** | ||
* Locks user planets | ||
*/ | ||
@Service | ||
@RequiredArgsConstructor | ||
public class UserPlanetLockService { | ||
private final PlanetRepository planetRepository; | ||
private final PlanetLockUtilService planetLockUtilService; | ||
private final AsyncRunnerBo asyncRunnerBo; | ||
|
||
@Resource | ||
@Lazy | ||
private UserPlanetLockService selfProxied; | ||
|
||
@Transactional | ||
public void runLockedForUser(UserStorage user, Runnable task) { | ||
planetLockUtilService.doInsideLock(planetRepository.findByOwnerId(user.getId()), task); | ||
} | ||
|
||
@Transactional(propagation = Propagation.NOT_SUPPORTED) | ||
public void runLockedForUserDelayed(UserStorage user, Runnable task, long delay) { | ||
asyncRunnerBo.runAsyncWithoutContextDelayed(() -> | ||
selfProxied.runLockedForUser(user, task) | ||
, delay); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.