+ public static Variable getPythonContextVariable(PythonContext context) {\r
+ NodeManager<PythonNode> nodeManager = new PythonNodeManager(context);\r
+ PythonNode root;\r
+ try {\r
+ root = nodeManager.getNode("/");\r
+ } catch (NodeManagerException e) {\r
+ // Should not happen\r
+ throw new RuntimeException("Getting root Python node failed");\r
+ }\r
+ \r
+ final NodeSupport<PythonNode> support = new NodeSupport<PythonNode>(nodeManager, 0, TimeUnit.NANOSECONDS);\r
+ \r
+ context.addListener(new Listener() {\r
+ @Override\r
+ public void updated(String variableName) {\r
+ try {\r
+ PythonNode root = nodeManager.getNode("/");\r
+ if (variableName != null) {\r
+ PythonNode node = nodeManager.getNode(variableName);\r
+ if (node != null) support.valueCache.removeListening(node);\r
+ support.structureCache.removeListening(root);\r
+ }\r
+ else {\r
+ List<PythonNode> props = nodeManager.getProperties(root);\r
+ for (PythonNode p : props)\r
+ support.valueCache.removeListening(p);\r
+ support.structureCache.removeListening(root);\r
+ }\r
+ \r
+ support.valueCache.clearExpired();\r
+ support.structureCache.clearExpired();\r
+ } catch (NodeManagerException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public void closed() {\r
+ }\r
+ });\r
+ \r
+ return new StandardGraphChildVariable(null, new VariableNode<PythonNode>(support, root), null);\r
+ }\r
+ \r