mirror of
https://github.com/postmannen/ctrl.git
synced 2025-01-07 04:49:17 +00:00
added subject as its own type attached to process
This commit is contained in:
parent
c8886121b9
commit
fea2d576a4
1 changed files with 42 additions and 21 deletions
55
publisher.go
55
publisher.go
|
@ -107,13 +107,29 @@ func (s *server) RunPublisher() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
proc := s.prepareNewProcess("btship1")
|
{
|
||||||
|
sub := subject{
|
||||||
|
node: "btship1",
|
||||||
|
messageType: "command",
|
||||||
|
method: "shellcommand",
|
||||||
|
domain: "shell",
|
||||||
|
}
|
||||||
|
proc := s.prepareNewProcess(sub)
|
||||||
// fmt.Printf("*** %#v\n", proc)
|
// fmt.Printf("*** %#v\n", proc)
|
||||||
go s.spawnProcess(proc)
|
go s.spawnProcess(proc)
|
||||||
|
}
|
||||||
|
|
||||||
proc = s.prepareNewProcess("btship2")
|
{
|
||||||
|
sub := subject{
|
||||||
|
node: "btship2",
|
||||||
|
messageType: "command",
|
||||||
|
method: "shellcommand",
|
||||||
|
domain: "shell",
|
||||||
|
}
|
||||||
|
proc := s.prepareNewProcess(sub)
|
||||||
// fmt.Printf("*** %#v\n", proc)
|
// fmt.Printf("*** %#v\n", proc)
|
||||||
go s.spawnProcess(proc)
|
go s.spawnProcess(proc)
|
||||||
|
}
|
||||||
|
|
||||||
select {}
|
select {}
|
||||||
|
|
||||||
|
@ -121,10 +137,27 @@ func (s *server) RunPublisher() {
|
||||||
|
|
||||||
type node string
|
type node string
|
||||||
|
|
||||||
|
// subject contains the representation of a subject to be used with one
|
||||||
|
// specific process
|
||||||
|
type subject struct {
|
||||||
|
// node, the name of the node
|
||||||
|
node string
|
||||||
|
// messageType, command/event
|
||||||
|
messageType string
|
||||||
|
// method, what is this message doing, etc. shellcommand, syslog, etc.
|
||||||
|
method string
|
||||||
|
// domain is used to differentiate services. Like there can be more
|
||||||
|
// logging services, but rarely more logging services for the same
|
||||||
|
// thing. Domain is here used to differentiate the the services and
|
||||||
|
// tell with one word what it is for.
|
||||||
|
domain string
|
||||||
|
}
|
||||||
|
|
||||||
// process are represent the communication to one individual host
|
// process are represent the communication to one individual host
|
||||||
type process struct {
|
type process struct {
|
||||||
messageID int
|
messageID int
|
||||||
subject string
|
// the subject used for the specific process
|
||||||
|
subjects subject
|
||||||
// Put a node here to be able know the node a process is at.
|
// Put a node here to be able know the node a process is at.
|
||||||
// NB: Might not be needed later on.
|
// NB: Might not be needed later on.
|
||||||
node node
|
node node
|
||||||
|
@ -133,28 +166,16 @@ type process struct {
|
||||||
// errorCh is used to report errors from a process
|
// errorCh is used to report errors from a process
|
||||||
// NB: Implementing this as an int to report for testing
|
// NB: Implementing this as an int to report for testing
|
||||||
errorCh chan string
|
errorCh chan string
|
||||||
// subject
|
|
||||||
}
|
|
||||||
|
|
||||||
type subject struct {
|
|
||||||
// node, the name of the node
|
|
||||||
node string
|
|
||||||
// messageType, command/event
|
|
||||||
messageType string
|
|
||||||
// method, what is this message doing, etc. shellcommand, syslog, etc.
|
|
||||||
method string
|
|
||||||
// description, usefu
|
|
||||||
description string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepareNewProcess will set the the provided values and the default
|
// prepareNewProcess will set the the provided values and the default
|
||||||
// values for a process.
|
// values for a process.
|
||||||
func (s *server) prepareNewProcess(nodeName string) process {
|
func (s *server) prepareNewProcess(subject subject) process {
|
||||||
// create the initial configuration for a sessions communicating with 1 host.
|
// create the initial configuration for a sessions communicating with 1 host.
|
||||||
s.lastProcessID++
|
s.lastProcessID++
|
||||||
proc := process{
|
proc := process{
|
||||||
messageID: 0,
|
messageID: 0,
|
||||||
node: node(nodeName),
|
node: node(subject.node),
|
||||||
processID: s.lastProcessID,
|
processID: s.lastProcessID,
|
||||||
errorCh: make(chan string),
|
errorCh: make(chan string),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue