Skip to content

Commit

Permalink
[ECO-5165][CHA-RC1] Implement logging for Rooms
Browse files Browse the repository at this point in the history
1. Added private property roomsLogger for DefaultRooms class
2. Added basic logging for Rooms#get method
  • Loading branch information
sacOO7 committed Dec 4, 2024
1 parent b84b113 commit e8f7033
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions chat-android/src/main/java/com/ably/chat/Rooms.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ internal class DefaultRooms(
private val chatApi: ChatApi,
override val clientOptions: ClientOptions,
private val clientId: String,
private val logger: Logger,
logger: Logger,
) : Rooms {
private val roomsLogger = logger.withContext(tag = "Rooms")

/**
* All operations for DefaultRooms should be executed under sequentialScope to avoid concurrency issues.
Expand All @@ -76,22 +77,28 @@ internal class DefaultRooms(
private val roomReleaseDeferred: MutableMap<String, CompletableDeferred<Unit>> = mutableMapOf()

override suspend fun get(roomId: String, options: RoomOptions): Room {
roomsLogger.trace("Rooms.get(); $roomId")

return sequentialScope.async {
val existingRoom = getReleasedOrExistingRoom(roomId)
existingRoom?.let {
if (options != existingRoom.options) { // CHA-RC1f1
throw ablyException("room already exists with different options", ErrorCode.BadRequest)
}
roomsLogger.debug("Rooms.get(); returning existing room with roomId: ${existingRoom.roomId}")
return@async existingRoom // CHA-RC1f2
}
// CHA-RC1f3
val newRoom = makeRoom(roomId, options)
roomIdToRoom[roomId] = newRoom
roomsLogger.debug("Rooms.get(); returning new room with roomId: ${newRoom.roomId}")
return@async newRoom
}.await()
}

override suspend fun release(roomId: String) {
roomsLogger.trace("Rooms.release(); $roomId")

sequentialScope.launch {
// CHA-RC1g4 - Previous Room Get in progress, cancel all of them
roomGetDeferred[roomId]?.let {
Expand Down Expand Up @@ -167,5 +174,5 @@ internal class DefaultRooms(
* Spec: CHA-RC1f3
*/
private fun makeRoom(roomId: String, options: RoomOptions): DefaultRoom =
DefaultRoom(roomId, options.copy(), realtimeClient, chatApi, clientId, logger)
DefaultRoom(roomId, options.copy(), realtimeClient, chatApi, clientId, roomsLogger)
}

0 comments on commit e8f7033

Please sign in to comment.