draft
Writes a Topology in code, the way it reads on a whiteboard: groups nested in groups, lanes where work is charged, and a weight beside each.
draft("pool") {
group("acme", Weight.of(3)) {
lane("interactive", Weight.of(3))
lane("batch", maxConcurrent = 2)
}
group("hobby") { lane("default") }
}A maxConcurrent beside a group, a lane or a group's template is its ceiling, the most leases open beneath it at once (Topology.Node.maxConcurrent); leave it out, or pass null, for none.
The draft is only a way to write the tree down. The value it returns is built through the Topology constructor, so it is checked by the same walk as Topology.from, and a mistake throws TopologyException listing every problem at once, addressed exactly as Topology.from would address it for the same tree. A weight is a Weight, so it is positive before the draft ever sees it.
Use Topology.from instead when the tree comes from an admin's file, where problems should be shown rather than thrown.
Parameters
the name of the group at the top of the tree.
declares the root's children, in order.
Throws
when the tree is invalid: an empty or repeated name, or a group with no children and no template.
when one group calls TopologyDraft.Group.template twice.
Samples
val fairness = draft("pool") {
group("acme", Weight.of(3)) {
lane("interactive", Weight.of(3, 2))
// A ceiling: never more than two batch jobs at once, however idle the pool is.
lane("batch", maxConcurrent = 2)
}
group("tenants") { template() }
}
check(fairness.children.map { it.name } == listOf("acme", "tenants"))
check((fairness.children[0] as Topology.Group).children.map { it.maxConcurrent } == listOf(null, 2L))
// A repeated lane is not built: the whole tree is refused, with every problem in it.
val refused = try {
draft("pool") {
group("acme") {
lane("batch")
lane("batch")
}
}
null
} catch (e: TopologyException) {
e
}
check(refused?.problems?.single()?.kind == TopologyProblem.Kind.DUPLICATE_NAME)