mirror of
https://github.com/postmannen/ctrl.git
synced 2025-01-18 21:59:30 +00:00
implemented the concept of processKind
This commit is contained in:
parent
39e29a079e
commit
29254c04d0
1 changed files with 41 additions and 34 deletions
17
publisher.go
17
publisher.go
|
@ -104,7 +104,7 @@ func (s *server) PublisherStart() {
|
||||||
// Prepare and start a single process
|
// Prepare and start a single process
|
||||||
{
|
{
|
||||||
sub := newSubject("ship1", "command", "shellcommand")
|
sub := newSubject("ship1", "command", "shellcommand")
|
||||||
proc := s.processPrepareNew(sub, s.errorCh)
|
proc := s.processPrepareNew(sub, s.errorCh, processKindPublisher)
|
||||||
// fmt.Printf("*** %#v\n", proc)
|
// fmt.Printf("*** %#v\n", proc)
|
||||||
go s.processSpawnWorker(proc)
|
go s.processSpawnWorker(proc)
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ func (s *server) PublisherStart() {
|
||||||
// Prepare and start a single process
|
// Prepare and start a single process
|
||||||
{
|
{
|
||||||
sub := newSubject("ship2", "command", "shellcommand")
|
sub := newSubject("ship2", "command", "shellcommand")
|
||||||
proc := s.processPrepareNew(sub, s.errorCh)
|
proc := s.processPrepareNew(sub, s.errorCh, processKindPublisher)
|
||||||
// fmt.Printf("*** %#v\n", proc)
|
// fmt.Printf("*** %#v\n", proc)
|
||||||
go s.processSpawnWorker(proc)
|
go s.processSpawnWorker(proc)
|
||||||
}
|
}
|
||||||
|
@ -191,11 +191,14 @@ func (s Subject) name() subjectName {
|
||||||
return subjectName(fmt.Sprintf("%s.%s.%s", s.Node, s.MessageKind, s.Method))
|
return subjectName(fmt.Sprintf("%s.%s.%s", s.Node, s.MessageKind, s.Method))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// processKind are either kindSubscriber or kindPublisher, and are
|
||||||
|
// used to distinguish the kind of process to spawn and to know
|
||||||
|
// the process kind put in the process map.
|
||||||
type processKind string
|
type processKind string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
kindSubscriber processKind = "subscriber"
|
processKindSubscriber processKind = "subscriber"
|
||||||
kindPublisher processKind = "publisher"
|
processKindPublisher processKind = "publisher"
|
||||||
)
|
)
|
||||||
|
|
||||||
// process are represent the communication to one individual host
|
// process are represent the communication to one individual host
|
||||||
|
@ -213,11 +216,12 @@ 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 errProcess
|
errorCh chan errProcess
|
||||||
|
processKind processKind
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) processPrepareNew(subject Subject, errCh chan errProcess) process {
|
func (s *server) processPrepareNew(subject Subject, errCh chan errProcess, processKind processKind) process {
|
||||||
// create the initial configuration for a sessions communicating with 1 host process.
|
// create the initial configuration for a sessions communicating with 1 host process.
|
||||||
s.lastProcessID++
|
s.lastProcessID++
|
||||||
proc := process{
|
proc := process{
|
||||||
|
@ -226,6 +230,7 @@ func (s *server) processPrepareNew(subject Subject, errCh chan errProcess) proce
|
||||||
node: node(subject.Node),
|
node: node(subject.Node),
|
||||||
processID: s.lastProcessID,
|
processID: s.lastProcessID,
|
||||||
errorCh: errCh,
|
errorCh: errCh,
|
||||||
|
processKind: processKind,
|
||||||
//messageCh: make(chan Message),
|
//messageCh: make(chan Message),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,6 +253,7 @@ func (s *server) processSpawnWorker(proc process) {
|
||||||
// give the message to the correct publisher process. A channel that
|
// give the message to the correct publisher process. A channel that
|
||||||
// is listened on in the for loop below could be used to receive the
|
// is listened on in the for loop below could be used to receive the
|
||||||
// messages from the message-pickup-process.
|
// messages from the message-pickup-process.
|
||||||
|
if proc.processKind == processKindPublisher {
|
||||||
for {
|
for {
|
||||||
// Wait and read the next message on the message channel
|
// Wait and read the next message on the message channel
|
||||||
m := <-proc.subject.messageCh
|
m := <-proc.subject.messageCh
|
||||||
|
@ -276,6 +282,7 @@ func (s *server) processSpawnWorker(proc process) {
|
||||||
log.Printf("The errAction was continue...so we're continuing\n")
|
log.Printf("The errAction was continue...so we're continuing\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func messageDeliver(proc process, message Message, natsConn *nats.Conn) {
|
func messageDeliver(proc process, message Message, natsConn *nats.Conn) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue