Skip to content
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-5013] feat: Implement room lifecycle monitoring #94

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

sacOO7
Copy link
Contributor

@sacOO7 sacOO7 commented Jan 6, 2025

  1. Implemented thread-safe ScopeEmitter ( Behaviour might look same as Hot Flows, but it avoid problems associated with hot flows. Added comment -> [ECO-5013] feat: Implement room lifecycle monitoring #94 (comment)
  2. Added impl. for the same as a part of RoomLifeCycleManager

@github-actions github-actions bot temporarily deployed to staging/pull/94/dokka January 6, 2025 12:52 Inactive
1. Defined standard Emitter interface as per RTE emitter spec
2. Added thread safe impl. for the same in ScopedEmitter class
3. Added private AsyncSubscriber class to process events in the given order
2. Added related unit tests covering all edge cases
@sacOO7 sacOO7 force-pushed the feature/CHA-RL4-room-monitoring branch from 4c60f8b to a7323c1 Compare January 7, 2025 11:59
@github-actions github-actions bot temporarily deployed to staging/pull/94/dokka January 7, 2025 12:01 Inactive
Copy link

github-actions bot commented Jan 7, 2025

Code Coverage

File Coverage [88.98%]
chat-android/src/main/java/com/ably/chat/Emitter.kt 97.67%
chat-android/src/main/java/com/ably/chat/RoomLifecycleManager.kt 87.84%
Total Project Coverage 85.81%

* Kotlin Emitter interface for supplied value
* Spec: RTE1
*/
internal interface Emitter<V> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think we need this, as we’re essentially reinventing Flow here. Additionally, we’re missing some crucial points in the ScopedEmitter implementation. In its current form, listeners will be invoked non-sequentially, which can be misleading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping we could have a discussion about this eventually. I don't think we're trying to reinvent the wheel here, though the implementation might resemble shared or hot flows.

Unlike cold flows, hot flows continue emitting values even if no one is actively collecting them. This can lead to situations where the flow keeps emitting values even when the component is in the background, which could potentially cause memory leaks.

Additionally, the flow API is well-suited for use in coroutine-based functions, as both emit and collect are suspending functions. On the other hand, tryEmit can be used in non-suspending functions (like the channel.on method here), although it's generally not recommended.

Since tryEmit() is not a suspending function, it requires a buffer to store the emitted values until they are processed by subscribers. To make this work, we need to set the buffer size to unlimited, but this can affect performance and slow down other subscribers.

Another challenge is canceling flows, as there’s no guarantee that queued events will be delivered when cancellation occurs.

I'll create a separate thread to dive deeper into this and explore how the Emitter implementation can be leveraged for the existing public API to handle messages and presence events asynchronously on the Dispatchers.Default scope, as opposed to relying on the current blocking subscribers.

1. Updated init method to include setting up ContributorListeners
2. Initialized property contributorStateChangeMonitor using ScopedEmitter
to track feature channel state changes
@github-actions github-actions bot temporarily deployed to staging/pull/94/dokka January 7, 2025 13:05 Inactive
sacOO7 added 2 commits January 8, 2025 15:58
…flag

tied to part of atomicCoroutineScope operations
1. Temporarily removed use of transientDetachTimeout since more clarity
needed from spec point of view
2. Added room monitoring impl. for each feature channel attach, update,
attaching, suspended and failed events
3. Updated release() method to remove all monitoring listeners when room
is released
Copy link

coderabbitai bot commented Jan 8, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot temporarily deployed to staging/pull/94/dokka January 8, 2025 13:31 Inactive
@sacOO7
Copy link
Contributor Author

sacOO7 commented Jan 8, 2025

TODO's

  • (CHA-RL4) A room must monitor the state of its contributors Realtime Channels and act upon any changes.
  • (CHA-RL4a) The state monitor must handle UPDATE events from each contributors underlying Realtime Channel
  • (CHA-RL4a1) [Testable] If the resumed flag of the update is set to true, then no action should be taken (i.e. CHA-RL4a3 and CHA-RL4a4 behaviours are not performed).
  • (CHA-RL4a2) [Testable] If the given contributor has not yet successfully managed to attach its Realtime Channel (i.e. no call to attach() on the channel, per CHA-RL1f, has succeeded), then no action should be taken (i.e. CHA-RL4a3 and CHA-RL4a4 behaviours are not performed).
  • (CHA-RL4a3) [Testable] If a room lifecycle operation is in progress, then a pending discontinuity event shall be recorded for this contributor – though it must not overwrite any existing discontinuity event. The ErrorInfo associated with the discontinuity shall be the reason for the underlying channel state change. The event will be notified to the contributor at a later point, as noted in this specification.
  • (CHA-RL4a4) [Testable] If a room lifecycle operation is not in progress, then a discontinuity event will immediately be emitted to the contributor. The ErrorInfo associated with the discontinuity shall be the reason for the underlying channel state change.
  • (CHA-RL4b) The state monitor must handle non-UPDATE channel state events.
  • (CHA-RL4b1) [Testable] If a room lifecycle operation is in progress, and the new channel state is ATTACHED, and the resumed flag is false, and the particular contributor has been attached previously (i.e. a previous call to attach() on the channel, per CHA-RL1f, has succeeded), then a pending discontinuity event will be recorded for the contributor. The error associated with this event shall be the reason for the channel state change.
  • (CHA-RL4b2) This specification point has been removed.
  • (CHA-RL4b3) This specification point has been removed.
  • (CHA-RL4b4) This specification point has been removed.
  • (CHA-RL4b5) [Testable] If a room lifecycle operation is not in progress and the channel state is FAILED, then the room status shall be transitioned to FAILED, using the reason for the channel state change as the error for the room status change. All transient disconnect timeouts are cancelled and a CHA-RL2f detach procedure is performed.
  • (CHA-RL4b6) This specification point has been removed.
  • (CHA-RL4b7) [Testable] If a room lifecycle operation is not in progress and the channel state is ATTACHING and no transient disconnect timeout exists for the contributor, then a transient disconnect timeout with a 5 second limit is created for the contributor. Upon timeout, the room status is transitioned to ATTACHING, using the reason from the initial channel state change as the error for the transition.
  • (CHA-RL4b10) [Testable] If a room lifecycle operation is not in progress and the channel state is ATTACHED and a transient disconnect timeout exists for the contributor, the timeout is cleared.
  • (CHA-RL4b8) [Testable] If a room lifecycle operation is not in progress, the channel state is ATTACHED, the room status is NOT ATTACHED and all contibutors channel are now ATTACHED, the room status is transitioned to ATTACHED.
  • (CHA-RL4b9) [Testable] If a room lifecycle operation is not in progress and the channel state is SUSPENDED, then the room status is transitioned to SUSPENDED, using the reason of the channel state change as the error. Any transient disconnect timeouts are cancelled and the room enters the RETRY loop.
  • Annotate code with relevant spec id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants