-
- Downloads
server: Refactor to use per-instance locking
Instead of having a `WebServer` object handling state machine state and a `WebSocketsCollection` handling websocket connections, we now have all per-instance state in `ServerApp` objects: websocket connections are tracked in `ServerApp.channels`, and state-machine state is in `StateMachineServerApp.state`. Updates to different instances can happen in parallel: synchronization happens at the level of independent apps. Also take this opportunity to clean up clock-driven apps: events are now sent unserialized, rather than being serialized and immediately deserialized afterwards. * jvm/src/main/scala/cs214/webapp/server/web/WebServer.scala: (Wordlist): New class. Move wordlist management here. (instanceIdWords): Load wordlist just once, eagerly. (RunningClock, RunningServerAppInstance): Remove (moved to `ServerApp.scala`) (apps): Rename to `instances`. (register): Overload to handle clock-driven and regular state machines separately. (withFreshInstanceId): New function. (createInstance): Simplify by moving functionality to `withFreshInstanceId` and `Wordlist`. (startClockFor, transition, handleMessage): Move functionality to `ServerApp.scala`. * jvm/src/main/scala/cs214/webapp/server/web/WebSocketsCollection.scala: Delete and merge all functionality into ServerApp.scala. * jvm/src/main/scala/cs214/webapp/server/web/ServerApp.scala: (ServerApp): Rename to `ServerAppFactory`. Add `instanceId` to `init` signature. (ServerAppInstance): Rename to `ServerApp`. Extend to handle websocket state. Implement a `shutdown` API to close all websocket connections. Synchronize every method on a per-instance lock. (StateMachineServerAppInstance): Rename to `StateMachineServerApp`. (Clock, ClockDrivenStateMachineServerApp): New classes. Move clock threads here and use the new `project` API to send unserialized Tick events. * jvm/src/main/scala/cs214/webapp/server/ApplicationJVM.scala: Don't allow repeated registrations. * jvm/src/main/scala/cs214/webapp/server/web/WebServerRoutes.scala: (getAppInfo): Avoid race condition due to `.contains` … `.apply` pattern.
Showing
- jvm/src/main/scala/cs214/webapp/server/ApplicationJVM.scala 8 additions, 9 deletionsjvm/src/main/scala/cs214/webapp/server/ApplicationJVM.scala
- jvm/src/main/scala/cs214/webapp/server/web/ServerApp.scala 167 additions, 42 deletionsjvm/src/main/scala/cs214/webapp/server/web/ServerApp.scala
- jvm/src/main/scala/cs214/webapp/server/web/WebServer.scala 49 additions, 142 deletionsjvm/src/main/scala/cs214/webapp/server/web/WebServer.scala
- jvm/src/main/scala/cs214/webapp/server/web/WebServerRoutes.scala 8 additions, 7 deletions.../main/scala/cs214/webapp/server/web/WebServerRoutes.scala
- jvm/src/main/scala/cs214/webapp/server/web/WebSocketsCollection.scala 0 additions, 68 deletions.../scala/cs214/webapp/server/web/WebSocketsCollection.scala
Loading
Please register or sign in to comment