TinaTiel / obs-chatbot

GNU General Public License v3.0
3 stars 0 forks source link

Refactor: Use MasterQueue + Router + ClientQueues instead of direct client references #57

Closed TinaTiel closed 3 years ago

TinaTiel commented 3 years ago

When thinking about #40 and researching re-registering beans etc. in Spring one thing was pretty consistent: Having a direct reference to the things most likely to go down (the Clients) via DI was making this super hard (not to mention, difficult to test)

So, what if we removed the references entirely and replaced it with a queue-based system? image

The idea is this:

  1. A Command and a RequestContext (username, args) are submitted to a (chat) CommandDispatcher
  2. The Command is parsed into a list of Actions, and combined with the RequestContext (username, args), to create a list of ActionCommands; each has the (a) the data specific to that Action, (b) a copy of the RequestContext, and (c) intended recipient (client)
  3. The list of ActionCommands is packaged into a Request object that has a new sequential-executor in it.
  4. The Request object is submitted to the (chat) CommandExecutor.
  5. When the CommandExecutor runs a request, the sequential-executor submits the ActionCommand to a MasterActionQueue (receiving a Future) and it will block in its own thread pending result of the Future.
  6. At the point, we could in a test poke around in the MasterActionQueue to verify the expected ActionCommands are there, but I digress...
  7. A MasterActionQueueRouter pulls items from the queue and, using the indended recipient, sends them to the correct ObsActionQueue, ChatActionQueue, etc.
  8. Optionally, Clients listen to their respective queues and execute in FIFO order. I say "Optional" because we may need to re-instantiate a client at runtime if its parameters change...Or we may register more clients to deal with load, etc.

With THIS architecture, compared to the previous, we solve several problems:

TinaTiel commented 3 years ago

Working on building out the delegators atm, see e3da89214f3a441b7f7cc43985ac43e839f6373e

TinaTiel commented 3 years ago

Router and MainQueue complete in e10d699

TinaTiel commented 3 years ago

Since we're using a ClientManager instead of the Client directly, going to work #58 as part of this now.