Repository navigation
[FEAT] 중도 입장 청중 동기화를 위한 SYNC 이벤트 추가 #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
89 changes: 89 additions & 0 deletions
89
src/main/java/com/debatetimer/event/sharing/RoomSubscribeInterceptor.java
This file contains hidden or 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,89 @@ | ||
| package com.debatetimer.event.sharing; | ||
|
|
||
| import com.debatetimer.domain.sharing.TimerEventType; | ||
| import com.debatetimer.dto.sharing.request.ChairmanSharingRequest; | ||
| import com.debatetimer.dto.sharing.response.SharingResponse; | ||
| import com.debatetimer.exception.custom.DTClientErrorException; | ||
| import com.debatetimer.exception.errorcode.ClientErrorCode; | ||
| import com.debatetimer.service.sharing.SharingRoomRegistry; | ||
| import org.springframework.context.annotation.Lazy; | ||
| import org.springframework.messaging.Message; | ||
| import org.springframework.messaging.MessageChannel; | ||
| import org.springframework.messaging.MessageHandler; | ||
| import org.springframework.messaging.simp.SimpMessageHeaderAccessor; | ||
| import org.springframework.messaging.simp.SimpMessageType; | ||
| import org.springframework.messaging.simp.SimpMessagingTemplate; | ||
| import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler; | ||
| import org.springframework.messaging.support.ExecutorChannelInterceptor; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** | ||
| * simple broker가 청중의 룸 구독을 등록한 뒤에 후속 메시지를 보낸다. | ||
| * SessionSubscribeEvent는 구독 등록 전에 발행될 수 있어, 그 시점에 룸으로 보내면 새 청중이 받지 못할 수 있다. | ||
| */ | ||
| @Component | ||
| public class RoomSubscribeInterceptor implements ExecutorChannelInterceptor { | ||
|
|
||
| private static final String AUDIENCE_SUBSCRIBE_PREFIX = "/room/"; | ||
| private static final String CHAIRMAN_CHANNEL_PREFIX = "/chairman/"; | ||
|
|
||
| private final SimpMessagingTemplate messagingTemplate; | ||
| private final SharingRoomRegistry sharingRoomRegistry; | ||
|
|
||
| public RoomSubscribeInterceptor( | ||
| @Lazy SimpMessagingTemplate messagingTemplate, | ||
| SharingRoomRegistry sharingRoomRegistry | ||
| ) { | ||
| this.messagingTemplate = messagingTemplate; | ||
| this.sharingRoomRegistry = sharingRoomRegistry; | ||
| } | ||
|
|
||
| @Override | ||
| public void afterMessageHandled(Message<?> message, MessageChannel channel, MessageHandler handler, Exception ex) { | ||
| if (ex != null || !(handler instanceof SimpleBrokerMessageHandler)) { | ||
| return; | ||
| } | ||
|
|
||
| SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.wrap(message); | ||
| String destination = accessor.getDestination(); | ||
| if (accessor.getMessageType() != SimpMessageType.SUBSCRIBE || destination == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (destination.startsWith(CHAIRMAN_CHANNEL_PREFIX)) { | ||
| handleChairmanSubscribe(destination); | ||
| return; | ||
| } | ||
|
|
||
| if (destination.startsWith(AUDIENCE_SUBSCRIBE_PREFIX)) { | ||
| handleAudienceSubscribe(destination); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * 사회자의 구독은 공유 시작을 뜻하므로, 이전에 종료된 룸이라도 다시 진행 상태로 되돌린다. | ||
| */ | ||
| private void handleChairmanSubscribe(String destination) { | ||
| long roomId = parseRoomId(destination, CHAIRMAN_CHANNEL_PREFIX); | ||
| sharingRoomRegistry.reopen(roomId); | ||
| } | ||
|
|
||
| private void handleAudienceSubscribe(String destination) { | ||
| long roomId = parseRoomId(destination, AUDIENCE_SUBSCRIBE_PREFIX); | ||
| if (sharingRoomRegistry.isFinished(roomId)) { | ||
| messagingTemplate.convertAndSend(AUDIENCE_SUBSCRIBE_PREFIX + roomId, | ||
| new SharingResponse(TimerEventType.FINISHED)); | ||
| return; | ||
| } | ||
| messagingTemplate.convertAndSend(CHAIRMAN_CHANNEL_PREFIX + roomId, new ChairmanSharingRequest(roomId)); | ||
| } | ||
|
|
||
| private long parseRoomId(String destination, String prefix) { | ||
| try { | ||
| String parsedRoomId = destination.substring(prefix.length()); | ||
| return Long.parseLong(parsedRoomId); | ||
| } catch (NumberFormatException exception) { | ||
| throw new DTClientErrorException(ClientErrorCode.INVALID_ROOM_ID); | ||
| } | ||
| } | ||
| } | ||
47 changes: 0 additions & 47 deletions
47
src/main/java/com/debatetimer/event/sharing/RoomSubscribeListener.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
20 changes: 20 additions & 0 deletions
20
src/main/java/com/debatetimer/scheduler/SharingRoomCleanupScheduler.java
This file contains hidden or 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,20 @@ | ||
| package com.debatetimer.scheduler; | ||
|
|
||
| import com.debatetimer.service.sharing.SharingRoomRegistry; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class SharingRoomCleanupScheduler { | ||
|
|
||
| private static final long INTERVAL_MILLIS = 60 * 60 * 1000L; | ||
|
|
||
| private final SharingRoomRegistry sharingRoomRegistry; | ||
|
|
||
| @Scheduled(fixedRate = INTERVAL_MILLIS) | ||
| public void cleanupExpiredRooms() { | ||
| sharingRoomRegistry.removeExpired(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.