|
1 | 1 | package eu.solven.kumite.app;
|
2 | 2 |
|
3 |
| -import java.util.concurrent.Executor; |
| 3 | +import java.util.List; |
| 4 | +import java.util.concurrent.ExecutorService; |
4 | 5 | import java.util.concurrent.Executors;
|
| 6 | +import java.util.stream.Collectors; |
| 7 | +import java.util.stream.IntStream; |
5 | 8 |
|
6 | 9 | import org.greenrobot.eventbus.EventBus;
|
7 | 10 | import org.greenrobot.eventbus.Logger;
|
|
15 | 18 | import eu.solven.kumite.app.persistence.InMemoryKumiteConfiguration;
|
16 | 19 | import eu.solven.kumite.board.BoardLifecycleManager;
|
17 | 20 | import eu.solven.kumite.board.BoardLifecycleManagerHelper;
|
| 21 | +import eu.solven.kumite.board.BoardMutator; |
18 | 22 | import eu.solven.kumite.board.BoardsRegistry;
|
| 23 | +import eu.solven.kumite.board.EnabledPlayers; |
19 | 24 | import eu.solven.kumite.board.realtime.RealTimeBoardManager;
|
20 | 25 | import eu.solven.kumite.contest.ContestsRegistry;
|
21 | 26 | import eu.solven.kumite.eventbus.ActivityLogger;
|
|
58 | 63 |
|
59 | 64 | KumiteAutomatedSpringConfig.class,
|
60 | 65 |
|
| 66 | + EnabledPlayers.class, |
61 | 67 | BoardLifecycleManagerHelper.class,
|
62 | 68 |
|
63 | 69 | })
|
64 | 70 | @Slf4j
|
65 | 71 | public class KumiteServerComponentsConfiguration {
|
66 | 72 |
|
67 | 73 | @Bean
|
68 |
| - @Qualifier(IGameMetadataConstants.TAG_TURNBASED) |
69 |
| - public BoardLifecycleManager tbBoardLifecycleManager(BoardLifecycleManagerHelper helper) { |
70 |
| - final Executor boardEvolutionExecutor = Executors.newFixedThreadPool(4); |
71 |
| - boardEvolutionExecutor |
72 |
| - .execute(() -> log.info("This flags the tbThreadPool threadName={}", Thread.currentThread().getName())); |
| 74 | + BoardMutator boardMutator(BoardLifecycleManagerHelper helper, EnabledPlayers enabledPlayer) { |
| 75 | + int nbThreads = 4; |
| 76 | + List<ExecutorService> boardMutationExecutors = IntStream.range(0, nbThreads).mapToObj(i -> { |
| 77 | + ExecutorService es = Executors.newSingleThreadExecutor(); |
| 78 | + es.execute(() -> log.info("This flags the boardMutator threadPool #{} threadName={}", |
| 79 | + i, |
| 80 | + Thread.currentThread().getName())); |
| 81 | + return es; |
| 82 | + }).collect(Collectors.toList()); |
| 83 | + |
| 84 | + return new BoardMutator(helper, enabledPlayer, boardMutationExecutors); |
| 85 | + } |
73 | 86 |
|
74 |
| - return new BoardLifecycleManager(helper, boardEvolutionExecutor); |
| 87 | + // Should we keep different BoardLifecycleManager? For now, we rely on a single complex RealTimeBoardManager |
| 88 | + // @Bean |
| 89 | + @Qualifier(IGameMetadataConstants.TAG_TURNBASED) |
| 90 | + public BoardLifecycleManager tbBoardLifecycleManager(BoardLifecycleManagerHelper helper, |
| 91 | + BoardMutator boardMutator) { |
| 92 | + return new BoardLifecycleManager(helper, boardMutator); |
75 | 93 | }
|
76 | 94 |
|
77 | 95 | // We can have multiple BoardLifecycleManager/boardEvolutionExecutor as long as a given contest is guaranteed to be
|
78 | 96 | // processed by a single executor
|
79 | 97 | @Bean
|
80 | 98 | @Qualifier(IGameMetadataConstants.TAG_REALTIME)
|
81 |
| - public RealTimeBoardManager rtBoardLifecycleManager(BoardLifecycleManagerHelper helper) { |
82 |
| - final Executor boardEvolutionExecutor = Executors.newFixedThreadPool(4); |
83 |
| - boardEvolutionExecutor |
84 |
| - .execute(() -> log.info("This flags the rtThreadPool threadName={}", Thread.currentThread().getName())); |
85 |
| - |
86 |
| - return new RealTimeBoardManager(helper, boardEvolutionExecutor); |
| 99 | + public RealTimeBoardManager rtBoardLifecycleManager(BoardLifecycleManagerHelper helper, BoardMutator boardMutator) { |
| 100 | + return new RealTimeBoardManager(helper, boardMutator); |
87 | 101 | }
|
88 | 102 |
|
89 | 103 | @Bean
|
|
0 commit comments