From e8f70335dc2af1bd31c97731fdc0401ff32aab2e Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Wed, 4 Dec 2024 18:58:29 +0530 Subject: [PATCH] [ECO-5165][CHA-RC1] Implement logging for Rooms 1. Added private property roomsLogger for DefaultRooms class 2. Added basic logging for Rooms#get method --- chat-android/src/main/java/com/ably/chat/Rooms.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/chat-android/src/main/java/com/ably/chat/Rooms.kt b/chat-android/src/main/java/com/ably/chat/Rooms.kt index 5193ba5f..1a6c4cf0 100644 --- a/chat-android/src/main/java/com/ably/chat/Rooms.kt +++ b/chat-android/src/main/java/com/ably/chat/Rooms.kt @@ -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. @@ -76,22 +77,28 @@ internal class DefaultRooms( private val roomReleaseDeferred: MutableMap> = 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 { @@ -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) }