Skip to content
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
feature-groupchatfrom
new-message-servlet
Open

New message servlet#92
tgomezzzz wants to merge 26 commits into
feature-groupchatfrom
new-message-servlet

Conversation

@tgomezzzz

Copy link
Copy Markdown
Contributor

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.

@tgomezzzz
tgomezzzz requested review from Rmoneygit and angplee July 31, 2020 18:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant