opee 0.0.1
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/LICENSE +27 -0
- data/README.md +49 -0
- data/lib/opee.rb +5 -0
- data/lib/opee/actor.rb +69 -0
- data/lib/opee/version.rb +5 -0
- data/test/tests.rb +40 -0
- metadata +54 -0
data/LICENSE
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Copyright (c) 2012, Peter Ohler
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
- Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
- Neither the name of Peter Ohler nor the names of its contributors may be
|
15
|
+
used to endorse or promote products derived from this software without
|
16
|
+
specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Opee gem
|
2
|
+
An experimental Object-base Parallel Evaluation Environment
|
3
|
+
|
4
|
+
The purpose of this gem is to explore setting up an environment that will run
|
5
|
+
completely in parallel with minimum use of mutex synchronization. Actors only
|
6
|
+
push the flow forward, never returning values when using the ask()
|
7
|
+
method. Other methods return immediately but they should never modify the data
|
8
|
+
portions of the Actors. They can be used to modify the control of the Actor.
|
9
|
+
|
10
|
+
# plans
|
11
|
+
|
12
|
+
- create an error handler that prints or logs rescued exceptions (::Opee::Log class)
|
13
|
+
|
14
|
+
- pick a problem to test against
|
15
|
+
|
16
|
+
- describe patterns for use
|
17
|
+
|
18
|
+
- Is the notion of a job needed to follow processing of an initial input?
|
19
|
+
- avoid using job for storing data though unless rules can be set up to isolate portions of the data to a specific processing path
|
20
|
+
|
21
|
+
### License:
|
22
|
+
|
23
|
+
Copyright (c) 2012, Peter Ohler
|
24
|
+
All rights reserved.
|
25
|
+
|
26
|
+
Redistribution and use in source and binary forms, with or without
|
27
|
+
modification, are permitted provided that the following conditions are met:
|
28
|
+
|
29
|
+
- Redistributions of source code must retain the above copyright notice, this
|
30
|
+
list of conditions and the following disclaimer.
|
31
|
+
|
32
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
33
|
+
this list of conditions and the following disclaimer in the documentation
|
34
|
+
and/or other materials provided with the distribution.
|
35
|
+
|
36
|
+
- Neither the name of Peter Ohler nor the names of its contributors may be
|
37
|
+
used to endorse or promote products derived from this software without
|
38
|
+
specific prior written permission.
|
39
|
+
|
40
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
41
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
43
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
44
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
45
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
46
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
47
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
48
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
49
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/lib/opee.rb
ADDED
data/lib/opee/actor.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
|
2
|
+
module Opee
|
3
|
+
|
4
|
+
class Actor
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@queue = []
|
8
|
+
@ask_mutex = Mutex.new()
|
9
|
+
@ask_timeout = 0.0
|
10
|
+
@max_queue_count = nil
|
11
|
+
@running = true
|
12
|
+
set_options(options)
|
13
|
+
@loop = Thread.start(self) do |me|
|
14
|
+
begin
|
15
|
+
sleep(1.0) if @queue.empty?
|
16
|
+
unless @queue.empty?
|
17
|
+
a = nil
|
18
|
+
@ask_mutex.synchronize {
|
19
|
+
a = @queue.pop()
|
20
|
+
}
|
21
|
+
send(a.op, *a.args)
|
22
|
+
end
|
23
|
+
rescue Exception => e
|
24
|
+
# TBD handle errors by passing them to a error handler
|
25
|
+
puts "*** #{e.class}: #{e.message}"
|
26
|
+
e.backtrace.each { |line| puts " " + line }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_options(options)
|
32
|
+
#
|
33
|
+
end
|
34
|
+
|
35
|
+
# deep copy and freeze args if not already frozen or primitive types
|
36
|
+
def ask(op, *args)
|
37
|
+
@ask_mutex.synchronize {
|
38
|
+
@queue << Act.new(op, args)
|
39
|
+
}
|
40
|
+
@loop.wakeup() if @running
|
41
|
+
end
|
42
|
+
|
43
|
+
def queue_count()
|
44
|
+
@queue.length
|
45
|
+
end
|
46
|
+
|
47
|
+
def stop()
|
48
|
+
@running = false
|
49
|
+
end
|
50
|
+
|
51
|
+
def start()
|
52
|
+
@running = true
|
53
|
+
@loop.wakeup()
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
class Act
|
59
|
+
attr_accessor :op
|
60
|
+
attr_accessor :args
|
61
|
+
|
62
|
+
def initialize(op, args)
|
63
|
+
@op = op
|
64
|
+
@args = args
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end # Actor
|
69
|
+
end # Opee
|
data/lib/opee/version.rb
ADDED
data/test/tests.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby -wW1
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
$: << File.join(File.dirname(__FILE__), "../lib")
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require 'opee'
|
8
|
+
|
9
|
+
class Relay < ::Opee::Actor
|
10
|
+
attr_reader :last_data
|
11
|
+
|
12
|
+
def initialize(buddy)
|
13
|
+
super
|
14
|
+
@buddy = buddy
|
15
|
+
@last_data = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def relay(data)
|
21
|
+
@last_data = data
|
22
|
+
@buddy.ask(:relay, data) unless @buddy.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
end # Relay
|
26
|
+
|
27
|
+
class Opeet < ::Test::Unit::TestCase
|
28
|
+
|
29
|
+
def test_ask_queue
|
30
|
+
a = ::Relay.new(nil)
|
31
|
+
assert_equal(0, a.queue_count())
|
32
|
+
a.stop()
|
33
|
+
a.ask(:relay, 7)
|
34
|
+
assert_equal(1, a.queue_count())
|
35
|
+
a.start()
|
36
|
+
sleep(0.2)
|
37
|
+
assert_equal(7, a.last_data)
|
38
|
+
end
|
39
|
+
|
40
|
+
end # Opeet
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opee
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Peter Ohler
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-17 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! 'An experimental Object-base Parallel Evaluation Environment. '
|
15
|
+
email: peter@ohler.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files:
|
19
|
+
- README.md
|
20
|
+
files:
|
21
|
+
- lib/opee/actor.rb
|
22
|
+
- lib/opee/version.rb
|
23
|
+
- lib/opee.rb
|
24
|
+
- test/tests.rb
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
homepage: http://www.ohler.com/opee
|
28
|
+
licenses: []
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options:
|
31
|
+
- --main
|
32
|
+
- README.md
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project: opee
|
49
|
+
rubygems_version: 1.8.21
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: An experimental Object-base Parallel Evaluation Environment.
|
53
|
+
test_files: []
|
54
|
+
has_rdoc: true
|