|
|
@ -51,26 +51,28 @@ func NewLockableExt(requirements []NodeID) *LockableExt {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func UnlockLockable(ctx *Context, node *Node) (uuid.UUID, error) {
|
|
|
|
func UnlockLockable(ctx *Context, node *Node) (uuid.UUID, error) {
|
|
|
|
msgs := Messages{}
|
|
|
|
messages := Messages{}
|
|
|
|
signal := NewLockSignal("unlock")
|
|
|
|
signal := NewLockSignal("unlock")
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, signal, node.ID)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, signal, node.ID)
|
|
|
|
return signal.ID(), ctx.Send(msgs)
|
|
|
|
return signal.ID(), ctx.Send(messages)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func LockLockable(ctx *Context, node *Node) (uuid.UUID, error) {
|
|
|
|
func LockLockable(ctx *Context, node *Node) (uuid.UUID, error) {
|
|
|
|
msgs := Messages{}
|
|
|
|
messages := Messages{}
|
|
|
|
signal := NewLockSignal("lock")
|
|
|
|
signal := NewLockSignal("lock")
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, signal, node.ID)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, signal, node.ID)
|
|
|
|
return signal.ID(), ctx.Send(msgs)
|
|
|
|
return signal.ID(), ctx.Send(messages)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (ext *LockableExt) HandleErrorSignal(ctx *Context, node *Node, source NodeID, signal *ErrorSignal) Messages {
|
|
|
|
func (ext *LockableExt) HandleErrorSignal(ctx *Context, node *Node, source NodeID, signal *ErrorSignal) (Messages, Changes) {
|
|
|
|
str := signal.Error
|
|
|
|
str := signal.Error
|
|
|
|
ctx.Log.Logf("lockable", "ERROR_SIGNAL: %s->%s %+v", source, node.ID, str)
|
|
|
|
ctx.Log.Logf("lockable", "ERROR_SIGNAL: %s->%s %+v", source, node.ID, str)
|
|
|
|
|
|
|
|
|
|
|
|
msgs := Messages {}
|
|
|
|
var messages Messages = nil
|
|
|
|
|
|
|
|
var changes Changes = nil
|
|
|
|
switch str {
|
|
|
|
switch str {
|
|
|
|
case "not_unlocked":
|
|
|
|
case "not_unlocked":
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "requirements")
|
|
|
|
if ext.State == Locking {
|
|
|
|
if ext.State == Locking {
|
|
|
|
ext.State = AbortingLock
|
|
|
|
ext.State = AbortingLock
|
|
|
|
req_info := ext.Requirements[source]
|
|
|
|
req_info := ext.Requirements[source]
|
|
|
@ -86,7 +88,7 @@ func (ext *LockableExt) HandleErrorSignal(ctx *Context, node *Node, source NodeI
|
|
|
|
ext.Requirements[id] = req_info
|
|
|
|
ext.Requirements[id] = req_info
|
|
|
|
ctx.Log.Logf("lockable", "SENT_ABORT_UNLOCK: %s to %s", lock_signal.ID(), id)
|
|
|
|
ctx.Log.Logf("lockable", "SENT_ABORT_UNLOCK: %s to %s", lock_signal.ID(), id)
|
|
|
|
|
|
|
|
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, lock_signal, id)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, lock_signal, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -95,17 +97,18 @@ func (ext *LockableExt) HandleErrorSignal(ctx *Context, node *Node, source NodeI
|
|
|
|
case "not_requirement":
|
|
|
|
case "not_requirement":
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return msgs
|
|
|
|
return messages, changes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (ext *LockableExt) HandleLinkSignal(ctx *Context, node *Node, source NodeID, signal *LinkSignal) Messages {
|
|
|
|
func (ext *LockableExt) HandleLinkSignal(ctx *Context, node *Node, source NodeID, signal *LinkSignal) (Messages, Changes) {
|
|
|
|
msgs := Messages {}
|
|
|
|
var messages Messages = nil
|
|
|
|
|
|
|
|
var changes Changes = nil
|
|
|
|
if ext.State == Unlocked {
|
|
|
|
if ext.State == Unlocked {
|
|
|
|
switch signal.Action {
|
|
|
|
switch signal.Action {
|
|
|
|
case "add":
|
|
|
|
case "add":
|
|
|
|
_, exists := ext.Requirements[signal.NodeID]
|
|
|
|
_, exists := ext.Requirements[signal.NodeID]
|
|
|
|
if exists == true {
|
|
|
|
if exists == true {
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "already_requirement"), source)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "already_requirement"), source)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if ext.Requirements == nil {
|
|
|
|
if ext.Requirements == nil {
|
|
|
|
ext.Requirements = map[NodeID]ReqInfo{}
|
|
|
|
ext.Requirements = map[NodeID]ReqInfo{}
|
|
|
@ -114,31 +117,34 @@ func (ext *LockableExt) HandleLinkSignal(ctx *Context, node *Node, source NodeID
|
|
|
|
Unlocked,
|
|
|
|
Unlocked,
|
|
|
|
uuid.UUID{},
|
|
|
|
uuid.UUID{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "req_added"), source)
|
|
|
|
changes = changes.Add(LockableExtType, "requirements")
|
|
|
|
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "remove":
|
|
|
|
case "remove":
|
|
|
|
_, exists := ext.Requirements[signal.NodeID]
|
|
|
|
_, exists := ext.Requirements[signal.NodeID]
|
|
|
|
if exists == false {
|
|
|
|
if exists == false {
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "can't link: not_requirement"), source)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "can't link: not_requirement"), source)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
delete(ext.Requirements, signal.NodeID)
|
|
|
|
delete(ext.Requirements, signal.NodeID)
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "req_removed"), source)
|
|
|
|
changes = changes.Add(LockableExtType, "requirements")
|
|
|
|
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "unknown_action"), source)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "unknown_action"), source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "not_unlocked"), source)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "not_unlocked"), source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return msgs
|
|
|
|
return messages, changes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (ext *LockableExt) HandleSuccessSignal(ctx *Context, node *Node, source NodeID, signal *SuccessSignal) Messages {
|
|
|
|
func (ext *LockableExt) HandleSuccessSignal(ctx *Context, node *Node, source NodeID, signal *SuccessSignal) (Messages, Changes) {
|
|
|
|
ctx.Log.Logf("lockable", "SUCCESS_SIGNAL: %+v", signal)
|
|
|
|
ctx.Log.Logf("lockable", "SUCCESS_SIGNAL: %+v", signal)
|
|
|
|
|
|
|
|
|
|
|
|
msgs := Messages{}
|
|
|
|
var messages Messages = nil
|
|
|
|
|
|
|
|
var changes Changes = nil
|
|
|
|
if source == node.ID {
|
|
|
|
if source == node.ID {
|
|
|
|
return msgs
|
|
|
|
return messages, changes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
info, found := ext.Requirements[source]
|
|
|
|
info, found := ext.Requirements[source]
|
|
|
@ -148,6 +154,7 @@ func (ext *LockableExt) HandleSuccessSignal(ctx *Context, node *Node, source Nod
|
|
|
|
} else if info.MsgID != signal.ReqID {
|
|
|
|
} else if info.MsgID != signal.ReqID {
|
|
|
|
ctx.Log.Logf("lockable", "Got success for wrong signal for %s: %s, expecting %s", source, signal.ReqID, info.MsgID)
|
|
|
|
ctx.Log.Logf("lockable", "Got success for wrong signal for %s: %s, expecting %s", source, signal.ReqID, info.MsgID)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "requirements")
|
|
|
|
if info.State == Locking {
|
|
|
|
if info.State == Locking {
|
|
|
|
if ext.State == Locking {
|
|
|
|
if ext.State == Locking {
|
|
|
|
info.State = Locked
|
|
|
|
info.State = Locked
|
|
|
@ -166,7 +173,10 @@ func (ext *LockableExt) HandleSuccessSignal(ctx *Context, node *Node, source Nod
|
|
|
|
ctx.Log.Logf("lockable", "WHOLE LOCK: %s - %s - %+v", node.ID, ext.PendingID, ext.PendingOwner)
|
|
|
|
ctx.Log.Logf("lockable", "WHOLE LOCK: %s - %s - %+v", node.ID, ext.PendingID, ext.PendingOwner)
|
|
|
|
ext.State = Locked
|
|
|
|
ext.State = Locked
|
|
|
|
ext.Owner = ext.PendingOwner
|
|
|
|
ext.Owner = ext.PendingOwner
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, NewSuccessSignal(ext.PendingID), *ext.Owner)
|
|
|
|
changes = changes.Add(LockableExtType, "state")
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "owner")
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "pending_owner")
|
|
|
|
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(ext.PendingID), *ext.Owner)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ctx.Log.Logf("lockable", "PARTIAL LOCK: %s - %d/%d", node.ID, locked, reqs)
|
|
|
|
ctx.Log.Logf("lockable", "PARTIAL LOCK: %s - %d/%d", node.ID, locked, reqs)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -175,7 +185,7 @@ func (ext *LockableExt) HandleSuccessSignal(ctx *Context, node *Node, source Nod
|
|
|
|
info.State = Unlocking
|
|
|
|
info.State = Unlocking
|
|
|
|
info.MsgID = lock_signal.ID()
|
|
|
|
info.MsgID = lock_signal.ID()
|
|
|
|
ext.Requirements[source] = info
|
|
|
|
ext.Requirements[source] = info
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, lock_signal, source)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, lock_signal, source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if info.State == Unlocking {
|
|
|
|
} else if info.State == Unlocking {
|
|
|
|
info.State = Unlocked
|
|
|
|
info.State = Unlocked
|
|
|
@ -193,14 +203,17 @@ func (ext *LockableExt) HandleSuccessSignal(ctx *Context, node *Node, source Nod
|
|
|
|
if unlocked == reqs {
|
|
|
|
if unlocked == reqs {
|
|
|
|
old_state := ext.State
|
|
|
|
old_state := ext.State
|
|
|
|
ext.State = Unlocked
|
|
|
|
ext.State = Unlocked
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "state")
|
|
|
|
ctx.Log.Logf("lockable", "WHOLE UNLOCK: %s - %s - %+v", node.ID, ext.PendingID, ext.PendingOwner)
|
|
|
|
ctx.Log.Logf("lockable", "WHOLE UNLOCK: %s - %s - %+v", node.ID, ext.PendingID, ext.PendingOwner)
|
|
|
|
if old_state == Unlocking {
|
|
|
|
if old_state == Unlocking {
|
|
|
|
previous_owner := *ext.Owner
|
|
|
|
previous_owner := *ext.Owner
|
|
|
|
ext.Owner = ext.PendingOwner
|
|
|
|
ext.Owner = ext.PendingOwner
|
|
|
|
ext.ReqID = nil
|
|
|
|
ext.ReqID = nil
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, NewSuccessSignal(ext.PendingID), previous_owner)
|
|
|
|
changes = changes.Add(LockableExtType, "owner")
|
|
|
|
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(ext.PendingID), previous_owner)
|
|
|
|
} else if old_state == AbortingLock {
|
|
|
|
} else if old_state == AbortingLock {
|
|
|
|
msgs = msgs.Add(ctx ,node.ID, node.Key, NewErrorSignal(*ext.ReqID, "not_unlocked"), *ext.PendingOwner)
|
|
|
|
messages = messages.Add(ctx ,node.ID, node.Key, NewErrorSignal(*ext.ReqID, "not_unlocked"), *ext.PendingOwner)
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "pending_owner")
|
|
|
|
ext.PendingOwner = ext.Owner
|
|
|
|
ext.PendingOwner = ext.Owner
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -209,14 +222,16 @@ func (ext *LockableExt) HandleSuccessSignal(ctx *Context, node *Node, source Nod
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return msgs
|
|
|
|
return messages, changes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Handle a LockSignal and update the extensions owner/requirement states
|
|
|
|
// Handle a LockSignal and update the extensions owner/requirement states
|
|
|
|
func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID, signal *LockSignal) Messages {
|
|
|
|
func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID, signal *LockSignal) (Messages, Changes) {
|
|
|
|
ctx.Log.Logf("lockable", "LOCK_SIGNAL: %s->%s %+v", source, node.ID, signal.State)
|
|
|
|
ctx.Log.Logf("lockable", "LOCK_SIGNAL: %s->%s %+v", source, node.ID, signal.State)
|
|
|
|
|
|
|
|
|
|
|
|
msgs := Messages{}
|
|
|
|
var messages Messages = nil
|
|
|
|
|
|
|
|
var changes Changes = nil
|
|
|
|
|
|
|
|
|
|
|
|
switch signal.State {
|
|
|
|
switch signal.State {
|
|
|
|
case "lock":
|
|
|
|
case "lock":
|
|
|
|
if ext.State == Unlocked {
|
|
|
|
if ext.State == Unlocked {
|
|
|
@ -225,7 +240,10 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID
|
|
|
|
new_owner := source
|
|
|
|
new_owner := source
|
|
|
|
ext.PendingOwner = &new_owner
|
|
|
|
ext.PendingOwner = &new_owner
|
|
|
|
ext.Owner = &new_owner
|
|
|
|
ext.Owner = &new_owner
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), new_owner)
|
|
|
|
changes = changes.Add(LockableExtType, "state")
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "pending_owner")
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "owner")
|
|
|
|
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), new_owner)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ext.State = Locking
|
|
|
|
ext.State = Locking
|
|
|
|
id := signal.ID()
|
|
|
|
id := signal.ID()
|
|
|
@ -233,6 +251,9 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID
|
|
|
|
new_owner := source
|
|
|
|
new_owner := source
|
|
|
|
ext.PendingOwner = &new_owner
|
|
|
|
ext.PendingOwner = &new_owner
|
|
|
|
ext.PendingID = signal.ID()
|
|
|
|
ext.PendingID = signal.ID()
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "state")
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "pending_owner")
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "requirements")
|
|
|
|
for id, info := range(ext.Requirements) {
|
|
|
|
for id, info := range(ext.Requirements) {
|
|
|
|
if info.State != Unlocked {
|
|
|
|
if info.State != Unlocked {
|
|
|
|
ctx.Log.Logf("lockable", "REQ_NOT_UNLOCKED_WHEN_LOCKING")
|
|
|
|
ctx.Log.Logf("lockable", "REQ_NOT_UNLOCKED_WHEN_LOCKING")
|
|
|
@ -241,11 +262,11 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID
|
|
|
|
info.State = Locking
|
|
|
|
info.State = Locking
|
|
|
|
info.MsgID = lock_signal.ID()
|
|
|
|
info.MsgID = lock_signal.ID()
|
|
|
|
ext.Requirements[id] = info
|
|
|
|
ext.Requirements[id] = info
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, lock_signal, id)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, lock_signal, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "not_unlocked"), source)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "not_unlocked"), source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "unlock":
|
|
|
|
case "unlock":
|
|
|
|
if ext.State == Locked {
|
|
|
|
if ext.State == Locked {
|
|
|
@ -254,13 +275,19 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID
|
|
|
|
new_owner := source
|
|
|
|
new_owner := source
|
|
|
|
ext.PendingOwner = nil
|
|
|
|
ext.PendingOwner = nil
|
|
|
|
ext.Owner = nil
|
|
|
|
ext.Owner = nil
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), new_owner)
|
|
|
|
changes = changes.Add(LockableExtType, "state")
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "owner")
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "pending_owner")
|
|
|
|
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), new_owner)
|
|
|
|
} else if source == *ext.Owner {
|
|
|
|
} else if source == *ext.Owner {
|
|
|
|
ext.State = Unlocking
|
|
|
|
ext.State = Unlocking
|
|
|
|
id := signal.ID()
|
|
|
|
id := signal.ID()
|
|
|
|
ext.ReqID = &id
|
|
|
|
ext.ReqID = &id
|
|
|
|
ext.PendingOwner = nil
|
|
|
|
ext.PendingOwner = nil
|
|
|
|
ext.PendingID = signal.ID()
|
|
|
|
ext.PendingID = signal.ID()
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "requirements")
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "pending_owner")
|
|
|
|
|
|
|
|
changes = changes.Add(LockableExtType, "state")
|
|
|
|
for id, info := range(ext.Requirements) {
|
|
|
|
for id, info := range(ext.Requirements) {
|
|
|
|
if info.State != Locked {
|
|
|
|
if info.State != Locked {
|
|
|
|
ctx.Log.Logf("lockable", "REQ_NOT_LOCKED_WHEN_UNLOCKING")
|
|
|
|
ctx.Log.Logf("lockable", "REQ_NOT_LOCKED_WHEN_UNLOCKING")
|
|
|
@ -269,22 +296,24 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID
|
|
|
|
info.State = Unlocking
|
|
|
|
info.State = Unlocking
|
|
|
|
info.MsgID = lock_signal.ID()
|
|
|
|
info.MsgID = lock_signal.ID()
|
|
|
|
ext.Requirements[id] = info
|
|
|
|
ext.Requirements[id] = info
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, lock_signal, id)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, lock_signal, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "not_locked"), source)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "not_locked"), source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
ctx.Log.Logf("lockable", "LOCK_ERR: unkown state %s", signal.State)
|
|
|
|
ctx.Log.Logf("lockable", "LOCK_ERR: unkown state %s", signal.State)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return msgs
|
|
|
|
return messages, changes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// LockableExts process Up/Down signals by forwarding them to owner, dependency, and requirement nodes
|
|
|
|
// LockableExts process Up/Down signals by forwarding them to owner, dependency, and requirement nodes
|
|
|
|
// LockSignal and LinkSignal Direct signals are processed to update the requirement/dependency/lock state
|
|
|
|
// 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 {
|
|
|
|
func (ext *LockableExt) Process(ctx *Context, node *Node, source NodeID, signal Signal) (Messages, Changes) {
|
|
|
|
messages := Messages{}
|
|
|
|
var messages Messages = nil
|
|
|
|
|
|
|
|
var changes Changes = nil
|
|
|
|
|
|
|
|
|
|
|
|
switch signal.Direction() {
|
|
|
|
switch signal.Direction() {
|
|
|
|
case Up:
|
|
|
|
case Up:
|
|
|
|
if ext.Owner != nil {
|
|
|
|
if ext.Owner != nil {
|
|
|
@ -292,24 +321,26 @@ func (ext *LockableExt) Process(ctx *Context, node *Node, source NodeID, signal
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, signal, *ext.Owner)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, signal, *ext.Owner)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case Down:
|
|
|
|
case Down:
|
|
|
|
for requirement, _ := range(ext.Requirements) {
|
|
|
|
for requirement := range(ext.Requirements) {
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, signal, requirement)
|
|
|
|
messages = messages.Add(ctx, node.ID, node.Key, signal, requirement)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case Direct:
|
|
|
|
case Direct:
|
|
|
|
switch sig := signal.(type) {
|
|
|
|
switch sig := signal.(type) {
|
|
|
|
case *LinkSignal:
|
|
|
|
case *LinkSignal:
|
|
|
|
messages = ext.HandleLinkSignal(ctx, node, source, sig)
|
|
|
|
messages, changes = ext.HandleLinkSignal(ctx, node, source, sig)
|
|
|
|
case *LockSignal:
|
|
|
|
case *LockSignal:
|
|
|
|
messages = ext.HandleLockSignal(ctx, node, source, sig)
|
|
|
|
messages, changes = ext.HandleLockSignal(ctx, node, source, sig)
|
|
|
|
case *ErrorSignal:
|
|
|
|
case *ErrorSignal:
|
|
|
|
messages = ext.HandleErrorSignal(ctx, node, source, sig)
|
|
|
|
messages, changes = ext.HandleErrorSignal(ctx, node, source, sig)
|
|
|
|
case *SuccessSignal:
|
|
|
|
case *SuccessSignal:
|
|
|
|
messages = ext.HandleSuccessSignal(ctx, node, source, sig)
|
|
|
|
messages, changes = ext.HandleSuccessSignal(ctx, node, source, sig)
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return messages
|
|
|
|
return messages, changes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|