Skip to content

Commit aa16a54

Browse files
committed
docs: further refine and detail model-client v2 docs
1 parent 92a7b75 commit aa16a54

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed
48.9 KB
Loading

docs/global/modules/core/pages/howto/mps-model-server-plugin.adoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44

55
You can run a *light version* of the `model-server` directly in MPS via the dedicated *MPS as Modelix Model Server Plugin*, which is published over at the https://plugins.jetbrains.com/plugin/22834-mps-as-modelix-model-server[JetBrains Marketplace^].
6-
It always supports the latest MPS versions.
76

87
NOTE: More information on the component in general can be found in the xref:core:reference/component-mps-model-server-plugin.adoc[corresponding component reference].
98

docs/global/modules/core/pages/howto/usage-model-client-v2.adoc

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,51 @@ We can consequently assume that its data is always correct and up-to-date.
5555

5656
[source, kotlin]
5757
--
58+
// create a new repository
5859
val myRepoId: RepositoryId = RepositoryId("myRepository")
59-
modelClientV2.initRepository(myRepoId)
60+
client.initRepository(myRepoId)
6061

62+
// obtain the main branch created by default
6163
val myBranchReference: BranchReference = BranchReference(repositoryId = myRepoId, branchName = RepositoryId.DEFAULT_BRANCH)
62-
val replicatedModel: ReplicatedModel = modelClientV2.getReplicatedModel(myBranchReference)
64+
65+
// replicate the branch content
66+
val replicatedModel: ReplicatedModel = client.getReplicatedModel(myBranchReference)
67+
// start the continuous replication
6368
replicatedModel.start()
6469
--
6570

6671
To ensure that read and write are executed correctly, we need to use read and write transactions whenever we interact with the content, e.g. by adding a new child:
6772

6873
[source, kotlin]
6974
--
70-
var rootNode: INode? = null
71-
// we need to start a read transaction to obtain model content
72-
replicatedModel.getBranch().getArea().executeRead {
73-
// initial root node after repository initialization has the id 1
74-
rootNode = replicatedModel.getBranch().getRootNode()
75-
}
75+
// initial root node after repository initialization has the id 1
76+
val rootNode: INode = replicatedModel.getBranch().getRootNode()
7677

77-
// we need to exit the read before we write
78-
replicatedModel.getBranch().getArea().executeWrite {
79-
val newChild: INode? = rootNode?.addNewChild("myRole")
80-
println("Added node $newChild under parent ${newChild?.parent}")
78+
// to create a node we need run a write transaction
79+
replicatedModel.getBranch().runWrite {
80+
val newChild: INode = rootNode.addNewChild("myRole")
81+
println("Added node $newChild under parent ${newChild.parent}")
8182
}
8283

83-
// we need to start a read transaction again to get model content
84-
replicatedModel.getBranch().getArea().executeRead {
85-
println("All nodes in repository: ${(rootNode?.getDescendants(true)?.toMutableList().map { (it as PNodeAdapter).nodeId.toString() })}")
84+
// to get model content we need a read transaction
85+
replicatedModel.getBranch().runRead {
86+
println("All nodes in repository: ${(rootNode.getDescendants(true).toMutableList())}")
8687
}
8788
--
8889

90+
Which will yield the following output:
91+
92+
[source]
93+
--
94+
Added node PNode2100000001 under parent PNode1
95+
All nodes in repository: [PNode1, PNode2100000001]
96+
--
97+
8998
CAUTION: If you try to access a node that does not exist, an exception is thrown.
9099

100+
Browsing to the `model-sever` content explorer over at http://localhost:28101/repos[] and selecting _Explore Latest Version_ for _myRepository_ you should see this:
101+
102+
image::model-client-v2-sample.png[Result in `model-server` of the above code]
103+
104+
91105
For more information how to deal with `INodes` and the `client`, check the https://api.modelix.org/latest/model-api/index.html[model API] and the https://api.modelix.org/latest/model-client/org.modelix.model.client2/-model-client-v2/index.html[ModelClientV2 API] respectively.

docs/global/modules/core/partials/nav-howto.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
* xref:core:howto/usage-model-server.adoc[]
22
* xref:core:howto/metrics.adoc[]
33
* xref:core:howto/usage-model-api-gen-gradle.adoc[]
4+
* xref:core:howto/usage-model-client-v2.adoc[]
45
* xref:core:howto/usage-light-model-client.adoc[]
56
* xref:core:howto/testing-against-model-api.adoc[]
67
* xref:core:howto/modelql.adoc[]

0 commit comments

Comments
 (0)