{
  "entity_types": [
    {
      "name": "Process",
      "scoped_containers": [
        {
          "name": "FD_FREE",
          "kind": "simple",
          "entity_type": "FileDescriptor"
        },
        {
          "name": "FD_OPEN",
          "kind": "simple",
          "entity_type": "FileDescriptor"
        },
        {
          "name": "INBOX",
          "kind": "simple",
          "entity_type": "Message"
        },
        {
          "name": "OUTBOX",
          "kind": "simple",
          "entity_type": "Message"
        },
        {
          "name": "PROCESSED",
          "kind": "simple",
          "entity_type": "Message"
        }
      ]
    },
    {
      "name": "FileDescriptor"
    },
    {
      "name": "Message"
    },
    {
      "name": "Signal"
    }
  ],
  "containers": [
    {
      "name": "READY_QUEUE",
      "kind": "simple",
      "entity_type": "Process"
    },
    {
      "name": "CPU0",
      "kind": "slot",
      "entity_type": "Process"
    },
    {
      "name": "BLOCKED",
      "kind": "simple",
      "entity_type": "Process"
    },
    {
      "name": "SEND_MSG_REQUEST",
      "kind": "simple",
      "entity_type": "Signal"
    },
    {
      "name": "SEND_FD_REQUEST",
      "kind": "simple",
      "entity_type": "Signal"
    },
    {
      "name": "DUP_SEND_REQUEST",
      "kind": "simple",
      "entity_type": "Signal"
    },
    {
      "name": "SIGNAL_DONE",
      "kind": "simple",
      "entity_type": "Signal"
    }
  ],
  "moves": [
    {
      "name": "schedule",
      "from": [
        "READY_QUEUE"
      ],
      "to": [
        "CPU0"
      ],
      "entity_type": "Process"
    },
    {
      "name": "preempt",
      "from": [
        "CPU0"
      ],
      "to": [
        "READY_QUEUE"
      ],
      "entity_type": "Process"
    },
    {
      "name": "block_process",
      "from": [
        "CPU0"
      ],
      "to": [
        "BLOCKED"
      ],
      "entity_type": "Process"
    },
    {
      "name": "unblock",
      "from": [
        "BLOCKED"
      ],
      "to": [
        "READY_QUEUE"
      ],
      "entity_type": "Process"
    },
    {
      "name": "open_fd",
      "scoped_from": [
        "FD_FREE"
      ],
      "scoped_to": [
        "FD_OPEN"
      ],
      "entity_type": "FileDescriptor"
    },
    {
      "name": "close_fd",
      "scoped_from": [
        "FD_OPEN"
      ],
      "scoped_to": [
        "FD_FREE"
      ],
      "entity_type": "FileDescriptor"
    },
    {
      "name": "process_msg",
      "scoped_from": [
        "INBOX"
      ],
      "scoped_to": [
        "PROCESSED"
      ],
      "entity_type": "Message"
    },
    {
      "name": "consume_signal",
      "from": [
        "SEND_MSG_REQUEST",
        "SEND_FD_REQUEST",
        "DUP_SEND_REQUEST"
      ],
      "to": [
        "SIGNAL_DONE"
      ],
      "entity_type": "Signal"
    }
  ],
  "channels": [
    {
      "name": "pipe_AB",
      "from": "proc_A",
      "to": "proc_B",
      "entity_type": "Message"
    },
    {
      "name": "fd_pipe_AB",
      "from": "proc_A",
      "to": "proc_B",
      "entity_type": "FileDescriptor"
    }
  ],
  "max_nesting_depth": 3,
  "tensions": [
    {
      "name": "schedule_ready",
      "priority": 10,
      "match": [
        {
          "bind": "proc",
          "in": "READY_QUEUE",
          "select": "max_by",
          "key": "priority"
        },
        {
          "bind": "cpu",
          "empty_in": [
            "CPU0"
          ],
          "select": "first"
        }
      ],
      "emit": [
        {
          "move": "schedule",
          "entity": "proc",
          "to": "cpu"
        }
      ]
    },
    {
      "name": "send_message",
      "priority": 15,
      "match": [
        {
          "bind": "sig",
          "in": "SEND_MSG_REQUEST",
          "select": "first"
        },
        {
          "bind": "proc",
          "in": "CPU0",
          "select": "first"
        },
        {
          "bind": "msg",
          "in": {
            "scope": "proc",
            "container": "OUTBOX"
          },
          "select": "first"
        }
      ],
      "emit": [
        {
          "send": "pipe_AB",
          "entity": "msg"
        },
        {
          "move": "consume_signal",
          "entity": "sig",
          "to": "SIGNAL_DONE"
        }
      ]
    },
    {
      "name": "receive_message",
      "priority": 12,
      "match": [
        {
          "bind": "proc_b",
          "in": "CPU0",
          "select": "first",
          "where": {
            "op": "==",
            "left": {
              "prop": "name",
              "of": "proc_b"
            },
            "right": "B"
          }
        },
        {
          "bind": "msg",
          "in": {
            "channel": "pipe_AB"
          },
          "select": "first"
        }
      ],
      "emit": [
        {
          "receive": "pipe_AB",
          "entity": "msg",
          "to": {
            "scope": "proc_b",
            "container": "INBOX"
          }
        }
      ]
    },
    {
      "name": "react_to_message",
      "priority": 8,
      "match": [
        {
          "bind": "proc_b",
          "in": "CPU0",
          "select": "first",
          "where": {
            "op": "==",
            "left": {
              "prop": "name",
              "of": "proc_b"
            },
            "right": "B"
          }
        },
        {
          "bind": "msg",
          "in": {
            "scope": "proc_b",
            "container": "INBOX"
          },
          "select": "first"
        }
      ],
      "emit": [
        {
          "set": "proc_b",
          "property": "messages_received",
          "value": {
            "op": "+",
            "left": {
              "prop": "messages_received",
              "of": "proc_b"
            },
            "right": 1
          }
        },
        {
          "move": "process_msg",
          "entity": "msg",
          "to": {
            "scope": "proc_b",
            "container": "PROCESSED"
          }
        }
      ]
    },
    {
      "name": "send_fd",
      "priority": 15,
      "match": [
        {
          "bind": "sig",
          "in": "SEND_FD_REQUEST",
          "select": "first"
        },
        {
          "bind": "proc",
          "in": "CPU0",
          "select": "first"
        },
        {
          "bind": "fd",
          "in": {
            "scope": "proc",
            "container": "FD_OPEN"
          },
          "select": "first"
        }
      ],
      "emit": [
        {
          "send": "fd_pipe_AB",
          "entity": "fd"
        },
        {
          "move": "consume_signal",
          "entity": "sig",
          "to": "SIGNAL_DONE"
        }
      ]
    },
    {
      "name": "receive_fd",
      "priority": 12,
      "match": [
        {
          "bind": "proc_b",
          "in": "CPU0",
          "select": "first",
          "where": {
            "op": "==",
            "left": {
              "prop": "name",
              "of": "proc_b"
            },
            "right": "B"
          }
        },
        {
          "bind": "fd",
          "in": {
            "channel": "fd_pipe_AB"
          },
          "select": "first"
        }
      ],
      "emit": [
        {
          "receive": "fd_pipe_AB",
          "entity": "fd",
          "to": {
            "scope": "proc_b",
            "container": "FD_FREE"
          }
        }
      ]
    },
    {
      "name": "dup_and_send_fd",
      "priority": 15,
      "match": [
        {
          "bind": "sig",
          "in": "DUP_SEND_REQUEST",
          "select": "first"
        },
        {
          "bind": "proc",
          "in": "CPU0",
          "select": "first"
        },
        {
          "bind": "fd",
          "in": {
            "scope": "proc",
            "container": "FD_OPEN"
          },
          "select": "first"
        }
      ],
      "emit": [
        {
          "duplicate": "fd",
          "in": {
            "scope": "proc",
            "container": "FD_OPEN"
          }
        },
        {
          "move": "consume_signal",
          "entity": "sig",
          "to": "SIGNAL_DONE"
        }
      ]
    }
  ],
  "entities": [
    {
      "name": "proc_A",
      "type": "Process",
      "in": "READY_QUEUE",
      "properties": {
        "priority": 5,
        "name": "A",
        "messages_received": 0
      }
    },
    {
      "name": "proc_B",
      "type": "Process",
      "in": "READY_QUEUE",
      "properties": {
        "priority": 3,
        "name": "B",
        "messages_received": 0
      }
    },
    {
      "name": "fd0_A",
      "type": "FileDescriptor",
      "in": {
        "scope": "proc_A",
        "container": "FD_FREE"
      }
    },
    {
      "name": "fd1_A",
      "type": "FileDescriptor",
      "in": {
        "scope": "proc_A",
        "container": "FD_FREE"
      }
    },
    {
      "name": "fd2_A",
      "type": "FileDescriptor",
      "in": {
        "scope": "proc_A",
        "container": "FD_FREE"
      }
    },
    {
      "name": "fd0_B",
      "type": "FileDescriptor",
      "in": {
        "scope": "proc_B",
        "container": "FD_FREE"
      }
    },
    {
      "name": "fd1_B",
      "type": "FileDescriptor",
      "in": {
        "scope": "proc_B",
        "container": "FD_FREE"
      }
    },
    {
      "name": "msg1",
      "type": "Message",
      "in": {
        "scope": "proc_A",
        "container": "OUTBOX"
      },
      "properties": {
        "content": "hello from A",
        "seq": 1
      }
    }
  ]
}
