customer.go
file containing a customer
type. 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 arrivalTime
and serviceTime
for maintaining its internal state.arrival
and service
. For expediency the customer
type is simply aliased, however these could be defined as custom types instead.waitSeconds
is defined as a simple integer to track how long customers wait (not who has to wait).Run
methods 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.Run
method 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.Measure
interface. This means defining a method named MeasureTo
so Dash can tell it where to publish measurements.Publisher
interface. This requires a PublishTo
method.Subscriber
interface through SubscribeTo
. Note that SubscribeTo
receives a ledger.Subscriber
type, which lets us associate a handler with an event type.Run
method. 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.go
as a queue of arrival events to process and an event ledger to publish to.Run
method 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.time
is the amount of simulated time to run for and limits
is the actual run time limits. Use time
to set how much simulated time to run for and limits
to set time limits. For example, setting a time
of 10 hours will run 10 hours of simulated time, but pairing that with limits
of 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.events
field to the JSON.MeasureTo
.waitSeconds
measurement type is simply an int
. If we want more information we can make it a struct or provide a MarshalJSON
method, and Dash will automatically incorporate those details into its output.