Support N distributed agents
This is the third main feature of this system. The code needs a bunch of polish, but it actually all works :) I've tested this briefly with N <= 3. Currently you have to build your own etcd cluster. It's quite easy, just run `etcd` and it will be ready. I usually run it in a throw away /tmp/ dir so that I can blow away the stored data easily.
This commit is contained in:
21
types.go
21
types.go
@@ -33,6 +33,8 @@ type Type interface {
|
||||
SetVertex(*Vertex)
|
||||
Compare(Type) bool
|
||||
SendEvent(eventName, bool)
|
||||
IsWatching() bool
|
||||
SetWatching(bool)
|
||||
GetTimestamp() int64
|
||||
UpdateTimestamp() int64
|
||||
//Process()
|
||||
@@ -43,6 +45,7 @@ type BaseType struct {
|
||||
timestamp int64 // last updated timestamp ?
|
||||
events chan Event
|
||||
vertex *Vertex
|
||||
watching bool // is Watch() loop running ?
|
||||
}
|
||||
|
||||
type NoopType struct {
|
||||
@@ -84,6 +87,16 @@ func (obj *BaseType) SetVertex(v *Vertex) {
|
||||
obj.vertex = v
|
||||
}
|
||||
|
||||
// is the Watch() function running?
|
||||
func (obj *BaseType) IsWatching() bool {
|
||||
return obj.watching
|
||||
}
|
||||
|
||||
// store status of if the Watch() function is running
|
||||
func (obj *BaseType) SetWatching(b bool) {
|
||||
obj.watching = b
|
||||
}
|
||||
|
||||
// get timestamp of a vertex
|
||||
func (obj *BaseType) GetTimestamp() int64 {
|
||||
return obj.timestamp
|
||||
@@ -160,7 +173,7 @@ func (obj *BaseType) ReadEvent(event *Event) bool {
|
||||
e.ACK()
|
||||
if e.Name == eventExit {
|
||||
return false
|
||||
} else if e.Name == eventContinue {
|
||||
} else if e.Name == eventStart { // eventContinue
|
||||
return true
|
||||
} else {
|
||||
log.Fatal("Unknown event: ", e)
|
||||
@@ -208,6 +221,12 @@ func (obj *NoopType) GetType() string {
|
||||
}
|
||||
|
||||
func (obj *NoopType) Watch() {
|
||||
if obj.IsWatching() {
|
||||
return
|
||||
}
|
||||
obj.SetWatching(true)
|
||||
defer obj.SetWatching(false)
|
||||
|
||||
//vertex := obj.vertex // stored with SetVertex
|
||||
var send = false // send event?
|
||||
for {
|
||||
|
||||
Reference in New Issue
Block a user