datacontext

package
v2.0.0-...-98cc131 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

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 OCM_CONTEXT_SUFFIX = ".context" + common.OCM_TYPE_GROUP_SUFFIX

Variables

View Source
var DefaultAttributeScheme = NewDefaulAttritutetScheme()

DefaultContext is the default context initialized by init functions.

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 RegisterAttributeType

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

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)
	GetType(attr string) (AttributeType, error)

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

func NewDefaulAttritutetScheme

func NewDefaulAttritutetScheme() 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 {
	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

	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(paranetAttr 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 {
	ContextProvider
	Delegates

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

	// BindTo binds the context to a context.Context and makes it
	// retrievable by a ForContext method
	BindTo(ctx context.Context) context.Context
	GetAttributes() Attributes
}

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 ContextIdentity

type ContextIdentity = finalizer.ObjectIdentity

type ContextProvider

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

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 InternalContext

type InternalContext interface {
	Context
	finalizer.RecorderProvider
}

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(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 UpdateFunc

type UpdateFunc func() error

func (UpdateFunc) Update

func (u UpdateFunc) Update() error

type Updater

type Updater interface {
	Update() error
}

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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