Documentation
¶
Index ¶
- Constants
- Variables
- func ChildGo(ctx *Context, thread Thread, child Thread, first_action string)
- func GQLHandler(ctx *Context, server *GQLThread) func(http.ResponseWriter, *http.Request)
- func GQLInterfaceLockable() *graphql.Interface
- func GQLInterfaceNode() *graphql.Interface
- func GQLInterfaceThread() *graphql.Interface
- func GQLListLockable() *graphql.List
- func GQLListThread() *graphql.List
- func GQLLockableDependencies(p graphql.ResolveParams) (interface{}, error)
- func GQLLockableName(p graphql.ResolveParams) (interface{}, error)
- func GQLLockableOwner(p graphql.ResolveParams) (interface{}, error)
- func GQLLockableRequirements(p graphql.ResolveParams) (interface{}, error)
- func GQLMutationSendUpdate() *graphql.Field
- func GQLNodeID(p graphql.ResolveParams) (interface{}, error)
- func GQLQuerySelf() *graphql.Field
- func GQLSignalDirection(p graphql.ResolveParams) (interface{}, error)
- func GQLSignalFn(p graphql.ResolveParams, ...) (interface{}, error)
- func GQLSignalSource(p graphql.ResolveParams) (interface{}, error)
- func GQLSignalString(p graphql.ResolveParams) (interface{}, error)
- func GQLSignalType(p graphql.ResolveParams) (interface{}, error)
- func GQLSubscribeFn(p graphql.ResolveParams, send_nil bool, ...) (interface{}, error)
- func GQLSubscribeSelf(p graphql.ResolveParams) (interface{}, error)
- func GQLSubscribeSignal(p graphql.ResolveParams) (interface{}, error)
- func GQLSubscriptionSelf() *graphql.Field
- func GQLSubscriptionUpdate() *graphql.Field
- func GQLThreadChildren(p graphql.ResolveParams) (interface{}, error)
- func GQLThreadListen(p graphql.ResolveParams) (interface{}, error)
- func GQLThreadParent(p graphql.ResolveParams) (interface{}, error)
- func GQLTypeGQLThread() *graphql.Object
- func GQLTypeGraphNode() *graphql.Object
- func GQLTypeSignal() *graphql.Object
- func GQLTypeSignalInput() *graphql.InputObject
- func GQLTypeSimpleLockable() *graphql.Object
- func GQLTypeSimpleThread() *graphql.Object
- func GQLWSDo(ctx *Context, p graphql.Params) chan *graphql.Result
- func GQLWSHandler(ctx *Context, server *GQLThread) func(http.ResponseWriter, *http.Request)
- func GraphiQLHandler() func(http.ResponseWriter, *http.Request)
- func LinkLockables(ctx *Context, lockable Lockable, requirements []Lockable, nodes NodeMap) error
- func LinkThreads(ctx *Context, thread Thread, child Thread, info ThreadInfo, nodes NodeMap) error
- func LockLockables(ctx *Context, to_lock []Lockable, new_owner Lockable, nodes NodeMap) error
- func RestoreSimpleLockable(ctx *Context, lockable Lockable, j SimpleLockableJSON, nodes NodeMap) error
- func RestoreSimpleThread(ctx *Context, thread Thread, j SimpleThreadJSON, nodes NodeMap) error
- func ThreadAbort(ctx *Context, thread Thread, signal GraphSignal) (string, error)
- func ThreadCancel(ctx *Context, thread Thread, signal GraphSignal) (string, error)
- func ThreadLoop(ctx *Context, thread Thread, first_action string) error
- func UnlinkLockables(ctx *Context, lockable Lockable, requirement Lockable) error
- func UnlinkThreads(ctx *Context, thread Thread, child Thread) error
- func UnlockLockables(ctx *Context, to_unlock []Lockable, old_owner Lockable, nodes NodeMap) error
- func UpdateChannel(node Node, buffer int, id NodeID) chan GraphSignal
- func UpdateMoreStates(ctx *Context, nodes []Node, locked_nodes NodeMap, nodes_fn NodesFn) error
- func UpdateStates(ctx *Context, nodes []Node, nodes_fn NodesFn) error
- func UseMoreStates(ctx *Context, new_nodes []Node, nodes NodeMap, nodes_fn NodesFn) error
- func UseStates(ctx *Context, init_nodes []Node, nodes_fn NodesFn) error
- func WriteNodes(ctx *Context, nodes NodeMap) error
- type BaseSignal
- func AbortSignal(source Node) BaseSignal
- func CancelSignal(source Node) BaseSignal
- func NewBaseSignal(source Node, _type string, direction SignalDirection) BaseSignal
- func NewDirectSignal(source Node, _type string) BaseSignal
- func NewDownSignal(source Node, _type string) BaseSignal
- func NewSignal(source Node, _type string) BaseSignal
- type ConsoleLogger
- func (logger *ConsoleLogger) Logf(component string, format string, items ...interface{})
- func (logger *ConsoleLogger) Logj(component string, s interface{}, format string, items ...interface{})
- func (logger *ConsoleLogger) Logm(component string, fields map[string]interface{}, format string, ...)
- func (logger *ConsoleLogger) SetComponents(components []string) error
- type Context
- type DBHeader
- type GQLContext
- type GQLThread
- type GQLThreadInfo
- type GQLThreadJSON
- type GQLWSMsg
- type GQLWSPayload
- type GraphNode
- func (node *GraphNode) ID() NodeID
- func (node *GraphNode) RegisterChannel(id NodeID, listener chan GraphSignal)
- func (node *GraphNode) Serialize() ([]byte, error)
- func (node *GraphNode) Signal(ctx *Context, signal GraphSignal, nodes NodeMap) error
- func (node *GraphNode) Type() NodeType
- func (node *GraphNode) UnregisterChannel(id NodeID)
- type GraphSignal
- type Lockable
- type Logger
- type Node
- func LoadGQLThread(ctx *Context, id NodeID, data []byte, nodes NodeMap) (Node, error)
- func LoadGraphNode(ctx *Context, id NodeID, data []byte, nodes NodeMap) (Node, error)
- func LoadNode(ctx *Context, id NodeID) (Node, error)
- func LoadNodeRecurse(ctx *Context, id NodeID, nodes NodeMap) (Node, error)
- func LoadSimpleLockable(ctx *Context, id NodeID, data []byte, nodes NodeMap) (Node, error)
- func LoadSimpleThread(ctx *Context, id NodeID, data []byte, nodes NodeMap) (Node, error)
- func NodeList[K Node](list []K) []Node
- type NodeDef
- type NodeID
- type NodeLoadFunc
- type NodeMap
- type NodeType
- type NodesFn
- type ObjTypeMap
- type SignalDirection
- type SimpleLockable
- func (lockable *SimpleLockable) AddDependency(dependency Lockable)
- func (lockable *SimpleLockable) AddRequirement(requirement Lockable)
- func (lockable *SimpleLockable) AllowedToTakeLock(l Lockable, new_owner Lockable) bool
- func (lockable *SimpleLockable) CanLock(new_owner Lockable) error
- func (lockable *SimpleLockable) CanUnlock(new_owner Lockable) error
- func (lockable *SimpleLockable) Dependencies() []Lockable
- func (lockable *SimpleLockable) Name() string
- func (lockable *SimpleLockable) Owner() Lockable
- func (lockable *SimpleLockable) RecordLock(l Lockable, last_owner Lockable)
- func (lockable *SimpleLockable) RecordUnlock(l Lockable) Lockable
- func (lockable *SimpleLockable) RemoveDependency(dependency Lockable)
- func (lockable *SimpleLockable) RemoveRequirement(requirement Lockable)
- func (lockable *SimpleLockable) Requirements() []Lockable
- func (lockable *SimpleLockable) Serialize() ([]byte, error)
- func (lockable *SimpleLockable) SetOwner(owner Lockable)
- func (lockable *SimpleLockable) Signal(ctx *Context, signal GraphSignal, nodes NodeMap) error
- func (state *SimpleLockable) Type() NodeType
- type SimpleLockableJSON
- type SimpleThread
- func (thread *SimpleThread) Action(action string) (ThreadAction, bool)
- func (thread *SimpleThread) AddChild(child Thread, info ThreadInfo) error
- func (thread *SimpleThread) Child(id NodeID) Thread
- func (thread *SimpleThread) ChildInfo(child NodeID) ThreadInfo
- func (thread *SimpleThread) ChildWaits() *sync.WaitGroup
- func (thread *SimpleThread) Children() []Thread
- func (thread *SimpleThread) ClearTimeout()
- func (thread *SimpleThread) DeserializeInfo(ctx *Context, data []byte) (ThreadInfo, error)
- func (thread *SimpleThread) Handler(signal_type string) (ThreadHandler, bool)
- func (thread *SimpleThread) Parent() Thread
- func (thread *SimpleThread) RemoveChild(child Thread)
- func (thread *SimpleThread) Serialize() ([]byte, error)
- func (thread *SimpleThread) SetActive(active bool) error
- func (thread *SimpleThread) SetParent(parent Thread)
- func (thread *SimpleThread) SetState(new_state string) error
- func (thread *SimpleThread) SetTimeout(timeout time.Time, action string)
- func (thread *SimpleThread) Signal(ctx *Context, signal GraphSignal, nodes NodeMap) error
- func (thread *SimpleThread) SignalChannel() <-chan GraphSignal
- func (thread *SimpleThread) State() string
- func (thread *SimpleThread) Timeout() <-chan time.Time
- func (thread *SimpleThread) TimeoutAction() string
- func (thread *SimpleThread) Type() NodeType
- type SimpleThreadJSON
- type Thread
- type ThreadAbortedError
- type ThreadAction
- type ThreadActions
- type ThreadHandler
- type ThreadHandlers
- type ThreadInfo
Constants ¶
const NODE_DB_HEADER_LEN = 12
Total length of the node database header, has magic to verify and type_hash to map to load function
const NODE_DB_MAGIC = 0x2491df14
Magic first four bytes of serialized DB content, stored big endian
const THREAD_SIGNAL_BUFFER_SIZE = 128
Variables ¶
var BaseThreadActions = ThreadActions{ "wait": ThreadWait, "start": ThreadDefaultStart, "restore": ThreadDefaultRestore, }
var BaseThreadHandlers = ThreadHandlers{ "abort": ThreadAbort, "cancel": ThreadCancel, }
var ThreadDefaultRestore = func(ctx *Context, thread Thread) (string, error) { ctx.Log.Logf("thread", "THREAD_DEFAULT_RESTORE: %s", thread.ID()) return "wait", nil }
var ThreadDefaultStart = func(ctx *Context, thread Thread) (string, error) { ctx.Log.Logf("thread", "THREAD_DEFAULT_START: %s", thread.ID()) err := ThreadStart(ctx, thread) if err != nil { return "", err } return "wait", nil }
var ThreadStart = func(ctx *Context, thread Thread) error { err := UpdateStates(ctx, []Node{thread}, func(nodes NodeMap) error { owner_id := NodeID("") if thread.Owner() != nil { owner_id = thread.Owner().ID() } if owner_id != thread.ID() { err := LockLockables(ctx, []Lockable{thread}, thread, nodes) if err != nil { return err } } return thread.SetState("started") }) if err != nil { return err } return nil }
var ThreadWait = func(ctx *Context, thread Thread) (string, error) { ctx.Log.Logf("thread", "THREAD_WAIT: %s TIMEOUT: %+v", thread.ID(), thread.Timeout()) for { select { case signal := <-thread.SignalChannel(): if signal.Source() == thread.ID() { ctx.Log.Logf("thread", "THREAD_SIGNAL_INTERNAL") } else { ctx.Log.Logf("thread", "THREAD_SIGNAL: %s %+v", thread.ID(), signal) } signal_fn, exists := thread.Handler(signal.Type()) if exists == true { ctx.Log.Logf("thread", "THREAD_HANDLER: %s - %s", thread.ID(), signal.Type()) return signal_fn(ctx, thread, signal) } else { ctx.Log.Logf("thread", "THREAD_NOHANDLER: %s - %s", thread.ID(), signal.Type()) } case <-thread.Timeout(): timeout_action := "" err := UpdateStates(ctx, []Node{thread}, func(nodes NodeMap) error { timeout_action = thread.TimeoutAction() thread.ClearTimeout() return nil }) if err != nil { ctx.Log.Logf("thread", "THREAD_TIMEOUT_ERR: %s - %e", thread.ID(), err) } ctx.Log.Logf("thread", "THREAD_TIMEOUT %s - NEXT_STATE: %s", thread.ID(), timeout_action) return timeout_action, nil } } }
Functions ¶
func GQLHandler ¶
func GQLInterfaceLockable ¶
func GQLInterfaceNode ¶
func GQLInterfaceThread ¶
func GQLListLockable ¶
func GQLListThread ¶
func GQLLockableDependencies ¶
func GQLLockableDependencies(p graphql.ResolveParams) (interface{}, error)
func GQLLockableName ¶
func GQLLockableName(p graphql.ResolveParams) (interface{}, error)
func GQLLockableOwner ¶
func GQLLockableOwner(p graphql.ResolveParams) (interface{}, error)
func GQLLockableRequirements ¶
func GQLLockableRequirements(p graphql.ResolveParams) (interface{}, error)
func GQLMutationSendUpdate ¶
func GQLNodeID ¶
func GQLNodeID(p graphql.ResolveParams) (interface{}, error)
func GQLQuerySelf ¶
func GQLSignalDirection ¶
func GQLSignalDirection(p graphql.ResolveParams) (interface{}, error)
func GQLSignalFn ¶
func GQLSignalFn(p graphql.ResolveParams, fn func(GraphSignal, graphql.ResolveParams) (interface{}, error)) (interface{}, error)
func GQLSignalSource ¶
func GQLSignalSource(p graphql.ResolveParams) (interface{}, error)
func GQLSignalString ¶
func GQLSignalString(p graphql.ResolveParams) (interface{}, error)
func GQLSignalType ¶
func GQLSignalType(p graphql.ResolveParams) (interface{}, error)
func GQLSubscribeFn ¶
func GQLSubscribeFn(p graphql.ResolveParams, send_nil bool, fn func(*Context, *GQLThread, GraphSignal, graphql.ResolveParams) (interface{}, error)) (interface{}, error)
func GQLSubscribeSelf ¶
func GQLSubscribeSelf(p graphql.ResolveParams) (interface{}, error)
func GQLSubscribeSignal ¶
func GQLSubscribeSignal(p graphql.ResolveParams) (interface{}, error)
func GQLSubscriptionSelf ¶
func GQLSubscriptionUpdate ¶
func GQLThreadChildren ¶
func GQLThreadChildren(p graphql.ResolveParams) (interface{}, error)
func GQLThreadListen ¶
func GQLThreadListen(p graphql.ResolveParams) (interface{}, error)
func GQLThreadParent ¶
func GQLThreadParent(p graphql.ResolveParams) (interface{}, error)
func GQLTypeGQLThread ¶
func GQLTypeGraphNode ¶
func GQLTypeSignal ¶
func GQLTypeSignalInput ¶
func GQLTypeSignalInput() *graphql.InputObject
func GQLTypeSimpleLockable ¶
func GQLTypeSimpleThread ¶
func GQLWSHandler ¶
func GraphiQLHandler ¶
func GraphiQLHandler() func(http.ResponseWriter, *http.Request)
func LinkLockables ¶
Link requirements as requirements to lockable Requires lockable and requirements to be locked for write, nodes passed because requirement check recursively locks
func LinkThreads ¶
Requires thread and childs thread to be locked for write
func LockLockables ¶
Lock nodes in the to_lock slice with new_owner, does not modify any states if returning an error Requires that all the nodes in to_lock and new_owner are locked for write
func RestoreSimpleLockable ¶
func RestoreSimpleLockable(ctx *Context, lockable Lockable, j SimpleLockableJSON, nodes NodeMap) error
Helper function to load links when loading a struct that embeds SimpleLockable
func RestoreSimpleThread ¶
func RestoreSimpleThread(ctx *Context, thread Thread, j SimpleThreadJSON, nodes NodeMap) error
func ThreadAbort ¶
func ThreadAbort(ctx *Context, thread Thread, signal GraphSignal) (string, error)
Default thread abort is to return a ThreadAbortedError
func ThreadCancel ¶
func ThreadCancel(ctx *Context, thread Thread, signal GraphSignal) (string, error)
Default thread cancel is to finish the thread
func ThreadLoop ¶
Main Loop for Threads
func UnlinkLockables ¶
Removes requirement as a requirement from lockable Requires lockable and requirement be locked for write
func UnlinkThreads ¶
Requires thread and childs thread to be locked for write
func UnlockLockables ¶
Unlock nodes in the to_unlock slice with old_owner, does not modify any states if returning an error Requires that all the nodes in to_unlock and old_owner are locked for write
func UpdateChannel ¶
func UpdateChannel(node Node, buffer int, id NodeID) chan GraphSignal
Create a new channel with a buffer the size of buffer, and register it to node with the id
func UpdateMoreStates ¶
Add nodes to an existing write context and call nodes_fn with nodes locked for read
func UpdateStates ¶
Initiate a write context for nodes and call nodes_fn with nodes locked for read
func UseMoreStates ¶
Add nodes to an existing read context and call nodes_fn with new_nodes locked for read
func UseStates ¶
Initiate a read context for nodes and call nodes_fn with init_nodes locked for read
func WriteNodes ¶
Write multiple nodes to the database in a single transaction
Types ¶
type BaseSignal ¶
type BaseSignal struct {
FDirection SignalDirection `json:"direction"`
FSource NodeID `json:"source"`
FType string `json:"type"`
}
BaseSignal is the most basic type of signal, it has no additional data
func AbortSignal ¶
func AbortSignal(source Node) BaseSignal
func CancelSignal ¶
func CancelSignal(source Node) BaseSignal
func NewBaseSignal ¶
func NewBaseSignal(source Node, _type string, direction SignalDirection) BaseSignal
func NewDirectSignal ¶
func NewDirectSignal(source Node, _type string) BaseSignal
func NewDownSignal ¶
func NewDownSignal(source Node, _type string) BaseSignal
func NewSignal ¶
func NewSignal(source Node, _type string) BaseSignal
func (BaseSignal) Direction ¶
func (signal BaseSignal) Direction() SignalDirection
func (BaseSignal) Source ¶
func (signal BaseSignal) Source() NodeID
func (BaseSignal) String ¶
func (state BaseSignal) String() string
func (BaseSignal) Type ¶
func (signal BaseSignal) Type() string
type ConsoleLogger ¶
type ConsoleLogger struct {
// contains filtered or unexported fields
}
A ConsoleLogger logs to stdout
func NewConsoleLogger ¶
func NewConsoleLogger(components []string) *ConsoleLogger
func (*ConsoleLogger) Logf ¶
func (logger *ConsoleLogger) Logf(component string, format string, items ...interface{})
func (*ConsoleLogger) Logj ¶
func (logger *ConsoleLogger) Logj(component string, s interface{}, format string, items ...interface{})
func (*ConsoleLogger) Logm ¶
func (logger *ConsoleLogger) Logm(component string, fields map[string]interface{}, format string, items ...interface{})
func (*ConsoleLogger) SetComponents ¶
func (logger *ConsoleLogger) SetComponents(components []string) error
type Context ¶
type Context struct {
// DB is the database connection used to load and write nodes
DB *badger.DB
// Log is an interface used to record events happening
Log Logger
// A mapping between type hashes and their corresponding node definitions
Types map[uint64]NodeDef
// GQL substructure
GQL GQLContext
}
A Context is all the data needed to run a graphvent
func NewContext ¶
Create a new Context with all the library content added
func (*Context) AddGQLType ¶
Add a non-node type to the gql context
func (*Context) RebuildSchema ¶
Recreate the GQL schema after making changes
func (*Context) RegisterNodeType ¶
Add a node to a context, returns an error if the def is invalid or already exists in the context
type DBHeader ¶
A DBHeader is parsed from the first NODE_DB_HEADER_LEN bytes of a serialized DB node
func NewDBHeader ¶
type GQLContext ¶
type GQLContext struct {
// Generated GQL schema
Schema graphql.Schema
// Interface types to compare against
NodeType reflect.Type
LockableType reflect.Type
ThreadType reflect.Type
// List of GQL types
TypeList []graphql.Type
// Interface type maps to map go types of specific interfaces to gql types
ValidNodes ObjTypeMap
ValidLockables ObjTypeMap
ValidThreads ObjTypeMap
Query *graphql.Object
Mutation *graphql.Object
Subscription *graphql.Object
}
GQL Specific Context information
type GQLThread ¶
type GQLThread struct {
SimpleThread
Listen string
// contains filtered or unexported fields
}
func NewGQLThread ¶
func (*GQLThread) DeserializeInfo ¶
func (thread *GQLThread) DeserializeInfo(ctx *Context, data []byte) (ThreadInfo, error)
type GQLThreadInfo ¶
type GQLThreadInfo struct {
Start bool `json:"start"`
StartAction string `json:"start_action"`
RestoreAction string `json:"restore_action"`
}
func NewGQLThreadInfo ¶
func NewGQLThreadInfo(start bool, start_action string, restore_action string) GQLThreadInfo
type GQLThreadJSON ¶
type GQLThreadJSON struct {
SimpleThreadJSON
Listen string `json:"listen"`
}
func NewGQLThreadJSON ¶
func NewGQLThreadJSON(thread *GQLThread) GQLThreadJSON
type GQLWSMsg ¶
type GQLWSMsg struct {
ID string `json:"id,omitempty"`
Type string `json:"type"`
Payload GQLWSPayload `json:"payload,omitempty"`
}
type GQLWSPayload ¶
type GraphNode ¶
A GraphNode is an implementation of a Node that can be embedded into more complex structures
func NewGraphNode ¶
func (*GraphNode) RegisterChannel ¶
func (node *GraphNode) RegisterChannel(id NodeID, listener chan GraphSignal)
func (*GraphNode) Signal ¶
func (node *GraphNode) Signal(ctx *Context, signal GraphSignal, nodes NodeMap) error
Propagate the signal to registered listeners, if a listener isn't ready to receive the update send it a notification that it was closed and then close it
func (*GraphNode) UnregisterChannel ¶
type GraphSignal ¶
type GraphSignal interface {
// How to propogate the signal
Direction() SignalDirection
Source() NodeID
Type() string
String() string
}
GraphSignals are passed around the event tree/resource DAG and cast by Type()
type Lockable ¶
type Lockable interface {
// All Lockables are nodes
Node
//// State Modification Function
// Record that lockable was returned to it's owner and is no longer held by this Node
// Returns the previous owner of the lockable
RecordUnlock(lockable Lockable) Lockable
// Record that lockable was locked by this node, and that it should be returned to last_owner
RecordLock(lockable Lockable, last_owner Lockable)
// Link a requirement to this Node
AddRequirement(requirement Lockable)
// Remove a requirement linked to this Node
RemoveRequirement(requirement Lockable)
// Link a dependency to this Node
AddDependency(dependency Lockable)
// Remove a dependency linked to this Node
RemoveDependency(dependency Lockable)
//
SetOwner(new_owner Lockable)
//// State Reading Functions
Name() string
// Called when new_owner wants to take lockable's lock but it's owned by this node
// A true return value means that the lock can be passed
AllowedToTakeLock(new_owner Lockable, lockable Lockable) bool
// Get all the linked requirements to this node
Requirements() []Lockable
// Get all the linked dependencies to this node
Dependencies() []Lockable
// Get the node's Owner
Owner() Lockable
// Called during the lock process after locking the state and before updating the Node's state
// a non-nil return value will abort the lock attempt
CanLock(new_owner Lockable) error
// Called during the unlock process after locking the state and before updating the Node's state
// a non-nil return value will abort the unlock attempt
CanUnlock(old_owner Lockable) error
}
A Lockable represents a Node that can be locked and hold other Nodes locks
type Logger ¶
type Logger interface {
SetComponents(components []string) error
// Log a formatted string
Logf(component string, format string, items ...interface{})
// Log a map of attributes and a format string
Logm(component string, fields map[string]interface{}, format string, items ...interface{})
// Log a structure to a file by marshalling and unmarshalling the json
Logj(component string, s interface{}, format string, items ...interface{})
}
A Logger is passed around to record events happening to components enabled by SetComponents
type Node ¶
type Node interface {
sync.Locker
RLock()
RUnlock()
// Serialize the Node for the database
Serialize() ([]byte, error)
ID() NodeID
Type() NodeType
// Send a GraphSignal to the node, requires that the node is locked for read so that it can propagate
Signal(ctx *Context, signal GraphSignal, nodes NodeMap) error
// Register a channel to receive updates sent to the node
RegisterChannel(id NodeID, listener chan GraphSignal)
// Unregister a channel from receiving updates sent to the node
UnregisterChannel(id NodeID)
}
A Node represents data that can be read by multiple goroutines and written to by one, with a unique ID attached, and a method to process updates(including propagating them to connected nodes) RegisterChannel and UnregisterChannel are used to connect arbitrary listeners to the node
func LoadGQLThread ¶
func LoadGraphNode ¶
func LoadNodeRecurse ¶
Recursively load a node from the database. It's expected that node_type.Load adds the newly loaded node to nodes before calling LoadNodeRecurse again.
func LoadSimpleLockable ¶
Load function for SimpleLockable
func LoadSimpleThread ¶
type NodeDef ¶
type NodeDef struct {
Load NodeLoadFunc
Type NodeType
GQLType *graphql.Object
Reflect reflect.Type
}
A NodeDef is a description of a node that can be added to a Context
func NewNodeDef ¶
func NewNodeDef(example Node, load_func NodeLoadFunc, gql_type *graphql.Object) NodeDef
Create a new Node def, extracting the Type and Reflect from example
type NodeID ¶
type NodeID string
IDs are how nodes are uniquely identified, and can be serialized for the database
type NodeLoadFunc ¶
NodeLoadFunc is the footprint of the function used to create a new node in memory from persisted bytes
type NodeType ¶
type NodeType string
Types are how nodes are associated with structs at runtime(and from the DB)
type SimpleLockable ¶
type SimpleLockable struct {
GraphNode
// contains filtered or unexported fields
}
SimpleLockable is a simple Lockable implementation that can be embedded into more complex structures
func NewSimpleLockable ¶
func NewSimpleLockable(id NodeID, name string) SimpleLockable
func (*SimpleLockable) AddDependency ¶
func (lockable *SimpleLockable) AddDependency(dependency Lockable)
func (*SimpleLockable) AddRequirement ¶
func (lockable *SimpleLockable) AddRequirement(requirement Lockable)
func (*SimpleLockable) AllowedToTakeLock ¶
func (lockable *SimpleLockable) AllowedToTakeLock(l Lockable, new_owner Lockable) bool
Nothing can take a lock from a simple lockable
func (*SimpleLockable) CanLock ¶
func (lockable *SimpleLockable) CanLock(new_owner Lockable) error
func (*SimpleLockable) CanUnlock ¶
func (lockable *SimpleLockable) CanUnlock(new_owner Lockable) error
func (*SimpleLockable) Dependencies ¶
func (lockable *SimpleLockable) Dependencies() []Lockable
func (*SimpleLockable) Name ¶
func (lockable *SimpleLockable) Name() string
func (*SimpleLockable) Owner ¶
func (lockable *SimpleLockable) Owner() Lockable
func (*SimpleLockable) RecordLock ¶
func (lockable *SimpleLockable) RecordLock(l Lockable, last_owner Lockable)
func (*SimpleLockable) RecordUnlock ¶
func (lockable *SimpleLockable) RecordUnlock(l Lockable) Lockable
func (*SimpleLockable) RemoveDependency ¶
func (lockable *SimpleLockable) RemoveDependency(dependency Lockable)
func (*SimpleLockable) RemoveRequirement ¶
func (lockable *SimpleLockable) RemoveRequirement(requirement Lockable)
func (*SimpleLockable) Requirements ¶
func (lockable *SimpleLockable) Requirements() []Lockable
func (*SimpleLockable) Serialize ¶
func (lockable *SimpleLockable) Serialize() ([]byte, error)
func (*SimpleLockable) SetOwner ¶
func (lockable *SimpleLockable) SetOwner(owner Lockable)
func (*SimpleLockable) Signal ¶
func (lockable *SimpleLockable) Signal(ctx *Context, signal GraphSignal, nodes NodeMap) error
Lockable.Signal sends the update to the owner, requirements, and dependencies before updating listeners
func (*SimpleLockable) Type ¶
func (state *SimpleLockable) Type() NodeType
type SimpleLockableJSON ¶
type SimpleLockableJSON struct {
Name string `json:"name"`
Owner *NodeID `json:"owner"`
Dependencies []NodeID `json:"dependencies"`
Requirements []NodeID `json:"requirements"`
LocksHeld map[NodeID]*NodeID `json:"locks_held"`
}
func NewSimpleLockableJSON ¶
func NewSimpleLockableJSON(lockable *SimpleLockable) SimpleLockableJSON
type SimpleThread ¶
type SimpleThread struct {
SimpleLockable
InfoType reflect.Type
// contains filtered or unexported fields
}
func NewSimpleThread ¶
func NewSimpleThread(id NodeID, name string, state_name string, info_type reflect.Type, actions ThreadActions, handlers ThreadHandlers) SimpleThread
func (*SimpleThread) Action ¶
func (thread *SimpleThread) Action(action string) (ThreadAction, bool)
func (*SimpleThread) AddChild ¶
func (thread *SimpleThread) AddChild(child Thread, info ThreadInfo) error
func (*SimpleThread) Child ¶
func (thread *SimpleThread) Child(id NodeID) Thread
func (*SimpleThread) ChildInfo ¶
func (thread *SimpleThread) ChildInfo(child NodeID) ThreadInfo
func (*SimpleThread) ChildWaits ¶
func (thread *SimpleThread) ChildWaits() *sync.WaitGroup
func (*SimpleThread) Children ¶
func (thread *SimpleThread) Children() []Thread
func (*SimpleThread) ClearTimeout ¶
func (thread *SimpleThread) ClearTimeout()
func (*SimpleThread) DeserializeInfo ¶
func (thread *SimpleThread) DeserializeInfo(ctx *Context, data []byte) (ThreadInfo, error)
SimpleThread as no associated info with children
func (*SimpleThread) Handler ¶
func (thread *SimpleThread) Handler(signal_type string) (ThreadHandler, bool)
func (*SimpleThread) Parent ¶
func (thread *SimpleThread) Parent() Thread
func (*SimpleThread) RemoveChild ¶
func (thread *SimpleThread) RemoveChild(child Thread)
func (*SimpleThread) Serialize ¶
func (thread *SimpleThread) Serialize() ([]byte, error)
func (*SimpleThread) SetActive ¶
func (thread *SimpleThread) SetActive(active bool) error
func (*SimpleThread) SetParent ¶
func (thread *SimpleThread) SetParent(parent Thread)
func (*SimpleThread) SetState ¶
func (thread *SimpleThread) SetState(new_state string) error
func (*SimpleThread) SetTimeout ¶
func (thread *SimpleThread) SetTimeout(timeout time.Time, action string)
func (*SimpleThread) Signal ¶
func (thread *SimpleThread) Signal(ctx *Context, signal GraphSignal, nodes NodeMap) error
SimpleThread.Signal updates the parent and children, and sends the signal to an internal channel
func (*SimpleThread) SignalChannel ¶
func (thread *SimpleThread) SignalChannel() <-chan GraphSignal
func (*SimpleThread) State ¶
func (thread *SimpleThread) State() string
func (*SimpleThread) Timeout ¶
func (thread *SimpleThread) Timeout() <-chan time.Time
func (*SimpleThread) TimeoutAction ¶
func (thread *SimpleThread) TimeoutAction() string
func (*SimpleThread) Type ¶
func (thread *SimpleThread) Type() NodeType
type SimpleThreadJSON ¶
type SimpleThreadJSON struct {
Parent *NodeID `json:"parent"`
Children map[NodeID]interface{} `json:"children"`
Timeout time.Time `json:"timeout"`
TimeoutAction string `json:"timeout_action"`
StateName string `json:"state_name"`
SimpleLockableJSON
}
func NewSimpleThreadJSON ¶
func NewSimpleThreadJSON(thread *SimpleThread) SimpleThreadJSON
type Thread ¶
type Thread interface {
// All Threads are Lockables
Lockable
/// State Modification Functions
SetParent(parent Thread)
AddChild(child Thread, info ThreadInfo) error
RemoveChild(child Thread)
SetState(new_thread string) error
SetTimeout(end_time time.Time, action string)
/// State Reading Functions
Parent() Thread
Children() []Thread
Child(id NodeID) Thread
ChildInfo(child NodeID) ThreadInfo
State() string
TimeoutAction() string
/// Functions that dont read/write thread
// Deserialize the attribute map from json.Unmarshal
DeserializeInfo(ctx *Context, data []byte) (ThreadInfo, error)
SetActive(active bool) error
Action(action string) (ThreadAction, bool)
Handler(signal_type string) (ThreadHandler, bool)
// Internal timeout channel for thread
Timeout() <-chan time.Time
// Internal signal channel for thread
SignalChannel() <-chan GraphSignal
ClearTimeout()
ChildWaits() *sync.WaitGroup
}
type ThreadAbortedError ¶
type ThreadAbortedError NodeID
func NewThreadAbortedError ¶
func NewThreadAbortedError(aborter NodeID) ThreadAbortedError
func (ThreadAbortedError) Error ¶
func (e ThreadAbortedError) Error() string
func (ThreadAbortedError) Is ¶
func (e ThreadAbortedError) Is(target error) bool
type ThreadActions ¶
type ThreadActions map[string]ThreadAction
func NewThreadActions ¶
func NewThreadActions() ThreadActions
type ThreadHandler ¶
type ThreadHandler func(*Context, Thread, GraphSignal) (string, error)
type ThreadHandlers ¶
type ThreadHandlers map[string]ThreadHandler
func NewThreadHandlers ¶
func NewThreadHandlers() ThreadHandlers
type ThreadInfo ¶
type ThreadInfo interface {
}
Interface to represent any type of thread information