This repository was archived by the owner on Jul 24, 2023. It is now read-only.
New message servlet#92
Open
tgomezzzz wants to merge 26 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR creates the servlet that handles new messages, bringing together MessagePromises and MessageUpdates to provide group chat functionality. In summary, clients send GET requests to the servlet, which creates a MessagePromise for each GET request. These MessagePromises block, so their GET requests are unable to respond to the client until they are awakened. When a client sends a new message via a POST request, the servlet stores the message in a MessageUpdate object. The MessageUpdate wakes each waiting MessagePromise and copies the message into it, allowing them to return the new message to the client. Upon successfully receiving a response, clients immediately send another GET request, so they are always waiting for the next message.
I relied on the following source to help implement this feature, particularly to understand how to use the observer pattern: https://docstore.mik.ua/orelly/java-ent/servlet/ch10_03.htm.
Known issue: When multiple clients are on a group chat, all but one of the client's GET requests are received by the server at the expected time. Testing showed that the clients all send their requests at the same time via fetch(), but the servlet consistently receives one, stalls for ~20 seconds, and then receives the remaining requests all at once. Sending a message within this 20 second period results in only one client seeing it (the sole client whose request was received), but if messages occur at least 20 seconds after each other, the group chat behaves as expected. After discussing with a VSE, I think this might have to do with a limit that the browser places on the number of requests that can be sent to a URL in a certain time frame.