MovingBlocks / FacadeServer

A headless facade that acts as a game host and provides web-based administration. Automation category: Terasology Facade. See https://forum.terasology.org/threads/facadeserver-headless-server-with-web-interface.1906
Apache License 2.0
4 stars 11 forks source link

Modules install resource #5

Closed gianluca-nitti closed 7 years ago

gianluca-nitti commented 7 years ago

This small pull request adds the feature which allows server administrators to install modules in the server using the web interface or API.

The added resource, ModuleInstallerResource:

Important: for this to work, the engine must be built including my commits on pull request MovingBlocks/Terasology#3028; FacadeServer won't compile if classes introduced in that PR, like ModuleInstallManager, are missing.

gianluca-nitti commented 7 years ago

Update: while doing some additional testing I noticed that the WebSocket connection between the server and the web interface was frequently dropping when using this feature. After researching a bit of information about the exception that was being thrown by some Jetty internal class, I found out that there was a concurrency issue - multiple threads sometimes were trying to send WebSocket messages at the same time (when the write method of a WritableResource returns, an ActionResult whose content depends on whether the method threw a ResourceAccessException or not is sent to the client, but inside that method ModuleInstallerResource starts a parallel task to download the new modules which can send messages to report progress), and the previously used method didn't support this. So I solved this issue in the latest commit by simply switching to another override of the sendString method of the RemoteEndpoint Jetty class; the currently used version is non-blocking, returns immediately and then calls a callback after the message has been sent. Looks like everything works correctly now. The method's javadoc isn't very exhaustive but the comment in the Jetty bug tracker talks about an internal buffer so in my understanding the messages are queued and then sent once at a time to the underlying socket.

msteiger commented 7 years ago

Great find about the Jetty "deficiency".

Cervator commented 7 years ago

Engine PR has been merged, I think this one can be as well now :-)

msteiger commented 7 years ago

Thanks @Cervator and @gianluca-nitti of course.