rsmp 0.1.19 → 0.1.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +10 -10
- data/documentation/{classes.md → classes_and_modules.md} +25 -22
- data/documentation/message_distribution.md +23 -0
- data/lib/rsmp.rb +9 -5
- data/lib/rsmp/archive.rb +5 -13
- data/lib/rsmp/{probe.rb → collector.rb} +31 -42
- data/lib/rsmp/{site_base.rb → components.rb} +2 -2
- data/lib/rsmp/listener.rb +33 -0
- data/lib/rsmp/logger.rb +3 -3
- data/lib/rsmp/{base.rb → logging.rb} +2 -2
- data/lib/rsmp/node.rb +4 -6
- data/lib/rsmp/notifier.rb +24 -0
- data/lib/rsmp/proxy.rb +25 -5
- data/lib/rsmp/site.rb +2 -2
- data/lib/rsmp/site_proxy.rb +66 -84
- data/lib/rsmp/site_proxy_wait.rb +181 -0
- data/lib/rsmp/supervisor.rb +2 -2
- data/lib/rsmp/supervisor_proxy.rb +0 -1
- data/lib/rsmp/tlc.rb +20 -4
- data/lib/rsmp/version.rb +1 -1
- data/lib/rsmp/wait.rb +4 -151
- data/rsmp.gemspec +4 -4
- metadata +22 -19
- data/lib/rsmp/probe_collection.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0aea7740c0640bc069efa1ec9426deb23b3bf4e3f7dce4656e3df814500615d3
|
4
|
+
data.tar.gz: 30d954a75a62d71d46b76b30e448dbc2e30281784f18b82488780e9837b1223b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a42695cbf11f334d1873843a2550e7734d7719e8fca7ef245d32946d71aa884b6305ff329afbd1713caec41bf213bd0aab62d4f91f5d685c05ed5ce929c68f6
|
7
|
+
data.tar.gz: 3e6c90b6aa6d505285fc27613ce06716f5a00a21893d266cb2e31e0c0f99ea2784610f30f9c4a583c129e95c94770c84a08aabcc6e0e35accfc70b94f3aa2e60
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rsmp (0.1.
|
5
|
-
async (~> 1.
|
6
|
-
async-io (~> 1.
|
4
|
+
rsmp (0.1.21)
|
5
|
+
async (~> 1.28.3)
|
6
|
+
async-io (~> 1.30.1)
|
7
7
|
colorize (~> 0.8.1)
|
8
|
-
json_schemer (~> 0.2.
|
8
|
+
json_schemer (~> 0.2.17)
|
9
9
|
thor (~> 1.0.1)
|
10
10
|
|
11
11
|
GEM
|
@@ -18,11 +18,11 @@ GEM
|
|
18
18
|
ffi (~> 1.9)
|
19
19
|
rspec-expectations (~> 3.4)
|
20
20
|
thor (~> 1.0)
|
21
|
-
async (1.
|
22
|
-
console (~> 1.
|
21
|
+
async (1.28.3)
|
22
|
+
console (~> 1.10)
|
23
23
|
nio4r (~> 2.3)
|
24
24
|
timers (~> 4.1)
|
25
|
-
async-io (1.
|
25
|
+
async-io (1.30.1)
|
26
26
|
async (~> 1.14)
|
27
27
|
backports (3.17.0)
|
28
28
|
builder (3.2.4)
|
@@ -63,7 +63,7 @@ GEM
|
|
63
63
|
multi_test (0.1.2)
|
64
64
|
nio4r (2.5.4)
|
65
65
|
rake (13.0.1)
|
66
|
-
regexp_parser (2.0.
|
66
|
+
regexp_parser (2.0.3)
|
67
67
|
rspec (3.9.0)
|
68
68
|
rspec-core (~> 3.9.0)
|
69
69
|
rspec-expectations (~> 3.9.0)
|
@@ -87,7 +87,7 @@ PLATFORMS
|
|
87
87
|
|
88
88
|
DEPENDENCIES
|
89
89
|
aruba (~> 1.0.0)
|
90
|
-
bundler (~> 2.
|
90
|
+
bundler (~> 2.2.3)
|
91
91
|
cucumber (~> 3.1.2)
|
92
92
|
rake (~> 13.0.1)
|
93
93
|
rsmp!
|
@@ -96,4 +96,4 @@ DEPENDENCIES
|
|
96
96
|
timecop (~> 0.9.1)
|
97
97
|
|
98
98
|
BUNDLED WITH
|
99
|
-
2.
|
99
|
+
2.2.3
|
@@ -1,42 +1,49 @@
|
|
1
|
-
# Classes
|
1
|
+
# Classes and Modules
|
2
2
|
|
3
|
-
##
|
3
|
+
## Overview
|
4
4
|
```
|
5
|
+
Node - - include Logging, Wait
|
6
|
+
/ \
|
7
|
+
Super Site - - include Components
|
5
8
|
|
6
|
-
.------ Base -------.
|
7
|
-
/ \
|
8
|
-
/ \
|
9
|
-
/ SiteBase module \
|
10
|
-
Node / \ Proxy
|
11
|
-
/ \ / \ / \
|
12
|
-
Super Site SiteProxy SupervisorProxy
|
13
9
|
|
10
|
+
Proxy - - include Logging, Wait
|
11
|
+
/ \
|
12
|
+
SupervisorProxy SiteProxy - - include Components, SiteProxyWait
|
14
13
|
```
|
15
14
|
|
15
|
+
## Modules
|
16
|
+
### Logging
|
17
|
+
Handle logging.
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
### Wait
|
20
|
+
Handles waiting for an async condition and block.
|
19
21
|
|
20
|
-
|
22
|
+
### SiteProxyWait
|
23
|
+
Handles waiting for different types of messages and responses from a remote site.
|
21
24
|
|
22
|
-
|
25
|
+
### Components
|
26
|
+
Component handling.
|
27
|
+
|
28
|
+
## Classes
|
29
|
+
### Node
|
23
30
|
A Node has an async task. A node can be started and stopped.
|
24
31
|
|
25
32
|
Node has two child classes: Site and Supervisor.
|
26
33
|
|
27
|
-
|
34
|
+
### Site
|
28
35
|
A Site represents an RSMP site, typically a traffic light, variable message sign, or other type of field equipment. An RSMP site can connect to one or more supervisors.
|
29
36
|
|
30
37
|
A Site has one or more SupervisorProxies (connections to supervisor).
|
31
38
|
|
32
39
|
A site has one of more components.
|
33
40
|
|
34
|
-
|
41
|
+
### Supervisor
|
35
42
|
A Supervisor represents an RSMP supervisor, typically a central supervisor system. An RSMP supervisor can handle connections one or more sites.
|
36
43
|
|
37
44
|
A Supervisor has one or more SiteProxies (connections to sites).
|
38
45
|
|
39
|
-
|
46
|
+
### Proxy
|
40
47
|
A Proxy represents a connection to a remove Site or Supervisor and handles the RSMP interface.
|
41
48
|
|
42
49
|
A proxy has an async task listening for messages on an TCP/IP socket. Incoming RSMP messages are parsing and appropriate handles are called.
|
@@ -45,18 +52,14 @@ A proxy also has a repaating async timer task for handling watchdog and acknowle
|
|
45
52
|
|
46
53
|
Proxy has to child classes: SiteProxy and SupervisorProxy.
|
47
54
|
|
48
|
-
|
55
|
+
### SiteProxy
|
49
56
|
A connection to a remote Site.
|
50
57
|
|
51
58
|
Handles RSMP messaging specific to a supervisor, including methods for requesting status, sending commands, etc.
|
52
59
|
|
53
60
|
A SiteProxy has one or more components, representing the components in the remote site.
|
54
61
|
|
55
|
-
|
62
|
+
### SupervisorProxy
|
56
63
|
A connection to a remote Site. Handles RSMP messaging specific to a site, including sending aggregated status, handling status requests, status subscription and command requests.
|
57
64
|
|
58
65
|
Status and command requests are delegated to the appropriate components.
|
59
|
-
|
60
|
-
## SiteBase
|
61
|
-
Things shared between Site and SiteProxy, mainly handling components.
|
62
|
-
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Message distribution
|
2
|
+
|
3
|
+
Proxy - - Distributor --> Receivers
|
4
|
+
|
5
|
+
A proxy distributes message to receivers, when they are installed.
|
6
|
+
|
7
|
+
Probes are special receivers that waits for specific message, and are used to implement methods for waiting for RMSP responses, statuses, alarms, etc.
|
8
|
+
|
9
|
+
Note that Archive is not a receiver, and does not receive messages via the Distributor. Instead the Archive gets and stores messages via the log() interface in the Logging module. The reason is that the items that the Archive and the Logger contain other data as well as the message, like error messages, warnings, text descriptions, colors codes, etc. The Distributor and Receiver handles only Message objects.
|
10
|
+
|
11
|
+
## Distributor
|
12
|
+
A module that handles distributing messages to receivers.
|
13
|
+
|
14
|
+
## Receiver
|
15
|
+
Receives messages as long as it's installed into a distributor.
|
16
|
+
|
17
|
+
## Probe
|
18
|
+
A subclass of Receiver that wait for specific messages. Once received
|
19
|
+
the client receives the collection.
|
20
|
+
|
21
|
+
## Proxy
|
22
|
+
A proxy includes the Distributor module and distributes each message to listerens after processing it.
|
23
|
+
|
data/lib/rsmp.rb
CHANGED
@@ -10,21 +10,25 @@ require 'json_schemer'
|
|
10
10
|
require 'async/queue'
|
11
11
|
|
12
12
|
require 'rsmp/rsmp'
|
13
|
-
require 'rsmp/
|
13
|
+
require 'rsmp/logging'
|
14
14
|
require 'rsmp/wait'
|
15
|
-
require 'rsmp/version'
|
16
15
|
require 'rsmp/node'
|
17
16
|
require 'rsmp/supervisor'
|
17
|
+
require 'rsmp/components'
|
18
|
+
require 'rsmp/notifier'
|
19
|
+
|
20
|
+
require 'rsmp/listener'
|
21
|
+
require 'rsmp/collector'
|
18
22
|
require 'rsmp/component'
|
19
|
-
require 'rsmp/site_base'
|
20
23
|
require 'rsmp/site'
|
21
24
|
require 'rsmp/proxy'
|
22
25
|
require 'rsmp/supervisor_proxy'
|
26
|
+
require 'rsmp/site_proxy_wait'
|
23
27
|
require 'rsmp/site_proxy'
|
24
28
|
require 'rsmp/error'
|
25
|
-
require 'rsmp/probe'
|
26
|
-
require 'rsmp/probe_collection'
|
27
29
|
require 'rsmp/message'
|
28
30
|
require 'rsmp/logger'
|
29
31
|
require 'rsmp/archive'
|
30
32
|
require 'rsmp/tlc'
|
33
|
+
|
34
|
+
require 'rsmp/version'
|
data/lib/rsmp/archive.rb
CHANGED
@@ -4,13 +4,12 @@
|
|
4
4
|
module RSMP
|
5
5
|
class Archive
|
6
6
|
attr_reader :items
|
7
|
-
attr_accessor :probes
|
8
7
|
|
9
8
|
@@index = 0
|
10
9
|
|
11
|
-
def initialize
|
10
|
+
def initialize max=100
|
12
11
|
@items = []
|
13
|
-
@
|
12
|
+
@max = max
|
14
13
|
end
|
15
14
|
|
16
15
|
def self.prepare_item item
|
@@ -48,20 +47,13 @@ module RSMP
|
|
48
47
|
def add item
|
49
48
|
item[:index] = RSMP::Archive.increase_index
|
50
49
|
@items << item
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
def capture task, options, &block
|
55
|
-
probe = RSMP::Probe.new self
|
56
|
-
probe.capture task, options, &block
|
50
|
+
if @items.size > @max
|
51
|
+
@items.shift
|
52
|
+
end
|
57
53
|
end
|
58
54
|
|
59
55
|
private
|
60
56
|
|
61
|
-
def probe item
|
62
|
-
@probes.process item
|
63
|
-
end
|
64
|
-
|
65
57
|
def find options, &block
|
66
58
|
# search backwards from newest to older, stopping once messages
|
67
59
|
# are older that options[:earliest]
|
@@ -3,58 +3,46 @@
|
|
3
3
|
# and the client wakes up.
|
4
4
|
|
5
5
|
module RSMP
|
6
|
-
class
|
6
|
+
class Collector < Listener
|
7
7
|
attr_reader :condition, :items, :done
|
8
8
|
|
9
|
-
def initialize
|
10
|
-
raise ArgumentError.new("
|
11
|
-
|
9
|
+
def initialize proxy, options={}
|
10
|
+
#raise ArgumentError.new("timeout option is missing") unless options[:timeout]
|
11
|
+
super proxy, options
|
12
12
|
@items = []
|
13
13
|
@condition = Async::Notification.new
|
14
|
-
|
15
|
-
|
16
|
-
def capture task, options={}, &block
|
17
|
-
raise ArgumentError.new("timeout option is missing") unless options[:timeout]
|
14
|
+
@done = false
|
18
15
|
@options = options
|
19
|
-
@block = block
|
20
16
|
@num = options[:num]
|
17
|
+
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
backscan from
|
25
|
-
end
|
26
|
-
|
27
|
-
# if backscan didn't find enough items, then
|
28
|
-
# insert ourself as probe and sleep until enough items are captured
|
29
|
-
if @items.size < @num
|
30
|
-
begin
|
31
|
-
@archive.probes.add self
|
32
|
-
task.with_timeout(options[:timeout]) do
|
33
|
-
@condition.wait
|
34
|
-
end
|
35
|
-
ensure
|
36
|
-
@archive.probes.remove self
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
if @num == 1
|
41
|
-
@items.first # if one item was requested, return item instead of array
|
42
|
-
else
|
43
|
-
@items[0..@num-1] # return array, but ensure we never return more than requested
|
44
|
-
end
|
19
|
+
def wait
|
20
|
+
@condition.wait
|
45
21
|
end
|
46
22
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
@archive.items[i][:timestamp] >= earliest
|
23
|
+
def collect_for task, duration
|
24
|
+
siphon do
|
25
|
+
task.sleep duration
|
51
26
|
end
|
52
27
|
end
|
53
28
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
29
|
+
def collect task, options={}, &block
|
30
|
+
@num = options[:num] if options[:num]
|
31
|
+
@options[:timeout] = options[:timeout] if options[:timeout]
|
32
|
+
@block = block
|
33
|
+
|
34
|
+
siphon do
|
35
|
+
task.with_timeout(@options[:timeout]) do
|
36
|
+
@condition.wait
|
37
|
+
end
|
57
38
|
end
|
39
|
+
|
40
|
+
#if @num == 1
|
41
|
+
# @items = @items.first # if one item was requested, return item instead of array
|
42
|
+
#else
|
43
|
+
# @items = @items.first @num # return array, but ensure we never return more than requested
|
44
|
+
#end
|
45
|
+
#@items
|
58
46
|
end
|
59
47
|
|
60
48
|
def reset
|
@@ -62,18 +50,19 @@ module RSMP
|
|
62
50
|
@done = false
|
63
51
|
end
|
64
52
|
|
65
|
-
def
|
53
|
+
def notify item
|
66
54
|
raise ArgumentError unless item
|
67
55
|
return true if @done
|
56
|
+
return if item[:message].direction == :in && @ingoing == false
|
57
|
+
return if item[:message].direction == :out && @outgoing == false
|
68
58
|
if matches? item
|
69
59
|
@items << item
|
70
60
|
if @num && @items.size >= @num
|
71
61
|
@done = true
|
62
|
+
@proxy.remove_listener self
|
72
63
|
@condition.signal
|
73
|
-
return true
|
74
64
|
end
|
75
65
|
end
|
76
|
-
false
|
77
66
|
end
|
78
67
|
|
79
68
|
def matches? item
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Receives messages from a Notifier, as long as it's
|
2
|
+
# installed as a listener.
|
3
|
+
# Can listen for ingoing and/or outgoing messages.
|
4
|
+
|
5
|
+
module RSMP
|
6
|
+
class Listener
|
7
|
+
|
8
|
+
def initialize proxy, options={}
|
9
|
+
@proxy = proxy
|
10
|
+
@ingoing = options[:ingoing] == nil ? true : options[:ingoing]
|
11
|
+
@outgoing = options[:outgoing] == nil ? false : options[:outgoing]
|
12
|
+
end
|
13
|
+
|
14
|
+
def ingoing?
|
15
|
+
ingoing == true
|
16
|
+
end
|
17
|
+
|
18
|
+
def outgoing?
|
19
|
+
outgoing == true
|
20
|
+
end
|
21
|
+
|
22
|
+
def notify item
|
23
|
+
end
|
24
|
+
|
25
|
+
def siphon &block
|
26
|
+
@proxy.add_listener self
|
27
|
+
yield
|
28
|
+
ensure
|
29
|
+
@proxy.remove_listener self
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/lib/rsmp/logger.rb
CHANGED
@@ -82,7 +82,6 @@ module RSMP
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def colorize level, str
|
85
|
-
#p String.color_samples
|
86
85
|
if @settings["color"] == false || @settings["color"] == nil
|
87
86
|
str
|
88
87
|
elsif @settings["color"] == true
|
@@ -125,8 +124,9 @@ module RSMP
|
|
125
124
|
end
|
126
125
|
end
|
127
126
|
|
128
|
-
def dump archive, force:false
|
129
|
-
|
127
|
+
def dump archive, force:false, num:nil
|
128
|
+
num ||= archive.items.size
|
129
|
+
log = archive.items.last(num).map do |item|
|
130
130
|
str = build_output item
|
131
131
|
str = colorize item[:level], str
|
132
132
|
end
|
@@ -3,10 +3,10 @@
|
|
3
3
|
#
|
4
4
|
|
5
5
|
module RSMP
|
6
|
-
|
6
|
+
module Logging
|
7
7
|
attr_reader :archive, :logger
|
8
8
|
|
9
|
-
def
|
9
|
+
def initialize_logging options
|
10
10
|
@archive = options[:archive] || RSMP::Archive.new
|
11
11
|
@logger = options[:logger] || RSMP::Logger.new(options[:log_settings])
|
12
12
|
end
|
data/lib/rsmp/node.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Handles a single connection to a supervisor.
|
4
|
-
# We connect to the supervisor.
|
1
|
+
# Base class for sites and supervisors
|
5
2
|
|
6
3
|
module RSMP
|
7
|
-
class Node
|
4
|
+
class Node
|
5
|
+
include Logging
|
8
6
|
include Wait
|
9
7
|
|
10
8
|
attr_reader :archive, :logger, :task, :deferred
|
11
9
|
|
12
10
|
def initialize options
|
13
|
-
|
11
|
+
initialize_logging options
|
14
12
|
@task = options[:task]
|
15
13
|
@deferred = []
|
16
14
|
end
|