mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +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
|
||||
{
|
||||
sub := newSubject("ship1", "command", "shellcommand")
|
||||
proc := s.processPrepareNew(sub, s.errorCh)
|
||||
proc := s.processPrepareNew(sub, s.errorCh, processKindPublisher)
|
||||
// fmt.Printf("*** %#v\n", proc)
|
||||
go s.processSpawnWorker(proc)
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ func (s *server) PublisherStart() {
|
|||
// Prepare and start a single process
|
||||
{
|
||||
sub := newSubject("ship2", "command", "shellcommand")
|
||||
proc := s.processPrepareNew(sub, s.errorCh)
|
||||
proc := s.processPrepareNew(sub, s.errorCh, processKindPublisher)
|
||||
// fmt.Printf("*** %#v\n", 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))
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
const (
|
||||
kindSubscriber processKind = "subscriber"
|
||||
kindPublisher processKind = "publisher"
|
||||
processKindSubscriber processKind = "subscriber"
|
||||
processKindPublisher processKind = "publisher"
|
||||
)
|
||||
|
||||
// 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
|
||||
// NB: Implementing this as an int to report for testing
|
||||
errorCh chan errProcess
|
||||
processKind processKind
|
||||
}
|
||||
|
||||
// prepareNewProcess will set the the provided values and the default
|
||||
// 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.
|
||||
s.lastProcessID++
|
||||
proc := process{
|
||||
|
@ -226,6 +230,7 @@ func (s *server) processPrepareNew(subject Subject, errCh chan errProcess) proce
|
|||
node: node(subject.Node),
|
||||
processID: s.lastProcessID,
|
||||
errorCh: errCh,
|
||||
processKind: processKind,
|
||||
//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
|
||||
// is listened on in the for loop below could be used to receive the
|
||||
// messages from the message-pickup-process.
|
||||
if proc.processKind == processKindPublisher {
|
||||
for {
|
||||
// Wait and read the next message on the message channel
|
||||
m := <-proc.subject.messageCh
|
||||
|
@ -277,6 +283,7 @@ func (s *server) processSpawnWorker(proc process) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func messageDeliver(proc process, message Message, natsConn *nats.Conn) {
|
||||
for {
|
||||
|
|
Loading…
Reference in a new issue