model

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2018 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(identifiers []TupleType, toCheck TupleType) (bool, int)

Contains returns true if an identifier exists in the identifier array

func IdentifiersToString

func IdentifiersToString(identifiers []TupleType) string

IdentifiersToString Take a slice of Identifiers and return a string representation

func RegisterTupleDescriptors

func RegisterTupleDescriptors(jsonRegistry string) (err error)

RegisterTupleDescriptors registers the TupleDescriptors

Types

type ActionFunction

type ActionFunction func(context.Context, RuleSession, string, map[TupleType]Tuple, RuleContext)

ActionFunction is a function pointer for handling action callbacks on the server side i.e part of the server side API

type Condition

type Condition interface {
	GetName() string
	GetEvaluator() ConditionEvaluator
	GetRule() Rule
	GetIdentifiers() []TupleType
	GetContext() RuleContext
	String() string
}

Condition interface to maintain/get various condition properties

type ConditionEvaluator

type ConditionEvaluator func(string, string, map[TupleType]Tuple, RuleContext) bool

ConditionEvaluator is a function pointer for handling condition evaluations on the server side i.e, part of the server side API

type MutableRule

type MutableRule interface {
	Rule
	AddCondition(conditionName string, idrs []string, cFn ConditionEvaluator, ctx RuleContext) (err error)
	SetAction(actionFn ActionFunction)
	SetPriority(priority int)
	SetContext(ctx RuleContext)
}

MutableRule interface has methods to add conditions and actions

type MutableTuple

type MutableTuple interface {
	Tuple
	SetString(ctx context.Context, name string, value string) (err error)
	SetInt(ctx context.Context, name string, value int) (err error)
	SetLong(ctx context.Context, name string, value int64) (err error)
	SetDouble(ctx context.Context, name string, value float64) (err error)
	SetBool(ctx context.Context, name string, value bool) (err error)

	//will try to coerce value to the named property's type
	SetValue(ctx context.Context, name string, value interface{}) (err error)
}

MutableTuple mutable part of the tuple

func NewTuple

func NewTuple(tupleType TupleType, values map[string]interface{}) (mtuple MutableTuple, err error)

func NewTupleKeyWithKeyValues

func NewTupleKeyWithKeyValues(tupleType TupleType, values ...interface{}) (mtuple MutableTuple, err error)

func NewTupleWithKeyValues

func NewTupleWithKeyValues(tupleType TupleType, values ...interface{}) (mtuple MutableTuple, err error)

type RetecontextKeyType

type RetecontextKeyType struct {
}

type Rule

type Rule interface {
	GetName() string
	GetIdentifiers() []TupleType
	GetConditions() []Condition
	GetActionFn() ActionFunction
	String() string
	GetPriority() int
	GetDeps() map[TupleType]map[string]bool
	GetContext() RuleContext
}

Rule ... a Rule interface

type RuleContext

type RuleContext interface{}

RuleContext associated with every rule

type RuleSession

type RuleSession interface {
	GetName() string

	AddRule(rule Rule) (err error)
	DeleteRule(ruleName string)
	GetRules() []Rule

	Assert(ctx context.Context, tuple Tuple) (err error)
	Retract(ctx context.Context, tuple Tuple)

	ScheduleAssert(ctx context.Context, delayInMillis uint64, key interface{}, tuple Tuple)
	CancelScheduledAssert(ctx context.Context, key interface{})

	Unregister()

	//Optional, called before asserting a tuple but after adding all rules
	SetStartupFunction(startupFn StartupRSFunction)

	GetStartupFunction() (startupFn StartupRSFunction)

	//To be called when the rule session is ready to start accepting tuples
	//This will invoke the StartupFunction
	Start(startupCtx map[string]interface{}) (err error)
}

RuleSession to maintain rules and assert tuples against those rules

type StartupRSFunction

type StartupRSFunction func(ctx context.Context, rs RuleSession, sessionCtx map[string]interface{}) (err error)

StartupRSFunction is called once after creation of a RuleSession

type Tuple

type Tuple interface {
	GetTupleType() TupleType
	GetTupleDescriptor() *TupleDescriptor

	GetProperties() []string
	GetString(name string) (val string, err error)
	GetInt(name string) (val int, err error)
	GetLong(name string) (val int64, err error)
	GetDouble(name string) (val float64, err error)
	GetBool(name string) (val bool, err error)
	//GetDateTime(name string) time.Time
	GetKey() TupleKey
}

Tuple is a runtime representation of a data tuple

type TupleDescriptor

type TupleDescriptor struct {
	Name         string                    `json:"name"`
	TTLInSeconds int                       `json:"ttl"`
	Props        []TuplePropertyDescriptor `json:"properties"`
	// contains filtered or unexported fields
}

TupleDescriptor defines the type of the structure, its properties, types

func GetTupleDescriptor

func GetTupleDescriptor(tupleType TupleType) *TupleDescriptor

GetTupleDescriptor gets the TupleDescriptor based on the TupleType

func (*TupleDescriptor) GetKeyProps

func (td *TupleDescriptor) GetKeyProps() []string

GetKeyProps returns all the key properties

func (*TupleDescriptor) GetProperty

func (td *TupleDescriptor) GetProperty(prop string) *TuplePropertyDescriptor

GetProperty fetches the property by name

func (*TupleDescriptor) UnmarshalJSON

func (td *TupleDescriptor) UnmarshalJSON(b []byte) error

type TupleKey

type TupleKey interface {
	String() string
	GetTupleDescriptor() TupleDescriptor
}

TupleKey primary key of a tuple

func NewTupleKey

func NewTupleKey(tupleType TupleType, values map[string]interface{}) (tupleKey TupleKey, err error)

type TuplePropertyDescriptor

type TuplePropertyDescriptor struct {
	Name     string    `json:"name"`
	PropType data.Type `json:"type"`
	KeyIndex int       `json:"pk-index"`
}

TuplePropertyDescriptor defines the actual property, its type, key index

func (TuplePropertyDescriptor) MarshalJSON

func (tpd TuplePropertyDescriptor) MarshalJSON() ([]byte, error)

MarshalJSON allows to hook & customize TupleDescriptor to JSON conversion

type TupleType

type TupleType string

TupleType Each tuple is of a certain type, described by TypeDescriptor

type ValueChangeListener

type ValueChangeListener interface {
	OnValueChange(tuple Tuple, prop string)
}

ValueChangeListener to pickup and process tuple value changes

Jump to

Keyboard shortcuts

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