diff --git a/gql.go b/gql.go index 58cbb89..41b3b2c 100644 --- a/gql.go +++ b/gql.go @@ -1000,18 +1000,35 @@ func (ext *GQLExt) Process(ctx *Context, source NodeID, node *Node, signal Signa sig := signal.(StringSignal) switch sig.Str { case "start_server": - err := ext.StartGQLServer(ctx, node) - if err == nil { - ctx.Send(node.ID, source, StringSignal{NewDirectSignal(GQLStateSignalType), "server_started"}) + if ext.State == "stopped" { + err := ext.StartGQLServer(ctx, node) + if err == nil { + ext.State = "running" + ctx.Send(node.ID, source, StringSignal{NewDirectSignal(GQLStateSignalType), "server_started"}) + } } case "stop_server": - err := ext.StopGQLServer() - if err == nil { - ctx.Send(node.ID, source, StringSignal{NewDirectSignal(GQLStateSignalType), "server_stopped"}) + if ext.State == "running" { + err := ext.StopGQLServer() + if err == nil { + ext.State = "stopped" + ctx.Send(node.ID, source, StringSignal{NewDirectSignal(GQLStateSignalType), "server_stopped"}) + } } default: ctx.Log.Logf("gql", "unknown gql state %s", sig.Str) } + } else if signal.Type() == StartSignalType { + switch ext.State { + case "running": + err := ext.StartGQLServer(ctx, node) + if err == nil { + ctx.Send(node.ID, source, StringSignal{NewDirectSignal(GQLStateSignalType), "server_started"}) + } + case "stopped": + default: + ctx.Log.Logf("gql", "unknown state to restore from: %s", ext.State) + } } } @@ -1090,6 +1107,7 @@ func NewGQLExt(ctx *Context, listen string, tls_cert []byte, tls_key []byte, sta tls_key = ssl_key_pem } return &GQLExt{ + State: state, Listen: listen, resolver_reads: map[uuid.UUID]uuid.UUID{}, resolver_chans: map[uuid.UUID]chan *ReadResultSignal{}, diff --git a/gql_test.go b/gql_test.go index b60da0a..4711bbe 100644 --- a/gql_test.go +++ b/gql_test.go @@ -20,7 +20,7 @@ func TestGQL(t *testing.T) { err := ctx.RegisterNodeType(TestNodeType, []ExtType{LockableExtType, ACLExtType}) fatalErr(t, err) - gql_ext, err := NewGQLExt(ctx, ":0", nil, nil, "start") + gql_ext, err := NewGQLExt(ctx, ":0", nil, nil, "stopped") fatalErr(t, err) listener_ext := NewListenerExt(10) policy := NewAllNodesPolicy(Actions{MakeAction("+")}) diff --git a/node.go b/node.go index 75beda4..ff3b518 100644 --- a/node.go +++ b/node.go @@ -195,6 +195,10 @@ func nodeLoop(ctx *Context, node *Node) error { if started == false { return fmt.Errorf("%s is already started, will not start again", node.ID) } + + // Queue the signal for extensions to perform startup actions + node.QueueSignal(time.Now(), NewDirectSignal(StartSignalType)) + for true { var signal Signal var source NodeID diff --git a/signal.go b/signal.go index 0540688..443936c 100644 --- a/signal.go +++ b/signal.go @@ -17,6 +17,7 @@ import ( type SignalDirection int const ( StopSignalType SignalType = "STOP" + StartSignalType = "START" ErrorSignalType = "ERROR" StatusSignalType = "STATUS" LinkSignalType = "LINK"