pcp-client 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pcp/client.rb +17 -1
- data/lib/pcp/simple_logger.rb +25 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 404c05c867f92b146e2f9d046fe2d8741bf38402
|
4
|
+
data.tar.gz: 6dcb82793a413080b7230d34228d6aab9ae70845
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d06217562d449a04f11c904d2cb0179a6bdbabe1458a48bc494f20fc38e7f29246bcfdb4d2173b99f1a1592d4a586d16b50cd638db7334523060f405110e646d
|
7
|
+
data.tar.gz: 7b4d892e27a3271e312b326a660d64a406127963b1f52356158ff17ca0f3e821f17dd22ef74351f4576354c86c8b059745b5150419d450c7b1175da004edd2b9
|
data/lib/pcp/client.rb
CHANGED
@@ -27,7 +27,7 @@ module PCP
|
|
27
27
|
@server = params[:server] || 'wss://localhost:8142/pcp'
|
28
28
|
@ssl_key = params[:ssl_key]
|
29
29
|
@ssl_cert = params[:ssl_cert]
|
30
|
-
@logger = Logger.new(STDOUT)
|
30
|
+
@logger = params[:logger] || Logger.new(STDOUT)
|
31
31
|
@logger.level = params[:loglevel] || Logger::WARN
|
32
32
|
@connection = nil
|
33
33
|
type = params[:type] || "ruby-pcp-client-#{$$}"
|
@@ -42,6 +42,22 @@ module PCP
|
|
42
42
|
# @param seconds [Numeric]
|
43
43
|
# @return [true,false,nil]
|
44
44
|
def connect(seconds = 0)
|
45
|
+
unless EM.reactor_running?
|
46
|
+
raise "An Eventmachine reactor needs to be running"
|
47
|
+
end
|
48
|
+
|
49
|
+
if EM.reactor_thread?
|
50
|
+
# Because we use a condition variable to signal this thread
|
51
|
+
# from the reactor thread to provide an imperative interface,
|
52
|
+
# they cannot be the same thread
|
53
|
+
raise "Cannot be run on the same thread as the reactor"
|
54
|
+
end
|
55
|
+
|
56
|
+
if @connection
|
57
|
+
# We close over so much, we really just need to say no for now
|
58
|
+
raise "Can only connect once per client"
|
59
|
+
end
|
60
|
+
|
45
61
|
mutex = Mutex.new
|
46
62
|
associated_cv = ConditionVariable.new
|
47
63
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
# This logger just adds events to the @events property, so when you
|
4
|
+
# .inspect it you can see what was logged.
|
5
|
+
module PCP
|
6
|
+
class SimpleLogger < ::Logger
|
7
|
+
def initialize(*args)
|
8
|
+
@events = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def add(severity, message = nil, progname = nil)
|
12
|
+
if message.nil?
|
13
|
+
if block_given?
|
14
|
+
message = yield
|
15
|
+
else
|
16
|
+
message = progname
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
@events << {:when => Time.now.to_f,
|
21
|
+
:severity => severity,
|
22
|
+
:message => message}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pcp-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet Labs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine-le
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/pcp/client.rb
|
63
63
|
- lib/pcp/message.rb
|
64
64
|
- lib/pcp/protocol.rb
|
65
|
+
- lib/pcp/simple_logger.rb
|
65
66
|
homepage: https://github.com/puppetlabs/ruby-pcp-client
|
66
67
|
licenses:
|
67
68
|
- ASL 2.0
|