-
Notifications
You must be signed in to change notification settings - Fork 1
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
[ECO-5099] Update RoomStatus and ConnectionStatus interfaces #48
Changes from all commits
ad8c071
0fae205
3527b1c
aeb2ba3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
package com.ably.chat | ||
|
||
import io.ably.lib.types.ErrorInfo | ||
import io.ably.lib.util.Log.LogHandler | ||
import kotlinx.coroutines.CoroutineName | ||
import kotlinx.coroutines.CoroutineScope | ||
|
@@ -56,20 +57,37 @@ interface Room { | |
*/ | ||
val occupancy: Occupancy | ||
|
||
/** | ||
* Returns the room options. | ||
* | ||
* @returns A copy of the options used to create the room. | ||
*/ | ||
val options: RoomOptions | ||
|
||
/** | ||
* (CHA-RS2) | ||
* Returns an object that can be used to observe the status of the room. | ||
* The current status of the room. | ||
* | ||
* @returns The status observable. | ||
* @returns The current status. | ||
*/ | ||
val status: RoomStatus | ||
|
||
/** | ||
* Returns the room options. | ||
* | ||
* @returns A copy of the options used to create the room. | ||
* The current error, if any, that caused the room to enter the current status. | ||
*/ | ||
val options: RoomOptions | ||
val error: ErrorInfo? | ||
|
||
/** | ||
* Registers a listener that will be called whenever the room status changes. | ||
* @param listener The function to call when the status changes. | ||
* @returns An object that can be used to unregister the listener. | ||
*/ | ||
fun onStatusChange(listener: RoomLifecycle.Listener): Subscription | ||
|
||
/** | ||
* Removes all listeners that were added by the `onStatusChange` method. | ||
*/ | ||
fun offAllStatusChange() | ||
|
||
/** | ||
* Attaches to the room to receive events in realtime. | ||
|
@@ -98,7 +116,6 @@ internal class DefaultRoom( | |
) : Room { | ||
|
||
private val _logger = logger | ||
override val status = DefaultStatus(logger) | ||
|
||
/** | ||
* RoomScope is a crucial part of the Room lifecycle. It manages sequential and atomic operations. | ||
|
@@ -132,9 +149,18 @@ internal class DefaultRoom( | |
override val occupancy = DefaultOccupancy( | ||
messages = messages, | ||
) | ||
|
||
private var _lifecycleManager: RoomLifecycleManager? = null | ||
|
||
private val _statusLifecycle = DefaultRoomLifecycle(logger) | ||
internal val statusLifecycle: DefaultRoomLifecycle | ||
get() = _statusLifecycle | ||
|
||
override val status: RoomStatus | ||
get() = _statusLifecycle.status | ||
|
||
override val error: ErrorInfo? | ||
get() = _statusLifecycle.error | ||
|
||
init { | ||
/** | ||
* TODO | ||
|
@@ -143,15 +169,21 @@ internal class DefaultRoom( | |
* Currently, all features are initialized by default. | ||
*/ | ||
val features = listOf(messages, presence, typing, reactions, occupancy) | ||
_lifecycleManager = RoomLifecycleManager(roomScope, status, features, _logger) | ||
_lifecycleManager = RoomLifecycleManager(roomScope, _statusLifecycle, features, _logger) | ||
/** | ||
* TODO | ||
* Make sure previous release op. for same was a success. | ||
* Make sure channels were removed using realtime.channels.release(contributor.channel.name); | ||
* Once this is a success, set room to initialized, if not set it to failed and throw error. | ||
* Note that impl. can change based on recent proposed changes to chat-room-lifecycle DR. | ||
*/ | ||
this.status.setStatus(RoomLifecycle.Initialized) | ||
this._statusLifecycle.setStatus(RoomStatus.Initialized) | ||
} | ||
Comment on lines
+172
to
+181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Address TODO comments and verify initialization sequence. The initialization logic contains multiple TODO comments indicating incomplete implementation:
These TODOs seem critical for proper room lifecycle management. Would you like me to help create GitHub issues to track these TODOs? They should cover:
|
||
|
||
override fun onStatusChange(listener: RoomLifecycle.Listener): Subscription = _statusLifecycle.onChange(listener) | ||
|
||
override fun offAllStatusChange() { | ||
_statusLifecycle.offAll() | ||
} | ||
|
||
override suspend fun attach() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Thread-safety concerns identified in status lifecycle management
The current implementation of
DefaultRoomLifecycle
has potential thread-safety issues:_status
and_error
) is accessed without synchronizationsetStatus
method modify shared state and emit events without thread coordinationEventEmitter
base class implementation needs to be verified for thread-safe event handlingRecommendations:
@Synchronized
to thesetStatus
methodsAtomicReference
for_status
and_error
fieldsEventEmitter
base class has thread-safe listener management🔗 Analysis chain
Verify thread-safety of status lifecycle management.
The status lifecycle implementation looks good, but let's verify the thread-safety of status updates.
Let me gather more information about the
DefaultRoomLifecycle
implementation to verify its thread-safety.Let me check for any synchronization mechanisms in the RoomStatus.kt file and look for event listeners that might be involved in concurrent access.
Let me check the implementation of RoomStatusEventEmitter and AtomicCoroutineScope since they seem to be key components in handling concurrent operations.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 10485
Script:
Length of output: 1213
Script:
Length of output: 1440
Script:
Length of output: 8045