datacontext

package
v0.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const CONTEXT_TYPE = "attributes" + OCM_CONTEXT_SUFFIX

CONTEXT_TYPE is the global type for an attribute context.

View Source
const MULTI_REF = false
View Source
const OCM_CONTEXT_SUFFIX = ".context" + common.OCM_TYPE_GROUP_SUFFIX

Variables

View Source
var DefaultAttributeScheme = NewDefaultAttributeScheme()

DefaultContext is the default context initialized by init functions.

View Source
var Realm = ocmlog.DefineSubRealm("context lifecycle", "context")

Functions

func AssureUpdater

func AssureUpdater(attrs AttributesContext, u Updater)

AssureUpdater is used to assure the existence of an updater in a root context if a config context is down the context hierarchy. This method SHOULD only be called by a config context.

func Debug

func Debug(c Context, msg string, keypairs ...interface{})

func FinalizedContext

func FinalizedContext[W Context, C InternalContext, P finalizableContextWrapper[C, W]](c C) P

FinalizedContext wraps a context implementation C into a separate wrapper object of type *W and returns this wrapper. It should have the type

struct {
   C
}

The wrapper is created and a runtime finalizer is defined for this object, which calls the Finalize Method on the context implementation.

func GetContextRefCount

func GetContextRefCount(ctx Context) int

func InternalContextRef

func InternalContextRef[C Context](ctx C) C

func IsPersistentContextRef

func IsPersistentContextRef(ctx Context) bool

func PersistentContextRef

func PersistentContextRef[C Context](ctx C) C

PersistentContextRef ensures a persistent context ref to the given context to avoid an automatic cleanup of the context, which is executed if all persistent refs are gone. If you want to keep context related objects longer than your used context reference, you should keep a persistent ref. This could be the one provided by context creation, or by retrieving an explicit one using this function.

func RegisterAttributeType

func RegisterAttributeType(name string, typ AttributeType, short ...string) error

func RegisterSetupHandler

func RegisterSetupHandler(h SetupHandler)

func SetupContext

func SetupContext[C Context](mode BuilderMode, ctx C) C

func SetupElement

func SetupElement[T ElementCopyable[T]](mode BuilderMode, target *T, create ElementCreator[T], def T) error

Types

type AttributeFactory

type AttributeFactory func(Context) interface{}

AttributeFactory is used to atomicly create a new attribute for a context.

type AttributeScheme

type AttributeScheme interface {
	Register(name string, typ AttributeType, short ...string) error

	Decode(attr string, data []byte, unmarshaler runtime.Unmarshaler) (interface{}, error)
	Encode(attr string, v interface{}, marshaller runtime.Marshaler) ([]byte, error)
	Convert(attr string, v interface{}) (interface{}, error)
	GetType(attr string) (AttributeType, error)

	AddKnownTypes(scheme AttributeScheme)
	Shortcuts() common.Properties
	KnownTypes() KnownTypes
	KnownTypeNames() []string
}

func NewDefaultAttributeScheme

func NewDefaultAttributeScheme() AttributeScheme

type AttributeType

type AttributeType interface {
	Name() string
	Decode(data []byte, unmarshaler runtime.Unmarshaler) (interface{}, error)
	Encode(v interface{}, marshaller runtime.Marshaler) ([]byte, error)
	Description() string
}

type Attributes

type Attributes interface {
	finalizer.Finalizable

	GetAttribute(name string, def ...interface{}) interface{}
	SetAttribute(name string, value interface{}) error
	SetEncodedAttribute(name string, data []byte, unmarshaller runtime.Unmarshaler) error
	GetOrCreateAttribute(name string, creator AttributeFactory) interface{}
}

func NewAttributes

func NewAttributes(ctx Context, parent Attributes, updater *Updater) Attributes

type AttributesContext

type AttributesContext interface {
	Context

	IsAttributesContext() bool
	AttributesContext() AttributesContext

	BindTo(ctx context.Context) context.Context
}

func ForContext

func ForContext(ctx context.Context) AttributesContext

ForContext returns the Context to use for context.Context. This is either an explicit context or the default context.

func New

func New(parentAttrs ...Attributes) AttributesContext

New provides a root attribute context.

func NewWithActions

func NewWithActions(parentAttrs Attributes, actions handlers.Registry) AttributesContext

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func (Builder) Bound

func (b Builder) Bound() (Context, context.Context)

func (Builder) New

func (b Builder) New(m ...BuilderMode) Context

func (Builder) WithActionHandlers

func (b Builder) WithActionHandlers(hdlrs handlers.Registry) Builder

func (Builder) WithAttributes

func (b Builder) WithAttributes(parentAttr Attributes) Builder

func (Builder) WithContext

func (b Builder) WithContext(ctx context.Context) Builder

type BuilderMode

type BuilderMode int

BuilderMode controls the handling of unset information in the builder configuration when calling the New method.

const (
	// MODE_SHARED uses the default contexts for unset nested context types.
	MODE_SHARED BuilderMode = iota
	// MODE_DEFAULTED uses dedicated context instances configured with the
	// context type specific default registrations.
	MODE_DEFAULTED
	// MODE_EXTENDED uses dedicated context instances configured with
	// context type registrations extending the default registrations.
	MODE_EXTENDED
	// MODE_CONFIGURED uses dedicated context instances configured with the
	// context type registrations configured with the actual state of the
	// default registrations.
	MODE_CONFIGURED
	// MODE_INITIAL uses completely new contexts for unset nested context types
	// and initial registrations.
	MODE_INITIAL
)

func Mode

func Mode(m ...BuilderMode) BuilderMode

func (BuilderMode) String

func (m BuilderMode) String() string

type Context

type Context interface {
	ContextBinder
	ContextProvider
	Delegates

	IsIdenticalTo(Context) bool

	// GetType returns the context type
	GetType() string
	GetId() ContextIdentity

	GetAttributes() Attributes

	Finalize() error
	Finalizer() *finalizer.Finalizer
}

Context describes a common interface for a data context used for a dedicated purpose. Such has a type and always specific attribute store. Every Context can be bound to a context.Context.

func ForContextByKey

func ForContextByKey(ctx context.Context, key interface{}, def Context) (Context, bool)

ForContextByKey retrieves the context for a given key to be used for a context.Context. If not defined, it returns the given default context and false.

func WithContext

func WithContext(ctx context.Context, parentAttrs Attributes) (Context, context.Context)

WithContext create a new Context bound to a context.Context.

type ContextBinder

type ContextBinder interface {
	// BindTo binds the context to a context.Context and makes it
	// retrievable by a ForContext method
	BindTo(ctx context.Context) context.Context
}

type ContextIdentity

type ContextIdentity = runtimefinalizer.ObjectIdentity

type ContextProvider

type ContextProvider interface {
	// AttributesContext returns the shared attributes
	AttributesContext() AttributesContext
}

type Converter

type Converter interface {
	Convert(interface{}) (interface{}, error)
}

Converter is an optional interface an AttributeType can implement to normalize an attribute value. It is called by the Attributes.SetAttribute method.

type DefaultAttributeType

type DefaultAttributeType struct{}

func (DefaultAttributeType) Encode

func (_ DefaultAttributeType) Encode(v interface{}, marshaller runtime.Marshaler) ([]byte, error)

type Delegates

type Delegates interface {
	ocmlog.LogProvider
	handlers.ActionsProvider
}

Delegates is the interface for common Context features, which might be delegated to aggregated contexts.

func ComposeDelegates

func ComposeDelegates(l logging.Context, a handlers.Registry) Delegates

type ElementCopyable

type ElementCopyable[T any] interface {
	comparable
	Copy() T
}

type ElementCreator

type ElementCreator[T any] func(base ...T) T

type GCWrapper

type GCWrapper struct {
	// contains filtered or unexported fields
}

GCWrapper is the embeddable base type for a context wrapper handling garbage collection. It also handles the BindTo interface for a context.

func (GCWrapper) BindTo

func (b GCWrapper) BindTo(ctx context.Context) context.Context

BindTo makes the Context reachable via the resulting context.Context. Go requires not to use a pointer receiver, here ??????

func (*GCWrapper) GetInternalContext

func (w *GCWrapper) GetInternalContext() Context

func (*GCWrapper) IsPersistent

func (w *GCWrapper) IsPersistent() bool

type InternalContext

type InternalContext interface {
	Context
	runtimefinalizer.RecorderProvider
	GetKey() interface{}
	GetAllocatable() refmgmt.Allocatable
}

func NewContextBase

func NewContextBase(eff Context, typ string, key interface{}, parentAttrs Attributes, delegates Delegates) InternalContext

NewContextBase creates a context base implementation supporting context attributes and the binding to a context.Context.

type KnownTypes

type KnownTypes map[string]AttributeType

KnownTypes is a set of known type names mapped to appropriate object decoders.

func (KnownTypes) Copy

func (t KnownTypes) Copy() KnownTypes

Copy provides a copy of the actually known types.

func (KnownTypes) TypeNames

func (t KnownTypes) TypeNames() []string

TypeNames return a sorted list of known type names.

type ObjectKey

type ObjectKey struct {
	Object interface{}
	Name   string
}

type Session

type Session interface {
	// Closer adds a closer returned by a function call providing a closer and an error
	// to the session if not error is returned. The results of the call are forwarded to
	// the own result. Unfortunately, Go does not support type parameters for methods,
	// therefore only an io.Closer can be returned a function result.
	Closer(closer io.Closer, extra ...interface{}) (io.Closer, error)
	GetOrCreate(key interface{}, creator func(SessionBase) Session) Session
	AddCloser(closer io.Closer, callbacks ...accessio.CloserCallback) io.Closer
	Close() error
	IsClosed() bool
}

Session is a context keeping track of objects requiring a close after final use. When closing a session all subsequent objects will be closed in the opposite order they are added. Added closers may be closed prio to the session without causing errors.

func GetOrCreateSubSession

func GetOrCreateSubSession(s Session, key interface{}, creator func(SessionBase) Session) Session

func NewSession

func NewSession() Session

type SessionBase

type SessionBase interface {
	Lock()
	Unlock()
	RLock()
	RUnlock()

	Session() Session
	IsClosed() bool
	AddCloser(closer io.Closer, callbacks ...accessio.CloserCallback) io.Closer
}

type SetupHandler

type SetupHandler interface {
	Setup(mode BuilderMode, ctx Context)
}

SetupHandler is a handler, which can be registered by an arbitrary context part used to setup this parts for a new context. For example, a typical use case is setup a default value for a context attribute. The handler may consider the context creation mode to determine the initial content or structure of the context part.

type SetupHandlerFunction

type SetupHandlerFunction func(mode BuilderMode, ctx Context)

SetupHandlerFunction is a function usable as SetupHandler.

func (SetupHandlerFunction) Setup

func (f SetupHandlerFunction) Setup(mode BuilderMode, ctx Context)

type SetupHandlerRegistry

type SetupHandlerRegistry interface {
	Register(h SetupHandler)
	Setup(mode BuilderMode, ctx Context)
}

SetupHandlerRegistry is used to register and execute SetupHandler for a freshly created context.

type UpdateFunc

type UpdateFunc func() error

func (UpdateFunc) Update

func (u UpdateFunc) Update() error

type Updater

type Updater interface {
	Update() error
}

type ViewCreator

type ViewCreator[C Context] interface {
	CreateView() C
}

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL