oml4r 2.9.pre.151.f020 → 2.9.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.
- data/README.md +30 -20
- data/lib/oml4r.rb +56 -20
- data/oml4r.gemspec +1 -0
- metadata +7 -6
data/README.md
CHANGED
|
@@ -1,44 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
OML4R: Native OML Implementation in Ruby {#oml4rdoc}
|
|
2
|
+
========================================
|
|
2
3
|
|
|
3
4
|
This is a simple client library for OML which does not use liboml2 and its
|
|
4
|
-
filters, but connects directly to the server using the text protocol.
|
|
5
|
+
filters, but connects directly to the server using the text protocol [oml-text].
|
|
5
6
|
User can use this library to create ruby applications which can send
|
|
6
7
|
measurement to the OML collection server. A simple example on how to use
|
|
7
8
|
this library is attached at the end of this file. Another example can be
|
|
8
9
|
found in the file oml4r-example.rb
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
Installation
|
|
12
|
+
------------
|
|
13
|
+
|
|
14
|
+
OML4R is available from RubyGems [oml4r-rubygem].
|
|
11
15
|
|
|
12
16
|
$ gem install oml4r
|
|
13
17
|
|
|
14
|
-
## Usage
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
Usage
|
|
20
|
+
-----
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
name :mymp
|
|
22
|
+
### Definition of a Measurement Point
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
class MyMP < OML4R::MPBase
|
|
25
|
+
name :mymp
|
|
26
|
+
|
|
27
|
+
param :mystring
|
|
28
|
+
param :myint, :type => :int32
|
|
29
|
+
param :mydouble, :type => :double
|
|
30
|
+
end
|
|
25
31
|
|
|
26
32
|
### Initialisation, Injection and Tear-down
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
OML4R::init(ARGV, {
|
|
35
|
+
:appName => 'oml4rSimpleExample',
|
|
36
|
+
:expID => 'foo',
|
|
37
|
+
:nodeID => 'n1',
|
|
38
|
+
:omlServer => 'file:-'}
|
|
39
|
+
)
|
|
40
|
+
MyMP.inject("hello", 13, 37.)
|
|
41
|
+
OML4R::close()
|
|
36
42
|
|
|
37
43
|
### Real example
|
|
38
44
|
|
|
39
45
|
See examples files oml4r-simple-example.rb and oml4r-wlanconfig.rb.
|
|
40
46
|
|
|
41
|
-
|
|
47
|
+
|
|
48
|
+
License
|
|
49
|
+
-------
|
|
42
50
|
|
|
43
51
|
Copyright 2009-2012 National ICT Australia (NICTA), Australia
|
|
44
52
|
|
|
@@ -60,3 +68,5 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
60
68
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
61
69
|
THE SOFTWARE.
|
|
62
70
|
|
|
71
|
+
[oml-text]: http://oml.mytestbed.net/projects/oml/wiki/Description_of_Text_protocol
|
|
72
|
+
[oml4r-rubygem]: https://rubygems.org/gems/oml4r/
|
data/lib/oml4r.rb
CHANGED
|
@@ -40,7 +40,7 @@ require 'optparse'
|
|
|
40
40
|
#
|
|
41
41
|
module OML4R
|
|
42
42
|
|
|
43
|
-
VERSION = "2.9.
|
|
43
|
+
VERSION = "2.9.0"
|
|
44
44
|
VERSION_STRING = "OML4R Client V#{VERSION}"
|
|
45
45
|
COPYRIGHT = "Copyright 2009-2012, NICTA"
|
|
46
46
|
DEF_SERVER_PORT = 3003
|
|
@@ -328,7 +328,11 @@ module OML4R
|
|
|
328
328
|
end
|
|
329
329
|
|
|
330
330
|
def self._create(key, domain, url)
|
|
331
|
-
|
|
331
|
+
out = _connect(url)
|
|
332
|
+
@@channels[key] = self.new(url, domain, out)
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def self._connect(url)
|
|
332
336
|
if url.start_with? 'file:'
|
|
333
337
|
proto, fname = url.split(':')
|
|
334
338
|
out = (fname == '-' ? $stdout : File.open(fname, "w+"))
|
|
@@ -340,8 +344,7 @@ module OML4R
|
|
|
340
344
|
else
|
|
341
345
|
raise "OML4R: Unknown transport in server url '#{url}'"
|
|
342
346
|
end
|
|
343
|
-
|
|
344
|
-
@@channels[key] = self.new(url, domain, out)
|
|
347
|
+
out
|
|
345
348
|
end
|
|
346
349
|
|
|
347
350
|
def self.[](name = :default, domain = :default)
|
|
@@ -371,9 +374,6 @@ module OML4R
|
|
|
371
374
|
klass.__print_meta__(appName)
|
|
372
375
|
end
|
|
373
376
|
|
|
374
|
-
# add empty line to separate header form MP channel
|
|
375
|
-
@@channels.values.each { |c| c.send "\n" }
|
|
376
|
-
|
|
377
377
|
MPBase.__useOML__()
|
|
378
378
|
end
|
|
379
379
|
|
|
@@ -393,7 +393,7 @@ module OML4R
|
|
|
393
393
|
line << "#{d[:name]}:#{d[:type]}"
|
|
394
394
|
end
|
|
395
395
|
msg = line.join(' ')
|
|
396
|
-
|
|
396
|
+
@header << msg
|
|
397
397
|
@index
|
|
398
398
|
end
|
|
399
399
|
|
|
@@ -416,26 +416,26 @@ module OML4R
|
|
|
416
416
|
@url = url
|
|
417
417
|
@out = out_channel
|
|
418
418
|
@index = 0
|
|
419
|
+
@header = []
|
|
420
|
+
@header_sent = false
|
|
419
421
|
@queue = Queue.new
|
|
420
422
|
start_runner
|
|
421
423
|
end
|
|
422
424
|
|
|
423
425
|
|
|
424
426
|
def send_protocol_header(nodeID, appName, startTime)
|
|
425
|
-
@
|
|
427
|
+
@header << "protocol: #{PROTOCOL}"
|
|
426
428
|
d = (@domain == :default) ? @@default_domain : @domain
|
|
427
429
|
raise "Missing domain name" unless d
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
@
|
|
432
|
-
@
|
|
433
|
-
@queue.push "sender-id: #{nodeID}"
|
|
434
|
-
@queue.push "app-name: #{appName}"
|
|
435
|
-
@queue.push "content: text"
|
|
430
|
+
@header << "experiment-id: #{d}"
|
|
431
|
+
@header << "start_time: #{startTime.tv_sec}"
|
|
432
|
+
@header << "sender-id: #{nodeID}"
|
|
433
|
+
@header << "app-name: #{appName}"
|
|
434
|
+
@header << "content: text"
|
|
436
435
|
end
|
|
437
436
|
|
|
438
437
|
def start_runner
|
|
438
|
+
header_sent = false
|
|
439
439
|
@runner = Thread.new do
|
|
440
440
|
active = true
|
|
441
441
|
begin
|
|
@@ -453,15 +453,51 @@ module OML4R
|
|
|
453
453
|
msg = ma.join("\n")
|
|
454
454
|
end
|
|
455
455
|
#$stderr.puts ">>>>>>#{@domain}: <#{msg}>"
|
|
456
|
-
|
|
457
|
-
|
|
456
|
+
unless msg.nil?
|
|
457
|
+
_send msg
|
|
458
|
+
end
|
|
458
459
|
end
|
|
460
|
+
puts ">> CLOSE"
|
|
459
461
|
@out.close
|
|
460
462
|
@out = nil
|
|
461
463
|
rescue Exception => ex
|
|
462
|
-
|
|
464
|
+
msg = "Exception while sending message to channel '#{@url}' (#{ex.class})"
|
|
463
465
|
Object.const_defined?(:MObject) ? MObject.warn(:oml4r, msg) : $stderr.puts("INFO #{msg}")
|
|
464
466
|
end
|
|
467
|
+
info "Channel #{url} closed"
|
|
468
|
+
end
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
def info(msg)
|
|
472
|
+
Object.const_defined?(:MObject) ? MObject.warn(:oml4r, msg) : $stderr.puts("INFO #{msg}")
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
def _send(msg)
|
|
476
|
+
begin
|
|
477
|
+
unless @header_sent
|
|
478
|
+
h = "#{@header.join("\n")}\n\n"
|
|
479
|
+
puts "'#{h}'"
|
|
480
|
+
@out.puts h
|
|
481
|
+
@header_sent = true
|
|
482
|
+
end
|
|
483
|
+
@out.puts msg
|
|
484
|
+
@out.flush
|
|
485
|
+
|
|
486
|
+
rescue Errno::EPIPE
|
|
487
|
+
# Trying to reconnect
|
|
488
|
+
info "Trying to reconnect to '#{@url}'"
|
|
489
|
+
loop do
|
|
490
|
+
sleep 5
|
|
491
|
+
begin
|
|
492
|
+
@out = self.class._connect(@url)
|
|
493
|
+
@header_sent = false
|
|
494
|
+
info "Reconnected to '#{@url}'"
|
|
495
|
+
return _send(msg)
|
|
496
|
+
rescue Errno::ECONNREFUSED => ex
|
|
497
|
+
info "Exception while reconnect '#{@url}' (#{ex.class})"
|
|
498
|
+
end
|
|
499
|
+
#Errno::ECONNREFUSED
|
|
500
|
+
end
|
|
465
501
|
end
|
|
466
502
|
end
|
|
467
503
|
|
data/oml4r.gemspec
CHANGED
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |gem|
|
|
|
25
25
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
26
26
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
27
27
|
gem.name = "oml4r"
|
|
28
|
+
gem.license = "MIT"
|
|
28
29
|
gem.require_paths = ["lib"]
|
|
29
30
|
gem.version = OML4R::VERSION
|
|
30
31
|
|
metadata
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: oml4r
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.9.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 2.9.0
|
|
5
|
+
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- NICTA
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-10
|
|
12
|
+
date: 2012-12-10 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: ! '["Simple OML client library for Ruby"]'
|
|
15
15
|
email:
|
|
@@ -28,7 +28,8 @@ files:
|
|
|
28
28
|
- lib/oml4r/oml4r-wlanconfig.rb
|
|
29
29
|
- oml4r.gemspec
|
|
30
30
|
homepage: http://oml.mytestbed.net
|
|
31
|
-
licenses:
|
|
31
|
+
licenses:
|
|
32
|
+
- MIT
|
|
32
33
|
post_install_message:
|
|
33
34
|
rdoc_options: []
|
|
34
35
|
require_paths:
|
|
@@ -42,9 +43,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
42
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
44
|
none: false
|
|
44
45
|
requirements:
|
|
45
|
-
- - ! '
|
|
46
|
+
- - ! '>='
|
|
46
47
|
- !ruby/object:Gem::Version
|
|
47
|
-
version:
|
|
48
|
+
version: '0'
|
|
48
49
|
requirements: []
|
|
49
50
|
rubyforge_project:
|
|
50
51
|
rubygems_version: 1.8.23
|