Documentation ¶
Overview ¶
Package objectstore implements support for tracking a mapping of object references to and from their instance ID. It tracks objects by proxy of their memory address (i.e: pointer value), in order to avoid the pitfalls of go's standard object equality mechanism (which is also reflect.Value's equality mechanism) causing distinct instances appearing to be equal (including when used as keys to a map).
Index ¶
- type ObjectStore
- func (o *ObjectStore) GetObject(instanceID string) (value reflect.Value, found bool)
- func (o *ObjectStore) GetObjectAs(instanceID string, typ reflect.Type) (value reflect.Value, found bool)
- func (o *ObjectStore) InstanceID(value reflect.Value) (instanceID string, found bool)
- func (o *ObjectStore) Interfaces(instanceID string) []api.FQN
- func (o *ObjectStore) Register(value reflect.Value, objectRef api.ObjectRef) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ObjectStore ¶
type ObjectStore struct {
// contains filtered or unexported fields
}
ObjectStore tracks object instances for which an identifier has been associated. Object to instanceID association is tracked using the object memory address (aka pointer value) in order to not have issues with go's standard object equality rules (we need distinct - but possibly equal) object instances to be considered as separate entities for our purposes.
func (*ObjectStore) GetObject ¶
func (o *ObjectStore) GetObject(instanceID string) (value reflect.Value, found bool)
GetObject attempts to retrieve the object value associated with the given instanceID. Returns the existing value and a boolean informing whether a value was associated with this instanceID or not.
The GetObject method is safe to call with an instanceID that was never registered with the ObjectStore.
func (*ObjectStore) GetObjectAs ¶ added in v1.53.0
func (o *ObjectStore) GetObjectAs(instanceID string, typ reflect.Type) (value reflect.Value, found bool)
GetObjectAs attempts to retrieve the object value associated with the given instanceID, compatible with the given type. Returns the existing value and a boolean informing whether a value was associated with this instanceID and compatible with this type or not.
The GetObjectAs method is safe to call with an instanceID that was never registered with the ObjectStore.
func (*ObjectStore) InstanceID ¶
func (o *ObjectStore) InstanceID(value reflect.Value) (instanceID string, found bool)
InstanceID attempts to determine the instanceID associated with the provided value, if any. Returns the existing instanceID and a boolean informing whether an instanceID was already found or not.
The InstanceID method is safe to call with values that are not track-able in an ObjectStore (i.e: non-pointer values, primitive values, etc...).
func (*ObjectStore) Interfaces ¶ added in v1.53.0
func (o *ObjectStore) Interfaces(instanceID string) []api.FQN
Interfaces returns the set of interfaces associated with the provided instanceID.
It returns a nil slice in case the instancceID is invalid, or if it does not have any associated interfaces.
func (*ObjectStore) Register ¶
Register associates the provided value with the given instanceID. It also registers any anonymously embedded value (transitively) against the same instanceID, so that methods promoted from those resolve the correct instanceID, too.
Returns an error if the provided value is not a pointer value; if the value or any of it's (transitively) anonymous embeds have already been registered against a different instanceID; of if the provided instanceID was already associated to a different value.
The call is idempotent: calling Register again with the same value and instanceID does not result in an error.