rb_banyan 0.1.2.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/rb_banyan.iml +25 -0
- data/.idea/workspace.xml +924 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE +661 -0
- data/README.md +135 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/banyan_base/simple_echo_client.rb +85 -0
- data/examples/banyan_base/simple_echo_server.rb +97 -0
- data/examples/coverage/.last_run.json +5 -0
- data/examples/coverage/.resultset.json.lock +0 -0
- data/exe/rb_backplane +150 -0
- data/exe/rb_monitor +75 -0
- data/lib/rb_banyan/banyan_base.rb +188 -0
- data/lib/rb_banyan/version.rb +3 -0
- data/lib/rb_banyan.rb +5 -0
- data/rb_banyan.gemspec +32 -0
- metadata +143 -0
data/README.md
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
## A Simple Echo Server
|
2
|
+
```
|
3
|
+
require 'rb_banyan/banyan_base.rb'
|
4
|
+
|
5
|
+
class SimpleEchoServer < BanyanBase
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
# set the process name for the console banner
|
9
|
+
super(process_name: 'SimpleEchoServer')
|
10
|
+
|
11
|
+
# allow time for zmq connections to complete
|
12
|
+
sleep(0.3)
|
13
|
+
|
14
|
+
# set the subscriber topic
|
15
|
+
set_subscriber_topic('echo')
|
16
|
+
|
17
|
+
# wait for messages to arrive
|
18
|
+
begin
|
19
|
+
receive_loop
|
20
|
+
rescue SystemExit, Interrupt
|
21
|
+
clean_up
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# process incoming messages - just resend the payload with
|
26
|
+
# a topic of 'reply'
|
27
|
+
def incoming_message_processing(_topic, payload)
|
28
|
+
publish_payload(payload, 'reply')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
SimpleEchoServer.new
|
34
|
+
|
35
|
+
```
|
36
|
+
## A Simple Echo Client
|
37
|
+
|
38
|
+
```
|
39
|
+
require 'rubygems'
|
40
|
+
require 'rb_banyan/banyan_base.rb'
|
41
|
+
|
42
|
+
# This is a simple echo client. It sends out a series of messages and expects an
|
43
|
+
# echo reply from the server
|
44
|
+
|
45
|
+
# To use: 1. Start the backplane.
|
46
|
+
# 2. Start the server.
|
47
|
+
# 3. Start this client.
|
48
|
+
|
49
|
+
class SimpleEchoClient < BanyanBase
|
50
|
+
|
51
|
+
def initialize
|
52
|
+
|
53
|
+
# set the process name for the console banner
|
54
|
+
super(process_name:'SimpleEchoClient')
|
55
|
+
|
56
|
+
# allow time for zmq connections to complete
|
57
|
+
sleep(0.3)
|
58
|
+
|
59
|
+
# initialize the number of messages to send and receive
|
60
|
+
@number_of_messages = @message_number = 10
|
61
|
+
|
62
|
+
# set the subscriber topic
|
63
|
+
set_subscriber_topic('reply')
|
64
|
+
|
65
|
+
# send the first message
|
66
|
+
publish_payload({'message_number': @message_number}, 'echo')
|
67
|
+
|
68
|
+
# adjust the message number for the next send
|
69
|
+
@message_number -= 1
|
70
|
+
|
71
|
+
# get the reply messages
|
72
|
+
# wait for messages to arrive
|
73
|
+
begin
|
74
|
+
receive_loop
|
75
|
+
rescue SystemExit, Interrupt
|
76
|
+
clean_up
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# With each incoming message, adjust the message number and
|
81
|
+
# publish the next message until the count is achieved.
|
82
|
+
def incoming_message_processing(_topic, payload)
|
83
|
+
# if all messages received, we are done.
|
84
|
+
if payload['message_number'] == 0
|
85
|
+
puts('All messages sent and received')
|
86
|
+
clean_up
|
87
|
+
exit(0)
|
88
|
+
|
89
|
+
# we have more to send - bump the message number and send the message out
|
90
|
+
else
|
91
|
+
@message_number -= 1
|
92
|
+
publish_payload({'message_number': @message_number}, 'echo')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
SimpleEchoClient.new
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
# RbBanyan
|
102
|
+
|
103
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rb_banyan`. To experiment with that code, run `bin/console` for an interactive prompt.
|
104
|
+
|
105
|
+
TODO: Delete this and the text above, and describe your gem
|
106
|
+
|
107
|
+
## Installation
|
108
|
+
|
109
|
+
Add this line to your application's Gemfile:
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
gem 'rb_banyan'
|
113
|
+
```
|
114
|
+
|
115
|
+
And then execute:
|
116
|
+
|
117
|
+
$ bundle
|
118
|
+
|
119
|
+
Or install it yourself as:
|
120
|
+
|
121
|
+
$ gem install rb_banyan
|
122
|
+
|
123
|
+
## Usage
|
124
|
+
|
125
|
+
TODO: Write usage instructions here
|
126
|
+
|
127
|
+
## Development
|
128
|
+
|
129
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
130
|
+
|
131
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
132
|
+
|
133
|
+
## Contributing
|
134
|
+
|
135
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rb_banyan.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rb_banyan"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
########################################################################################
|
2
|
+
# Copyright (c) 2017 Alan Yorinks - All Rights Reserved.
|
3
|
+
#
|
4
|
+
# This file is part of JavaScript-Banyan.
|
5
|
+
#
|
6
|
+
# Ruby Banyan is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
8
|
+
# Version 3 as published by the Free Software Foundation; either
|
9
|
+
# or (at your option) any later version.
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# General Public License for more details.
|
14
|
+
|
15
|
+
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
|
16
|
+
# along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
#
|
19
|
+
# simple_echo_server.rb
|
20
|
+
########################################################################################
|
21
|
+
|
22
|
+
require_relative '../../lib/rb_banyan/banyan_base.rb'
|
23
|
+
|
24
|
+
# This is a simple echo client. It sends out a series of messages and expects an
|
25
|
+
# echo reply from the server
|
26
|
+
|
27
|
+
# To use: 1. Start the backplane.
|
28
|
+
# 2. Start the server.
|
29
|
+
# 3. Start this client.
|
30
|
+
|
31
|
+
class SimpleEchoClient < BanyanBase
|
32
|
+
|
33
|
+
def initialize(process_name: 'SimpleEchoClient',
|
34
|
+
subscribe_topic: 'echo',
|
35
|
+
publish_topic: 'reply',
|
36
|
+
publish_payload: {'message_number': @message_number})
|
37
|
+
|
38
|
+
super(process_name:process_name)
|
39
|
+
|
40
|
+
# allow time for zmq connections to complete
|
41
|
+
sleep(0.3)
|
42
|
+
|
43
|
+
# initialize the number of messages to send and receive
|
44
|
+
@number_of_messages = @message_number = 10
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
# set the subscriber topic
|
49
|
+
set_subscriber_topic('reply')
|
50
|
+
|
51
|
+
# send the first message - make sure that the server is already started
|
52
|
+
publish_payload({'message_number': @message_number}, 'echo')
|
53
|
+
# adjust the message number for the next send
|
54
|
+
@message_number -= 1
|
55
|
+
|
56
|
+
# get the reply messages
|
57
|
+
begin
|
58
|
+
receive_loop
|
59
|
+
rescue SystemExit, Interrupt
|
60
|
+
clean_up
|
61
|
+
exit(0)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def incoming_message_processing(_topic, payload)
|
66
|
+
if payload['message_number'] == 0
|
67
|
+
# all messages sent - wait for user to press Enter to exit the client.
|
68
|
+
begin
|
69
|
+
puts((@number_of_messages).to_s + ' messages sent and received. ')
|
70
|
+
puts('Press enter to exit.')
|
71
|
+
gets
|
72
|
+
clean_up
|
73
|
+
exit(0)
|
74
|
+
end
|
75
|
+
|
76
|
+
# bump the message number and send the message out
|
77
|
+
else
|
78
|
+
@message_number -= 1
|
79
|
+
publish_payload({'message_number': @message_number}, 'echo')
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
SimpleEchoClient.new
|
@@ -0,0 +1,97 @@
|
|
1
|
+
########################################################################################
|
2
|
+
# Copyright (c) 2017 Alan Yorinks - All Rights Reserved.
|
3
|
+
#
|
4
|
+
# This file is part of JavaScript-Banyan.
|
5
|
+
#
|
6
|
+
# Ruby Banyan is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
8
|
+
# Version 3 as published by the Free Software Foundation; either
|
9
|
+
# or (at your option) any later version.
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# General Public License for more details.
|
14
|
+
|
15
|
+
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
|
16
|
+
# along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
#
|
19
|
+
# simple_echo_server.rb
|
20
|
+
#############################################################################
|
21
|
+
|
22
|
+
require_relative '../../lib/rb_banyan/banyan_base.rb'
|
23
|
+
###################################################################
|
24
|
+
# This is a very basic echo server.
|
25
|
+
# It subscribes to receive messages with a topic of 'echo', and
|
26
|
+
# when a message is received, it publishes the received payload,
|
27
|
+
# with a topic of 'reply'
|
28
|
+
###################################################################
|
29
|
+
class SimpleEchoServer < BanyanBase
|
30
|
+
|
31
|
+
def initialize(process_name: 'SimpleEchoServer',
|
32
|
+
subscribe_topic: 'echo',
|
33
|
+
publish_topic: 'reply')
|
34
|
+
|
35
|
+
super(process_name:process_name)
|
36
|
+
sleep(0.3)
|
37
|
+
|
38
|
+
@subscribe_topic = subscribe_topic
|
39
|
+
@publish_topic = publish_topic
|
40
|
+
|
41
|
+
# allow time for zmq connections to complete
|
42
|
+
|
43
|
+
# set the subscriber topic
|
44
|
+
set_subscriber_topic(@subscribe_topic)
|
45
|
+
|
46
|
+
# wait for messages to arrive
|
47
|
+
begin
|
48
|
+
receive_loop
|
49
|
+
rescue SystemExit, Interrupt
|
50
|
+
clean_up
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
# process incoming messages - just resend the payload with
|
56
|
+
# a topic of 'reply'
|
57
|
+
def incoming_message_processing(_topic, payload)
|
58
|
+
publish_payload(payload, @publish_topic)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
options = { process_name: 'MultiEchoClient',
|
65
|
+
subscribe_topic: 'echo',
|
66
|
+
publish_topic: 'reply'}
|
67
|
+
|
68
|
+
optparse = OptionParser.new do |opts|
|
69
|
+
opts.on('-n', '--n Process Name',
|
70
|
+
'Name Of This Banyan Component') do |process_name|
|
71
|
+
options[:process_name] = process_name
|
72
|
+
end
|
73
|
+
|
74
|
+
opts.on('-p', '--p Publish Topic',
|
75
|
+
'Topic String') do |loop_time|
|
76
|
+
options[:publish_topic] = loop_time
|
77
|
+
end
|
78
|
+
|
79
|
+
opts.on('-s', '--s Subscribe Topic',
|
80
|
+
'Topic String') do |loop_time|
|
81
|
+
options[:subscribe_topic] = loop_time
|
82
|
+
end
|
83
|
+
|
84
|
+
opts.on('-h', '--help', 'Display this screen') do
|
85
|
+
puts opts
|
86
|
+
exit
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
begin
|
91
|
+
optparse.parse!
|
92
|
+
end
|
93
|
+
|
94
|
+
options[:loop_time] = options[:loop_time].to_f
|
95
|
+
SimpleEchoServer.new(process_name: options[:process_name],
|
96
|
+
publish_topic: options[:publish_topic],
|
97
|
+
subscribe_topic: options[:subscribe_topic])
|
File without changes
|
data/exe/rb_backplane
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
|
4
|
+
###########################################################################
|
5
|
+
# Copyright (c) 2017 Alan Yorinks - All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This file is part of Ruby-Banyan.
|
8
|
+
#
|
9
|
+
# Ruby Banyan is free software; you can redistribute it and/or
|
10
|
+
# modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
11
|
+
# Version 3 as published by the Free Software Foundation; either
|
12
|
+
# or (at your option) any later version.
|
13
|
+
# This library is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
+
# General Public License for more details.
|
17
|
+
|
18
|
+
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
|
19
|
+
# along with this library; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#
|
22
|
+
# banyan_base.rb
|
23
|
+
#############################################################################
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
require 'ffi-rzmq'
|
27
|
+
require 'socket'
|
28
|
+
require 'msgpack'
|
29
|
+
require 'optparse'
|
30
|
+
|
31
|
+
###################################################################
|
32
|
+
# This the banyan backplane for ruby. It must be started before
|
33
|
+
# any other banyan components are invoked.
|
34
|
+
|
35
|
+
###################################################################
|
36
|
+
|
37
|
+
# noinspection RubyResolve,RubyResolve
|
38
|
+
|
39
|
+
class BackPlane
|
40
|
+
|
41
|
+
def initialize(subscriber_port: '43125', publisher_port: '43124',
|
42
|
+
process_name: 'Backplane', loop_time: 0.001)
|
43
|
+
|
44
|
+
# This is the initializer for the Banyan BackPlane class. The class must be instantiated
|
45
|
+
# before starting any other Python Banyan modules
|
46
|
+
|
47
|
+
# :param subscriber_port: subscriber IP port number
|
48
|
+
# :param publisher_port: publisher IP port number
|
49
|
+
# :param backplane_name: name to appear on the console for this backplane
|
50
|
+
# :param loop_time: event loop idle timer
|
51
|
+
|
52
|
+
@subscriber_port = subscriber_port
|
53
|
+
@publisher_port = publisher_port
|
54
|
+
@process_name = process_name
|
55
|
+
@loop_time = loop_time
|
56
|
+
|
57
|
+
@back_plane_ip_address = Socket.ip_address_list[1].ip_address
|
58
|
+
|
59
|
+
puts('************************************************************')
|
60
|
+
# noinspection RubyResolve
|
61
|
+
puts(process_name + ' BackPlane on IP address: ' +
|
62
|
+
@back_plane_ip_address)
|
63
|
+
puts('Subscriber Port = ' + @subscriber_port)
|
64
|
+
puts('Publisher Port = ' + @publisher_port)
|
65
|
+
puts('Loop Time = ' + @loop_time.to_s + ' seconds')
|
66
|
+
puts('************************************************************')
|
67
|
+
|
68
|
+
# establish the zeromq sub and pub sockets and connect to the backplane
|
69
|
+
@context = ZMQ::Context.create
|
70
|
+
|
71
|
+
@subscriber = @context.socket ZMQ::SUB
|
72
|
+
@publisher = @context.socket ZMQ::PUB
|
73
|
+
|
74
|
+
# subscribe to all messages
|
75
|
+
@subscriber.setsockopt ZMQ::SUBSCRIBE, ''
|
76
|
+
|
77
|
+
# noinspection RubyResolve
|
78
|
+
# this looks backwards, but is correct. the backplane
|
79
|
+
# accepts messages and re-sends them.
|
80
|
+
@subscriber.bind 'tcp://' + @back_plane_ip_address + ':' + @publisher_port
|
81
|
+
@publisher.bind 'tcp://' + @back_plane_ip_address + ':' + @subscriber_port
|
82
|
+
trap("INT") {puts "Control C detected - bye bye."; @publisher.close; @subscriber.close; @context.terminate; exit}
|
83
|
+
|
84
|
+
loop do
|
85
|
+
list = []
|
86
|
+
p = @subscriber.recv_strings(list, ZMQ::DONTWAIT)
|
87
|
+
begin
|
88
|
+
if p == -1
|
89
|
+
sleep(@loop_time)
|
90
|
+
if ZMQ::Util.errno == ZMQ::EAGAIN
|
91
|
+
next
|
92
|
+
else
|
93
|
+
puts ZMQ::Util.errno
|
94
|
+
end
|
95
|
+
else
|
96
|
+
@publisher.send_strings(list, flags = ZMQ::DONTWAIT)
|
97
|
+
end
|
98
|
+
rescue Interrupt
|
99
|
+
clean_up
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def clean_up
|
105
|
+
# cleanup before exiting
|
106
|
+
|
107
|
+
@publisher.close
|
108
|
+
@subscriber.close
|
109
|
+
@context.terminate
|
110
|
+
exit
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
options = {publisher_port: '43124',
|
115
|
+
subscriber_port: '43125', process_name: 'Unknown',
|
116
|
+
loop_time: '0.01'}
|
117
|
+
|
118
|
+
optparse = OptionParser.new do |opts|
|
119
|
+
|
120
|
+
opts.on('-p', '--p PUBLISHER PORT', 'Publisher Port Number') do |publisher_port|
|
121
|
+
options[:publisher_port] = publisher_port
|
122
|
+
end
|
123
|
+
|
124
|
+
opts.on('-s', '--s SUBSCRIBER PORT', 'Subscriber Port Number') do |subscriber_port|
|
125
|
+
options[:subscriber_port] = subscriber_port
|
126
|
+
end
|
127
|
+
|
128
|
+
opts.on('-n', '--n Process Name', 'Name Of This Banyan Component') do |process_name|
|
129
|
+
options[:process_name] = process_name
|
130
|
+
end
|
131
|
+
|
132
|
+
opts.on('-t', '--t Loop Delay Time', 'Time In Seconds') do |loop_time|
|
133
|
+
options[:loop_time] = loop_time
|
134
|
+
end
|
135
|
+
opts.on('-h', '--help', 'Display this screen') do
|
136
|
+
puts opts
|
137
|
+
exit
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
begin
|
142
|
+
optparse.parse!
|
143
|
+
end
|
144
|
+
|
145
|
+
options[:loop_time] = options[:loop_time].to_f
|
146
|
+
BackPlane.new(subscriber_port: options[:subscriber_port],
|
147
|
+
publisher_port: options[:publisher_port],
|
148
|
+
process_name: options[:process_name],
|
149
|
+
loop_time: options[:loop_time])
|
150
|
+
|
data/exe/rb_monitor
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/rb_banyan/banyan_base.rb'
|
4
|
+
|
5
|
+
|
6
|
+
class RBMonitor < BanyanBase
|
7
|
+
def initialize(back_plane_ip_address: nil, subscriber_port: '43125', publisher_port: '43124',
|
8
|
+
process_name: 'Monitor', loop_time: 0.1)
|
9
|
+
|
10
|
+
back_plane_ip_address = Socket.ip_address_list[1].ip_address if back_plane_ip_address.nil?
|
11
|
+
|
12
|
+
super(back_plane_ip_address: back_plane_ip_address, subscriber_port: subscriber_port, publisher_port: publisher_port,
|
13
|
+
process_name: process_name, loop_time: loop_time)
|
14
|
+
|
15
|
+
# allow time for zmq connections to complete
|
16
|
+
sleep(0.3)
|
17
|
+
|
18
|
+
set_subscriber_topic('')
|
19
|
+
|
20
|
+
# wait for messages to arrive
|
21
|
+
begin
|
22
|
+
receive_loop
|
23
|
+
rescue SystemExit, Interrupt
|
24
|
+
clean_up
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def incoming_message_processing(topic, payload)
|
29
|
+
puts(topic, payload)
|
30
|
+
STDOUT.flush
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
options = {back_plane_ip_address: nil, publisher_port: '43124',
|
35
|
+
subscriber_port: '43125', process_name: 'Banyan Monitor',
|
36
|
+
loop_time: '0.001'}
|
37
|
+
|
38
|
+
optparse = OptionParser.new do |opts|
|
39
|
+
opts.on('-b', '--b Backplane Ip Address', 'IP address of Backplane in use') do |back_plane_ip_address|
|
40
|
+
options[:back_plane_ip_address] = back_plane_ip_address
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on('-p', '--p PUBLISHER PORT', 'Publisher Port Number') do |publisher_port|
|
44
|
+
options[:publisher_port] = publisher_port
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on('-s', '--s SUBSCRIBER PORT', 'Subscriber Port Number') do |subscriber_port|
|
48
|
+
options[:subscriber_port] = subscriber_port
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on('-n', '--n Process Name', 'Name Of This Banyan Component') do |process_name|
|
52
|
+
options[:process_name] = process_name
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on('-t', '--t Loop Delay Time', 'Time In Seconds') do |loop_time|
|
56
|
+
options[:loop_time] = loop_time
|
57
|
+
end
|
58
|
+
opts.on('-h', '--help', 'Display this screen') do
|
59
|
+
puts opts
|
60
|
+
exit
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
begin
|
65
|
+
optparse.parse!
|
66
|
+
end
|
67
|
+
|
68
|
+
options[:loop_time] = options[:loop_time].to_f
|
69
|
+
b = RBMonitor.new(back_plane_ip_address: options[:back_plane_ip_address],
|
70
|
+
subscriber_port: options[:subscriber_port],
|
71
|
+
publisher_port: options[:publisher_port],
|
72
|
+
process_name: options[:process_name],
|
73
|
+
loop_time: options[:loop_time])
|
74
|
+
|
75
|
+
|