mardi 6 août 2019

What best practice/design pattern for Queue input where input varies and time framing

I have developed an application to interact with a vending machine. My application has a two way communication where the machine sends different inputs. Inputs might come in in different time (unexpected) however, a cycle of operations is predefined.

In other words, let's consider a general scenario where

  1. machine sends a signal as a trigger for a cycle of operations as a use key in a selection,
  2. then my device will check on the input to ensure it is a request (if not a request, then just ignore - at least for now),
  3. if yes then my application will send acknowledgement of receiving input to the machine and proceed with do some processing, if not then my app will ignore
  4. one processing is done, my app will send a signal to proceed further or for cancellation of the cycle (order)
  5. if to proceed then, my app will send a proceeding signal and waiting a respond upon a machine completion
  6. if the machine sends an error signal then a cancellation process is started

I just gave a scenario, as you can see machine inputs might pop up here and there due to for example but limited to, a user selects many times or reselect again during the process at the beggining or at any time. Interruption might happen any time due to long process network latency where the vending machine will wait for awhile and then sends a cancel signal and my application has to act accordingly, etc.

Long story short, as you can see the process might invovle many factors and input from machine, user, time,... However, a cycle of operation is defined (1) receiving order, (2) validation, (3) send dispense signal, (4) receives succ/err signal. but in between many things might happen and many scenario are invovled.

FYI: 1. to keep receiving signal from the vending machine, I am using a buffer (queue) with a separate thread 2. I am using state design pattern

However, I feel the code has become messy as I need for example during waiting for success signal from the machine to remove/pull those input non-relevant such as request ones,... I am trying to present the pain in here as input is unpredictable. it is not a straigtforward process.

my questions:

  1. anything that could help me to control inputs/signals
  2. how to avoid having multiple buffer pulls inside the states looking for the expected input
  3. how to control interruptions due to process time length (due to e.g., network latency), machine cacellation signal, maybe power off no respond from machine
  4. how to control intruption control in the state design pattern such as my app in "despensing" waiting for succ/fail signal from the machine side, the machine sends cancellation/err signal (again this behavior can happen anytime)
  5. give time frame for processing operation so that to ensure states can work smoothly and seamlessly
  6. or any suggestion to imporve such process handling in terms of design

I hope that my concern and problem is clear

Aucun commentaire:

Enregistrer un commentaire