go.temporal.io/server/chasm/parent_pointer.go
102 LOC · 25 covered · 77 uncovered · 14 ranges · 556 concepts · 7 introducers · 259 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
package chasm
import (
"fmt"
"reflect"
"go.temporal.io/api/serviceerror"
"go.temporal.io/server/common/softassert"
)
const (
parentPtrInternalFieldName = "Internal"
)
// ParentPtr is a in-memory pointer to the parent component of a CHASM component.
//
// CHASM map is not a component, so if a component is inside a map, its ParentPtr
// will point to the nearest ancestor component that is not a map.
//
// ParentPtr is only initialized and available for use **after** the transition that
// creates the component using ParentPtr is completed.
type ParentPtr[T any] struct {
// Exporting this field as this generic struct needs to be created via reflection,
// and reflection can't set private fields.
Internal parentPtrInternal
}
type parentPtrInternal struct {
// Storing currentNode instead of parent component Node here so that
// we can differentiate between root node and non-initialized ParentPtr.
currentNode *Node
}
// Get returns the parent component, deserializing it if necessary.
// Panics rather than returning an error, as errors are supposed to be handled by the framework as opposed to the
// application.
vT, ok := p.TryGet(chasmContext)
if !ok {
// nolint:forbidigo // Panic is intended here for framework error handling.
parent_pointer.go ×1
panic(serviceerror.NewInternal("expect parent component value but got nil"))
}
}
// TryGet returns the parent component and a boolean indicating if the value was found,
// deserializing if necessary.
// Panics rather than returning an error, as errors are supposed to be handled by the framework as opposed to the
// application.
var nilT T
if p.Internal.currentNode == nil {
return nilT, false
}
if parent == nil {
}
if parent == nil {
encodedPath, _ := p.Internal.currentNode.getEncodedPath()
// nolint:forbidigo // Panic is intended here for framework error handling.
panic(softassert.UnexpectedInternalErr(
p.Internal.currentNode.logger,
"unable to find parent component for CHASM component inside a map",
fmt.Errorf("child node name: %s", encodedPath),
))
}
}
// nolint:forbidigo // Panic is intended here for framework error handling.
panic(softassert.UnexpectedInternalErr(
parent.logger,
"unexpected CHASM node that has a child component",
fmt.Errorf("node %s, node metadata: %s",
parent.nodeName,
parent.serializedNode.GetMetadata().String(),
),
))
}
// nolint:forbidigo // Panic is intended here for framework error handling.
panic(err)
}
return nilT, false
}
if !isT {
// nolint:forbidigo // Panic is intended here for framework error handling.
panic(serviceerror.NewInternalf("parent component value doesn't implement %s", reflect.TypeFor[T]().Name()))
}
}