|
@@ -6,13 +6,58 @@
|
|
|
<parameter name="mvk"/>
|
|
|
<body>
|
|
|
<![CDATA[
|
|
|
+ self.mvs = ModelverseState("../bootstrap/bootstrap.m.gz")
|
|
|
self.request_queue = [("", "", "load_primitives", [], None)]
|
|
|
+ self.mvs.GC = True
|
|
|
self.mvk = mvk
|
|
|
self.first = True
|
|
|
self.mvs_response = None
|
|
|
+
|
|
|
+ self.mvs_operations = {
|
|
|
+ "CN": self.mvs.create_node,
|
|
|
+ "CE": self.mvs.create_edge,
|
|
|
+ "CNV": self.mvs.create_nodevalue,
|
|
|
+ "CD": self.mvs.create_dict,
|
|
|
+
|
|
|
+ "RV": self.mvs.read_value,
|
|
|
+ "RO": self.mvs.read_outgoing,
|
|
|
+ "RI": self.mvs.read_incoming,
|
|
|
+ "RE": self.mvs.read_edge,
|
|
|
+ "RD": self.mvs.read_dict,
|
|
|
+ "RDN": self.mvs.read_dict_node,
|
|
|
+ "RDNE": self.mvs.read_dict_node_edge,
|
|
|
+ "RDE": self.mvs.read_dict_edge,
|
|
|
+ "RRD": self.mvs.read_reverse_dict,
|
|
|
+ "RR": self.mvs.read_root,
|
|
|
+ "RDK": self.mvs.read_dict_keys,
|
|
|
+
|
|
|
+ "DE": self.mvs.delete_edge,
|
|
|
+ "DN": self.mvs.delete_node,
|
|
|
+ }
|
|
|
+
|
|
|
]]>
|
|
|
</body>
|
|
|
</constructor>
|
|
|
+
|
|
|
+ <method name="execute_modelverse">
|
|
|
+ <parameter name="username"/>
|
|
|
+ <parameter name="operation"/>
|
|
|
+ <parameter name="params"/>
|
|
|
+ <body>
|
|
|
+ <![CDATA[
|
|
|
+ reply = None
|
|
|
+ commands = []
|
|
|
+ while 1:
|
|
|
+ commands = self.mvk.execute_yields(username, operation, params, reply)
|
|
|
+ if commands is None:
|
|
|
+ break
|
|
|
+ reply = [self.mvs_operations[command[0]](*(command[1]))[0] for command in commands]
|
|
|
+ #for c, r in zip(commands, reply):
|
|
|
+ # print("%s --> %s" % (c, r))
|
|
|
+ ]]>
|
|
|
+ </body>
|
|
|
+ </method>
|
|
|
+
|
|
|
<scxml initial="init">
|
|
|
<parallel id="init">
|
|
|
<state id="queue">
|
|
@@ -24,6 +69,7 @@
|
|
|
<parameter name="params"/>
|
|
|
<parameter name="request_id"/>
|
|
|
<script>
|
|
|
+ print 'got execute event'
|
|
|
self.request_queue.append(("/" + returnpath, username, operation, params, request_id))
|
|
|
</script>
|
|
|
</transition>
|
|
@@ -32,6 +78,11 @@
|
|
|
|
|
|
<state id="execute" initial="idle">
|
|
|
<state id="idle">
|
|
|
+ <onentry>
|
|
|
+ <script>
|
|
|
+ print 'in idle'
|
|
|
+ </script>
|
|
|
+ </onentry>
|
|
|
<transition cond="self.request_queue" target="../execution"/>
|
|
|
</state>
|
|
|
|
|
@@ -40,6 +91,7 @@
|
|
|
<script>
|
|
|
try:
|
|
|
_, username, operation, params, _ = self.request_queue[0]
|
|
|
+ print 'executing %s %s' % (operation, params)
|
|
|
self.mvs_commands = self.mvk.execute_yields(username, operation, params, self.mvs_response)
|
|
|
except:
|
|
|
import traceback
|
|
@@ -69,14 +121,17 @@
|
|
|
</script>
|
|
|
</transition>
|
|
|
|
|
|
- <transition cond="len(self.mvs_commands) > 0" target="../waiting_for_response">
|
|
|
+ <transition cond="self.mvs_commands is not None and len(self.mvs_commands) > 0" target="../waiting_for_response">
|
|
|
<raise event="HTTP_input" scope="narrow" target="'parent/to_mvs'">
|
|
|
<parameter expr="'requests=%s' % json.dumps(self.mvs_commands)"/>
|
|
|
<parameter expr="'parent/executor'"/>
|
|
|
</raise>
|
|
|
</transition>
|
|
|
|
|
|
- <transition cond="len(self.mvs_commands) == 0" target=".">
|
|
|
+ <transition cond="self.mvs_commands is not None and len(self.mvs_commands) == 0" target=".">
|
|
|
+ <script>
|
|
|
+ self.mvs_response = []
|
|
|
+ </script>
|
|
|
</transition>
|
|
|
</state>
|
|
|
|
|
@@ -85,10 +140,18 @@
|
|
|
<parameter name="data"/>
|
|
|
<script>
|
|
|
self.mvs_response = [v[0] for v in json.loads(data["data"])]
|
|
|
- if len(self.mvs_response) == 1:
|
|
|
- self.mvs_response = self.mvs_response[0]
|
|
|
</script>
|
|
|
</transition>
|
|
|
+ <onexit>
|
|
|
+ <script>
|
|
|
+ print 'leaving waiting_for_response'
|
|
|
+ </script>
|
|
|
+ </onexit>
|
|
|
+ <onentry>
|
|
|
+ <script>
|
|
|
+ print 'entering waiting_for_response'
|
|
|
+ </script>
|
|
|
+ </onentry>
|
|
|
</state>
|
|
|
</state>
|
|
|
</parallel>
|