Home   :   Matrix Language   :   Model Examples   :   Zig Zag

Zig Zag Model




The Zig Zag model is very similar to the Ping Pong model, but is included here to demonstrate the synchronous creation and deletion of an object.




At start up a single Zig object exists which creates a Zag object, establishes a relationship and then sends an event to it.  The Zag object responds by relating to Zig and sending an event back.   


Zig sends another event to Zag which enters its final state (where it will be deleted by Zig), unrelating and sends an event back to Zig to say it can be deleted.  Zig then dissolves its relationship and deletes Zag.



Model Walkthrough




The relationship Zig:Relationship:Zag is conditional since a Zig can exist without a Zag as is the situation on start up.






The Sending state is responsible for creating a Zag object via the CreateActive Process, forming a relationship and sending an event to the newly created object.


Click on the picture below to get a clearer view of the diagram.


Entity:Zig, State:Starting


At this level, object creation and access (read and write to attributes) is considered to happen instantaneously, whereas sending an event takes a finite time.  So, as long as the creation process executes before the event sending process (and the PFD shows it does) it is guaranteed that the object will exist to receive the event.  The actual rules governing synchronisation of attribute access and events are little more subtle than what's describe here but this is a good way of thinking about it for the moment.


It is also worth saying here that Matrix does not allow copies of objects to be made.  When an object attribute is read or updated it is the actual object that is being manipulated, not a copy of an object that has to be written back later.


Entity:Zig, State:Holding


The diagram below shows how Zag is first unrelated and then deleted synchronously.  The Delete action process is shown updating the data store but the Unrelate action process does not because it does affect the object directly (only the relationship).


Entity:Zig, State:Vanish


The STD for Zag shows both synchronous creation and synchronous deletion.  Synchronous deletion works on objects in a dynamic state.  It's literally not possible to synchronously delete an object in a deletion state.




Entity:Zag, State:Holding


Entity:Zag, State:Waiting



Matrix Model


Click on the Code Map diagram below to get a view of the code.




Expected Output


When the Matrix model is executed under the Simulator with all tracing turned off the following display output is produced in the command prompt window:



    Matrix Model Simulator - Learning Edition - Version 1.0.0

    Development on THU-02-JAN-2014 @ 12:26:07

    Copyright (C) 2014, Dark Matter Systems Ltd.  All rights reserved.


    Connection established: MATRIX*CORE - Version 0.5.2



$ | Zig Zag Scenario


$ trace all off

$ trace display on

$ trace events on

$ trace states on


$ initialise all



                    Hold ->


                    <- Hold


                    Wait ->


                    <- Kill




$ host pause

Press any key to continue . . .


$ exit


        Model Simulation Elapsed Time: 00:00:01


    Disconnected from MATRIX*CORE on THU-02-JAN-2014 @ 12:26:08

Copyright 2017 Dark Matter Systems Ltd. All Rights Reserved.