customer.gofile containing a
customertype. It has the same fields as the input JSON. The customer type also has access to the event and measure ledgers of the simulation, which it uses to publish and subscribe to events, and to record measurements of wait time. Finally, the customer has pointer fields called
serviceTimefor maintaining its internal state.
service. For expediency the
customertype is simply aliased, however these could be defined as custom types instead.
waitSecondsis defined as a simple integer to track how long customers wait (not who has to wait).
Runmethods at the specified times.
Run. This method takes in the current time, updates the actor's state, and returns the next time to run them along with a boolean indicator of whether not there is anything left for them to do.
Runmethod is shown below. It has three sections. In the first, the customer tests to see if they have entered service. If so, they publish a measurement of their wait time in the queue, and tell Dash that they don't have anything left to do.
Measureinterface. This means defining a method named
MeasureToso Dash can tell it where to publish measurements.
Publisherinterface. This requires a
SubscribeTo. Note that
ledger.Subscribertype, which lets us associate a handler with an event type.
Runmethod. This means that when Dash selects a customer actor to run, it first processes all events published to the event ledger since the last time it ran. Thus our customer's state is kept up to date.
server.goas a queue of arrival events to process and an event ledger to publish to.
Runmethod is simple. If the server has a nonempty queue of customer arrivals to serve, it starts the first one and publishes their service time. The server is then busy until they are done servicing that customer. Otherwise, the server waits for something to do.
timeis the amount of simulated time to run for and
limitsis the actual run time limits. Use
timeto set how much simulated time to run for and
limitsto set time limits. For example, setting a
timeof 10 hours will run 10 hours of simulated time, but pairing that with
limitsof 1 minute will ensure that the simulation stops after 1 real minute of time, regardless of whether those 10 simulated hours have completed. In our model, there is always a server actor lurking about, so we have to tell Dash when to quit.
eventsfield to the JSON.
waitSecondsmeasurement type is simply an
int. If we want more information we can make it a struct or provide a
MarshalJSONmethod, and Dash will automatically incorporate those details into its output.