12.2 Publishing a Graph
Publishing a Single Graph Snapshot
publish()
methods in PgxGraph can be used to publish the current selected snapshot of the graph.
Note:
Callingpublish()
without arguments publishes the snapshot with its persistent properties but does not publish transient properties.
publish()
method will fail with an exception.
Note:
Graphs published with snapshots and single published snapshots share the same namespace. For example, see Example 4-1 to publish a graph using publish()
method.
If you want to publish specific transient properties, you must list them within the publish()
call.
opg4j> var prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1")
opg4j> prop.fill(0)
opg4j> var cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost")
opg4j> cost.fill(0d)
opg4j> graph.publish(List.of(prop1), List.of(cost))
VertexProperty<Integer, Integer> prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1");
prop.fill(0);
EdgeProperty<Double> cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost");
cost.fill(0d);
List<VertexProperty<Integer, Integer> vertexProps = Arrays.asList(prop);
List<EdgeProperty<Double>> edgeProps = Arrays.asList(cost);
graph.publish(vertexProps, edgeProps);
prop = graph.create_vertex_property("integer", "prop1")
prop.fill(0)
cost = graph.create_edge_property("double", "cost")
cost.fill(0d)
vertex_props = [prop]
edge_props = [cost]
graph.publish(vertex_props, edge_props)
Publishing a Graph with Snapshots
If you want to make all snapshots of the graph visible to other sessions, use the publishWithSnapshots()
methods instead. When a graph is published with snapshots, the GraphMetaData
information of each snapshot is also made available to the other sessions, with the exception of the graph configuration, which is null
.
With publishing, all persistent properties of all snapshots are also published and made visible to the other sessions, while transient properties are session-private and thus should be published explicitly. Once published, all properties become read-only. Hence, transient properties are not published when calling publishWithSnapshots()
without arguments.
publishWithSnapshots()
method will move the graph name from the session-private namespace to the public namespace (see Namespaces and Sharing for more information about namespaces). If a graph with the same name has been already published, the publishWithSnapshots()
method will fail with an exception.
If you want to publish specific transient properties, you should list them within the publishWithSnapshots()
call, as in the following example.
opg4j> var prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1")
opg4j> prop.fill(0)
opg4j> var cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost")
opg4j> cost.fill(0d)
opg4j> graph.publishWithSnapshots(List.of(prop1), List.of(cost))
VertexProperty<Integer, Integer> prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1");
prop.fill(0);
EdgeProperty<Double> cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost");
cost.fill(0d);
List<VertexProperty<Integer, Integer> vertexProps = Arrays.asList(prop);
List<EdgeProperty<Double>> edgeProps = Arrays.asList(cost);
graph.publishWithSnapshots(vertexProps,edgeProps);
VertexProperty<Integer, Integer> prop1 = graph.createVertexProperty(PropertyType.INTEGER, "prop1")
prop.fill(0)
EdgeProperty<Double> cost = graph.createEdgeProperty(PropertyType.DOUBLE, "cost")
cost.fill(0d)
List<VertexProperty<Integer, Integer> vertexProps = Arrays.asList(prop)
List<EdgeProperty<Double>> edgeProps = Arrays.asList(cost)
graph.publishWithSnapshots(vertexProps,edgeProps)
Note:
The published properties, like the original transient properties, are associated to the specific snapshot they had been created on, so they are not visible on other snapshots.Referencing a Published Graph from Another Session
Other sessions can reference a published graph by its name via the getGraph()
method of the session object.
The following example references a published graph of session1
, myGraph
, in session2
.
opg4j> var session2 = instance.createSession("session2")
opg4j> var graph2 = session2.getGraph(Namespace.PUBLIC, "myGraph")
PgxSession session2 = instance.createSession("session2");
PgxGraph graph2 = session2.getGraph(Namespace.PUBLIC, "myGraph");
session2 = pypgx.get_session("session2");
PgxGraph graph2 = session2.get_graph("myGraph")
session2
can see only the published snapshot. If the graph has been published without snapshots, calls to the getAvailableSnapshots()
method of session2
return an empty queue.
getGraph()
returns the most recent snapshot available. session2
can see all the available snapshots via getAvailableSnapshots()
and set a specific one via the setSnapshot()
method of PgxSession
.
Note:
You must remember to release every graph you reference, when you do not need it anymore. See Deleting a Graph for more information.Publishing a Property
After publishing (a single snapshot or all of them), you can still publish transient properties individually:
opg4j> graph.getVertexProperty("prop1").publish()
opg4j> graph.getEdgeProperty("cost").publish()
graph.getVertexProperty("prop1").publish();
graph.getEdgeProperty("cost").publish();
graph.get_vertex_property("prop1").publish()
graph.get_edge_property("cost").publish()
Note:
Published properties are associated to the specific snapshot they have been created on and thus visible only on that snapshot.Getting a Published Property in Another Session
Sessions referencing a published graph (with or without snapshots) can reference a published property via the usual getVertexProperty
and getEdgeProperty
calls of PgxGraph
.
opg4j> var session2 = instance.createSession("session2")
opg4j> var graph2 = session2.getGraph(Namespace.PUBLIC, "myGraph")
opg4j> var vertexProperty = graph2.getVertexProperty("prop1")
opg4j> var edgeProperty = graph2.getEdgeProperty("cost")
PgxSession session2 = instance.createSession("session2");
PgxGraph graph2 = session2.getGraph(Namespace.PUBLIC, "myGraph");
VertexProperty<Integer, Integer> vertexProperty = graph2.getVertexProperty("prop1");
EdgeProperty<Double> edgeProperty = graph2.getEdgeProperty("cost");
session2 = pypgx.get_session(session_name ="session2")
graph2 = session2.get_graph("myGraph")
vertex_property = graph2.get_vertex_property("prop1")
edge_property = graph2.get_edge_property("cost")
session2
now has a reference to the published graph of session1
called myGraph
and can reference its published properties via myGraph
itself.
Parent topic: Graphs Management