From 1f02cb0d503dd3a971eed95a7263a10261128d77 Mon Sep 17 00:00:00 2001 From: postmannen Date: Tue, 6 Apr 2021 06:08:26 +0200 Subject: [PATCH] Renamed EchoX to REQPing and REQPong --- configuration_flags.go | 12 ++++++------ etc/config.toml | 16 ++++++++-------- example/toShip1-REQPing.json | 11 +++++++++++ startup_processes.go | 20 ++++++++++---------- subscriber_method_types.go | 24 ++++++++++++------------ 5 files changed, 47 insertions(+), 36 deletions(-) create mode 100644 example/toShip1-REQPing.json diff --git a/configuration_flags.go b/configuration_flags.go index f2e4fb5..eb6bf45 100644 --- a/configuration_flags.go +++ b/configuration_flags.go @@ -106,9 +106,9 @@ type Configuration struct { // Subscriber for text logging StartSubREQTextToLogFile flagNodeSlice // Subscriber for Echo Request - StartSubEchoRequest flagNodeSlice + StartSubREQPing flagNodeSlice // Subscriber for Echo Reply - StartSubEchoReply flagNodeSlice + StartSubREQPong flagNodeSlice // Subscriber for CLICommandRequest StartSubREQCliCommand flagNodeSlice // Subscriber for REQnCliCommand @@ -137,8 +137,8 @@ func newConfigurationDefaults() Configuration { StartSubErrorLog: flagNodeSlice{Values: []node{}}, StartSubREQHello: flagNodeSlice{OK: true, Values: []node{"*"}}, StartSubREQTextToLogFile: flagNodeSlice{OK: true, Values: []node{"*"}}, - StartSubEchoRequest: flagNodeSlice{OK: true, Values: []node{"*"}}, - StartSubEchoReply: flagNodeSlice{OK: true, Values: []node{"*"}}, + StartSubREQPing: flagNodeSlice{OK: true, Values: []node{"*"}}, + StartSubREQPong: flagNodeSlice{OK: true, Values: []node{"*"}}, StartSubREQCliCommand: flagNodeSlice{OK: true, Values: []node{"*"}}, StartSubREQnCliCommand: flagNodeSlice{OK: true, Values: []node{"*"}}, StartSubREQTextToConsole: flagNodeSlice{OK: true, Values: []node{"*"}}, @@ -176,8 +176,8 @@ func (c *Configuration) CheckFlags() error { flag.Var(&c.StartSubErrorLog, "startSubErrorLog", "Specify comma separated list for nodes to allow messages from. Use \"*\" for from all. Value RST will turn off subscriber.") flag.Var(&c.StartSubREQHello, "startSubREQHello", "Specify comma separated list for nodes to allow messages from. Use \"*\" for from all. Value RST will turn off subscriber.") flag.Var(&c.StartSubREQTextToLogFile, "startSubREQTextToLogFile", "Specify comma separated list for nodes to allow messages from. Use \"*\" for from all. Value RST will turn off subscriber.") - flag.Var(&c.StartSubEchoRequest, "startSubEchoRequest", "Specify comma separated list for nodes to allow messages from. Use \"*\" for from all. Value RST will turn off subscriber.") - flag.Var(&c.StartSubEchoReply, "startSubEchoReply", "Specify comma separated list for nodes to allow messages from. Use \"*\" for from all. Value RST will turn off subscriber.") + flag.Var(&c.StartSubREQPing, "startSubREQPing", "Specify comma separated list for nodes to allow messages from. Use \"*\" for from all. Value RST will turn off subscriber.") + flag.Var(&c.StartSubREQPong, "startSubREQPong", "Specify comma separated list for nodes to allow messages from. Use \"*\" for from all. Value RST will turn off subscriber.") flag.Var(&c.StartSubREQCliCommand, "startSubREQCliCommand", "Specify comma separated list for nodes to allow messages from. Use \"*\" for from all. Value RST will turn off subscriber.") flag.Var(&c.StartSubREQnCliCommand, "startSubREQnCliCommand", "Specify comma separated list for nodes to allow messages from. Use \"*\" for from all. Value RST will turn off subscriber.") flag.Var(&c.StartSubREQTextToConsole, "startSubREQTextToConsole", "Specify comma separated list for nodes to allow messages from. Use \"*\" for from all. Value RST will turn off subscriber.") diff --git a/etc/config.toml b/etc/config.toml index e7a922c..8588b4d 100644 --- a/etc/config.toml +++ b/etc/config.toml @@ -9,14 +9,6 @@ PromHostAndPort = ":2112" StartPubREQHello = 0 SubscribersDataFolder = "./data" -[StartSubEchoReply] - OK = true - Values = ["*"] - -[StartSubEchoRequest] - OK = true - Values = ["*"] - [StartSubErrorLog] OK = true Values = ["*"] @@ -29,6 +21,14 @@ SubscribersDataFolder = "./data" OK = true Values = ["*"] +[StartSubREQPing] + OK = true + Values = ["*"] + +[StartSubREQPong] + OK = true + Values = ["*"] + [StartSubREQTextToConsole] OK = true Values = ["*"] diff --git a/example/toShip1-REQPing.json b/example/toShip1-REQPing.json new file mode 100644 index 0000000..7afdb4f --- /dev/null +++ b/example/toShip1-REQPing.json @@ -0,0 +1,11 @@ +[ + { + + "toNode": "ship1", + "data": [""], + "method":"REQPing", + "timeout":3, + "retries":3, + "methodTimeout": 10 + } +] \ No newline at end of file diff --git a/startup_processes.go b/startup_processes.go index 97bf3ab..0260e2d 100644 --- a/startup_processes.go +++ b/startup_processes.go @@ -75,22 +75,22 @@ func (s *server) ProcessesStart() { } } - // Start a subscriber for ECHORequest messages - if s.configuration.StartSubEchoRequest.OK { + // Start a subscriber for Ping Request messages + if s.configuration.StartSubREQPing.OK { { - fmt.Printf("Starting Echo Request subscriber: %#v\n", s.nodeName) - sub := newSubject(ECHORequest, s.nodeName) - proc := newProcess(s.processes, s.toRingbufferCh, s.configuration, sub, s.errorKernel.errorCh, processKindSubscriber, s.configuration.StartSubEchoRequest.Values, nil) + fmt.Printf("Starting Ping Request subscriber: %#v\n", s.nodeName) + sub := newSubject(REQPing, s.nodeName) + proc := newProcess(s.processes, s.toRingbufferCh, s.configuration, sub, s.errorKernel.errorCh, processKindSubscriber, s.configuration.StartSubREQPing.Values, nil) go proc.spawnWorker(s) } } - // Start a subscriber for ECHOReply messages - if s.configuration.StartSubEchoReply.OK { + // Start a subscriber for REQPong messages + if s.configuration.StartSubREQPong.OK { { - fmt.Printf("Starting Echo Reply subscriber: %#v\n", s.nodeName) - sub := newSubject(ECHOReply, s.nodeName) - proc := newProcess(s.processes, s.toRingbufferCh, s.configuration, sub, s.errorKernel.errorCh, processKindSubscriber, s.configuration.StartSubEchoReply.Values, nil) + fmt.Printf("Starting Pong subscriber: %#v\n", s.nodeName) + sub := newSubject(REQPong, s.nodeName) + proc := newProcess(s.processes, s.toRingbufferCh, s.configuration, sub, s.errorKernel.errorCh, processKindSubscriber, s.configuration.StartSubREQPong.Values, nil) go proc.spawnWorker(s) } } diff --git a/subscriber_method_types.go b/subscriber_method_types.go index 190a754..1b580f6 100644 --- a/subscriber_method_types.go +++ b/subscriber_method_types.go @@ -91,9 +91,9 @@ const ( // Echo request will ask the subscriber for a // reply generated as a new message, and sent back to where // the initial request was made. - ECHORequest Method = "ECHORequest" + REQPing Method = "REQPing" // Will generate a reply for a ECHORequest - ECHOReply Method = "ECHOReply" + REQPong Method = "REQPong" ) // The mapping of all the method constants specified, what type @@ -131,10 +131,10 @@ func (m Method) GetMethodsAvailable() MethodsAvailable { ErrorLog: methodErrorLog{ commandOrEvent: EventACK, }, - ECHORequest: methodEchoRequest{ + REQPing: methodREQPing{ commandOrEvent: EventACK, }, - ECHOReply: methodEchoReply{ + REQPong: methodREQPong{ commandOrEvent: EventACK, }, }, @@ -356,20 +356,20 @@ func (m methodErrorLog) handler(proc process, message Message, node string) ([]b // --- -type methodEchoRequest struct { +type methodREQPing struct { commandOrEvent CommandOrEvent } -func (m methodEchoRequest) getKind() CommandOrEvent { +func (m methodREQPing) getKind() CommandOrEvent { return m.commandOrEvent } -func (m methodEchoRequest) handler(proc process, message Message, node string) ([]byte, error) { - log.Printf("<--- ECHO REQUEST received from: %v, containing: %v", message.FromNode, message.Data) +func (m methodREQPing) handler(proc process, message Message, node string) ([]byte, error) { + log.Printf("<--- PING REQUEST received from: %v, containing: %v", message.FromNode, message.Data) // Prepare and queue for sending a new message with the output // of the action executed. - newReplyMessage(proc, message, ECHOReply, []byte{}) + newReplyMessage(proc, message, REQPong, []byte{}) ackMsg := []byte("confirmed from: " + node + ": " + fmt.Sprint(message.ID)) return ackMsg, nil @@ -377,15 +377,15 @@ func (m methodEchoRequest) handler(proc process, message Message, node string) ( // --- -type methodEchoReply struct { +type methodREQPong struct { commandOrEvent CommandOrEvent } -func (m methodEchoReply) getKind() CommandOrEvent { +func (m methodREQPong) getKind() CommandOrEvent { return m.commandOrEvent } -func (m methodEchoReply) handler(proc process, message Message, node string) ([]byte, error) { +func (m methodREQPong) handler(proc process, message Message, node string) ([]byte, error) { log.Printf("<--- ECHO Reply received from: %v, containing: %v", message.FromNode, message.Data) ackMsg := []byte("confirmed from: " + node + ": " + fmt.Sprint(message.ID))