Skip to content

Commit

Permalink
[ECO-5095][CHA-RL*] Implement logging for RoomLifecycleManager
Browse files Browse the repository at this point in the history
1. Added private property logger with thread specific dynamic context
2. Added trace, debug, error logging for private doRetry method
3. Added trace, debug, error logging for attach method
4. Added trace, debug, error logging for detach method
5. Added trace, debug, error logging for release method
6. Added helper method to join with brackets for string list
  • Loading branch information
sacOO7 committed Dec 12, 2024
1 parent 91049c9 commit ba6eeb8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion chat-android/src/main/java/com/ably/chat/Room.kt
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ internal class DefaultRoom(

lifecycleManager = RoomLifecycleManager(roomScope, statusLifecycle, roomFeatures, this.logger)

this.logger.debug("Initialized with features: ${roomFeatures.joinToString { it.featureName }}")
this.logger.debug("Initialized with features: ${roomFeatures.map { it.featureName }.joinWithBrackets}")
}

override fun onStatusChange(listener: RoomLifecycle.Listener): Subscription =
Expand Down
12 changes: 6 additions & 6 deletions chat-android/src/main/java/com/ably/chat/RoomLifecycleManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ internal class RoomLifecycleManager(
private suspend fun doAttach(): RoomAttachmentResult {
logger.trace("doAttach();")
val attachResult = DefaultRoomAttachmentResult()
logger.debug("doAttach(); trying to attach all features: ${contributors.joinToString { it.featureName }}")
logger.debug("doAttach(); trying to attach all features: ${contributors.map { it.featureName }.joinWithBrackets}")
for (feature in contributors) { // CHA-RL1f - attach each feature sequentially
try {
logger.debug("doAttach(); attaching feature: ${feature.featureName}")
Expand Down Expand Up @@ -425,7 +425,7 @@ internal class RoomLifecycleManager(
}

// CHA-RL1g, We successfully attached all the channels - set our status to attached, start listening changes in channel status
logger.debug("doAttach(); attach success for all features: ${contributors.joinToString { it.featureName }}")
logger.debug("doAttach(); attach success for all features: ${contributors.map { it.featureName }.joinWithBrackets}")
this.statusLifecycle.setStatus(attachResult)
logger.debug("doAttach(); transitioned room to ATTACHED state")
this.operationInProgress = false
Expand Down Expand Up @@ -569,7 +569,7 @@ internal class RoomLifecycleManager(
*/
private suspend fun doDetach() {
logger.trace("doDetach();")
logger.debug("doDetach(); detaching all features: ${contributors.joinToString { it.featureName }}")
logger.debug("doDetach(); detaching all features: ${contributors.map { it.featureName }.joinWithBrackets}")
var channelWindDown = kotlin.runCatching { doChannelWindDown() }
var firstContributorFailedError: AblyException? = null
while (channelWindDown.isFailure) { // CHA-RL2h
Expand All @@ -584,7 +584,7 @@ internal class RoomLifecycleManager(

// CHA-RL2g - If we aren't in the failed state, then we're detached
if (statusLifecycle.status !== RoomStatus.Failed) {
logger.debug("doDetach(); successfully detached all features: ${contributors.joinToString { it.featureName }}")
logger.debug("doDetach(); successfully detached all features: ${contributors.map { it.featureName }.joinWithBrackets}")
statusLifecycle.setStatus(RoomStatus.Detached)
logger.debug("doDetach(); transitioned room to DETACHED state")
return
Expand Down Expand Up @@ -640,14 +640,14 @@ internal class RoomLifecycleManager(
*/
private suspend fun releaseChannels() {
logger.trace("releaseChannels();")
logger.debug("releaseChannels(); releasing all features: ${contributors.joinToString { it.featureName }}")
logger.debug("releaseChannels(); releasing all features: ${contributors.map { it.featureName }.joinWithBrackets}")
var contributorsReleased = kotlin.runCatching { doRelease() }
while (contributorsReleased.isFailure) {
// Wait a short period and then try again
delay(retryDurationInMs)
contributorsReleased = kotlin.runCatching { doRelease() }
}
logger.debug("releaseChannels(); success, released all features: ${contributors.joinToString { it.featureName }}")
logger.debug("releaseChannels(); success, released all features: ${contributors.map { it.featureName }.joinWithBrackets}")
}

/**
Expand Down
2 changes: 2 additions & 0 deletions chat-android/src/main/java/com/ably/chat/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ val Channel.errorMessage: String
", ${reason.message}"
}

val List<String>.joinWithBrackets: String get() = joinToString(prefix = "[", postfix = "]") { it }

@Suppress("FunctionName")
fun ChatChannelOptions(init: (ChannelOptions.() -> Unit)? = null): ChannelOptions {
val options = ChannelOptions()
Expand Down

0 comments on commit ba6eeb8

Please sign in to comment.