From 59424cecc1e813cd8df07e34513733ec69dcf54c Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Sat, 11 Nov 2023 14:52:08 -0700 Subject: [PATCH] Added some logging and fixes --- event.go | 6 +++--- gql.go | 2 +- group.go | 2 +- lockable.go | 18 ++++++++++++------ node.go | 12 ++++-------- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/event.go b/event.go index af830e7..40b8203 100644 --- a/event.go +++ b/event.go @@ -105,7 +105,7 @@ func (signal EventControlSignal) Permission() Tree { func (ext *EventExt) UpdateState(node *Node, changes Changes, state string) { if ext.State != state { - changes.Add(EventExtType, "changes") + changes.Add(EventExtType, "state") ext.State = state node.QueueSignal(time.Now(), NewEventStateSignal(node.ID, ext.State, time.Now())) } @@ -113,7 +113,7 @@ func (ext *EventExt) UpdateState(node *Node, changes Changes, state string) { func (ext *EventExt) Process(ctx *Context, node *Node, source NodeID, signal Signal) (Messages, Changes) { var messages Messages = nil - var changes Changes = nil + var changes = Changes{} if signal.Direction() == Up && ext.Parent != node.ID { messages = messages.Add(ctx, ext.Parent, node, nil, signal) @@ -147,7 +147,7 @@ var test_event_commands = map[string]map[string]string{ func (ext *TestEventExt) Process(ctx *Context, node *Node, source NodeID, signal Signal) (Messages, Changes) { var messages Messages = nil - var changes Changes = nil + var changes = Changes{} switch sig := signal.(type) { case *EventControlSignal: diff --git a/gql.go b/gql.go index 09479be..ba6f004 100644 --- a/gql.go +++ b/gql.go @@ -1656,7 +1656,7 @@ func (ext *GQLExt) FreeResponseChannel(req_id uuid.UUID) chan Signal { func (ext *GQLExt) Process(ctx *Context, node *Node, source NodeID, signal Signal) (Messages, Changes) { // Process ReadResultSignalType by forwarding it to the waiting resolver - var changes Changes = nil + var changes = Changes{} switch sig := signal.(type) { case *SuccessSignal: diff --git a/group.go b/group.go index b865e20..ae19368 100644 --- a/group.go +++ b/group.go @@ -225,7 +225,7 @@ func NewGroupExt(sub_groups map[string][]NodeID) *GroupExt { func (ext *GroupExt) Process(ctx *Context, node *Node, source NodeID, signal Signal) (Messages, Changes) { var messages Messages = nil - var changes Changes = nil + var changes = Changes{} switch sig := signal.(type) { case *AddMemberSignal: diff --git a/lockable.go b/lockable.go index 755c0a3..cc62618 100644 --- a/lockable.go +++ b/lockable.go @@ -5,6 +5,12 @@ import ( "time" ) +var AllowAnyLockPolicy = NewAllNodesPolicy(Tree{ + SerializedType(LockSignalType): { + Hash(LockStateBase, "lock"): nil, + }, +}) + type ReqState byte const ( Unlocked = ReqState(0) @@ -69,7 +75,7 @@ func LockLockable(ctx *Context, node *Node) (uuid.UUID, error) { func (ext *LockableExt) HandleErrorSignal(ctx *Context, node *Node, source NodeID, signal *ErrorSignal) (Messages, Changes) { var messages Messages = nil - var changes Changes = nil + var changes = Changes{} info, info_found := node.ProcessResponse(ext.WaitInfos, signal) if info_found { @@ -116,7 +122,7 @@ func (ext *LockableExt) HandleErrorSignal(ctx *Context, node *Node, source NodeI func (ext *LockableExt) HandleLinkSignal(ctx *Context, node *Node, source NodeID, signal *LinkSignal) (Messages, Changes) { var messages Messages = nil - var changes Changes = nil + var changes = Changes{} if ext.State == Unlocked { switch signal.Action { case "add": @@ -151,7 +157,7 @@ func (ext *LockableExt) HandleLinkSignal(ctx *Context, node *Node, source NodeID func (ext *LockableExt) HandleSuccessSignal(ctx *Context, node *Node, source NodeID, signal *SuccessSignal) (Messages, Changes) { var messages Messages = nil - var changes Changes = nil + var changes = Changes{} if source == node.ID { return messages, changes } @@ -235,7 +241,7 @@ func (ext *LockableExt) HandleSuccessSignal(ctx *Context, node *Node, source Nod // Handle a LockSignal and update the extensions owner/requirement states func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID, signal *LockSignal) (Messages, Changes) { var messages Messages = nil - var changes Changes = nil + var changes = Changes{} switch signal.State { case "lock": @@ -311,7 +317,7 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID func (ext *LockableExt) HandleTimeoutSignal(ctx *Context, node *Node, source NodeID, signal *TimeoutSignal) (Messages, Changes) { var messages Messages = nil - var changes Changes = nil + var changes = Changes{} wait_info, found := node.ProcessResponse(ext.WaitInfos, signal) if found == true { @@ -359,7 +365,7 @@ func (ext *LockableExt) HandleTimeoutSignal(ctx *Context, node *Node, source Nod // LockSignal and LinkSignal Direct signals are processed to update the requirement/dependency/lock state func (ext *LockableExt) Process(ctx *Context, node *Node, source NodeID, signal Signal) (Messages, Changes) { var messages Messages = nil - var changes Changes = nil + var changes = Changes{} switch signal.Direction() { case Up: diff --git a/node.go b/node.go index 3a49b1e..8f3f61d 100644 --- a/node.go +++ b/node.go @@ -49,16 +49,13 @@ func RandID() NodeID { type Changes map[ExtType][]string -func (changes *Changes) Add(ext ExtType, fields ...string) { - if *changes == nil { - *changes = Changes{} - } - current, exists := (*changes)[ext] +func (changes Changes) Add(ext ExtType, fields ...string) { + current, exists := changes[ext] if exists == false { current = []string{} } current = append(current, fields...) - (*changes)[ext] = current + changes[ext] = current } // Extensions are data attached to nodes that process signals @@ -550,7 +547,6 @@ func (node *Node) Process(ctx *Context, source NodeID, signal Signal) error { for ext_type, ext := range(node.Extensions) { ctx.Log.Logf("node_process", "PROCESSING_EXTENSION: %s/%s", node.ID, ext_type) ext_messages, ext_changes := ext.Process(ctx, node, source, signal) - ctx.Log.Logf("gql", "%s changes %+v", reflect.TypeOf(ext), ext_changes) if len(ext_messages) != 0 { messages = append(messages, ext_messages...) } @@ -561,7 +557,7 @@ func (node *Node) Process(ctx *Context, source NodeID, signal Signal) error { } } } - ctx.Log.Logf("gql", "changes after process %+v", changes) + ctx.Log.Logf("changes", "Changes for %s after %+v - %+v", node.ID, reflect.TypeOf(signal), changes) if len(messages) != 0 { send_err := ctx.Send(messages)