legion 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4b0225245d1e96a8c1a1c67525ccbc4c016c108
4
- data.tar.gz: 2d9a10ccffecd74598e2608fa97c45f191aa01ca
3
+ metadata.gz: f42434869f3fbd249e20f433fe13964d00157a4b
4
+ data.tar.gz: 462d1c607be4627681952c9968d2b9f6bf06f615
5
5
  SHA512:
6
- metadata.gz: c637b4f433b0f0081f5158d014ab80986576d8375ef748fd3e3b0d35508d504b990629ce267ab5aa04b78396c1d567233ff5134f309284b71b849f91b856fabc
7
- data.tar.gz: 72168bc261d81feded3b4fa9b1d4b501747e255cd2ae3762ccca0a9541a4b164a910c273b94ff3d0cfabdcb7aab8885e676006c69525a43e9e3e1af2135a13b4
6
+ metadata.gz: 6855d708d2fd03e7fc7ae3a301154e7efdd6fbafbb5b1796403c44e84ef3b06798c7b9c6727bdf7233b09b2f8c58018f750157ac08a47ce5bc10968d19cbff54
7
+ data.tar.gz: 21c09d6e2c68a8f0322fe3ffdbf7e7b5f597221f99b0c355f38acfba405e4cf5df45ce9f32f5d72d01cb978449ec9451c1d56d548607c41b8d1c3dc4b4450fd5
@@ -6,8 +6,6 @@ module Legion
6
6
  class Object
7
7
  include MonitorMixin
8
8
 
9
- attr_reader :pid, :uri
10
-
11
9
  class << self
12
10
  def method_added(name)
13
11
  return if name =~ /_async\z/i
@@ -31,6 +29,8 @@ module Legion
31
29
  end
32
30
  end
33
31
 
32
+ attr_reader :pid, :uri
33
+
34
34
  def ok?
35
35
  true
36
36
  end
@@ -5,23 +5,25 @@ module Legion
5
5
  attr_reader(
6
6
  :klass,
7
7
  :processes,
8
+ :port,
8
9
  :local_instances,
9
10
  :remote_instances
10
11
  )
11
12
 
12
- def initialize(klass, processes: 1)
13
+ def initialize(klass, processes: 1, port: 42042)
13
14
  @klass = klass
14
15
  @processes = processes
16
+ @port = port
15
17
  @local_instances = []
16
18
  @remote_instances = []
17
19
  end
18
20
 
19
- def start_remote_instances(port: nil)
21
+ def start
20
22
  DRb.start_service
21
23
  (1..processes).each do |i|
22
24
  local_instance = klass.new
23
25
  local_instance.start_remote_instance(port: port)
24
- port += 1
26
+ @port += 1
25
27
  local_instances << local_instance
26
28
  remote_instance = DRbObject.new_with_uri(local_instance.uri)
27
29
  verify_remote_instance(remote_instance)
@@ -29,22 +31,29 @@ module Legion
29
31
  end
30
32
  end
31
33
 
32
- def stop_remote_instances
33
- remote_instances.each do |remote_instance|
34
- remote_instance.exit rescue nil
35
- end
34
+ def stop
35
+ remote_instances.each { |inst| inst.exit }
36
36
  DRb.stop_service
37
37
  end
38
38
 
39
39
  def get_remote_instance
40
- @remote_instance_index ||= 0
41
- remote_instance = remote_instances[@remote_instance_index]
40
+ @index ||= 0
41
+ remote_instance = remote_instances[@index]
42
42
  sleep 0.01 while remote_instance.busy?
43
- @remote_instance_index += 1
44
- @remote_instance_index = 0 if @remote_instance_index >= remote_instances.length
43
+ @index += 1
44
+ @index = 0 if @index >= remote_instances.length
45
45
  remote_instance
46
46
  end
47
47
 
48
+ def method_missing(name, *args)
49
+ get_remote_instance.send("#{name}_async", *args)
50
+ end
51
+
52
+ def respond_to?(name)
53
+ return true if super
54
+ klass.instance_methods.include? name.to_sym
55
+ end
56
+
48
57
  protected
49
58
 
50
59
  def verify_remote_instance(remote_instance)
@@ -1,3 +1,3 @@
1
1
  module Legion
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,28 +1,19 @@
1
1
  require_relative "../lib/legion"
2
2
 
3
3
  class Example < Legion::Object
4
+ before(:work) { puts "before work" }
4
5
 
5
6
  def work(index)
7
+ puts "working on: #{index}"
6
8
  sleep 2
7
9
  end
8
-
9
- before :work do
10
- puts "before work"
11
- end
12
-
13
10
  end
14
11
 
15
12
  def run_example
16
- supervisor = Legion::Supervisor.new(Example, processes: 7)
17
- supervisor.start_remote_instances(port: 42042)
18
-
19
- 1000.times do |i|
20
- worker = supervisor.get_remote_instance
21
- worker.work_async(i)
22
- puts i
23
- end
24
-
25
- supervisor.stop_remote_instances
13
+ supervisor = Legion::Supervisor.new(Example, processes: 7, port: 52042)
14
+ supervisor.start
15
+ 1000.times { |i| supervisor.work(i) }
16
+ supervisor.stop
26
17
  end
27
18
 
28
19
  run_example
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: True concurrent processing power made easy... even for MRI.
41
+ description: Concurrent processing made easy... even for MRI.
42
42
  email:
43
43
  - natehop@gmail.com
44
44
  executables: []
@@ -73,7 +73,7 @@ rubyforge_project:
73
73
  rubygems_version: 2.0.3
74
74
  signing_key:
75
75
  specification_version: 4
76
- summary: True concurrent processing power made easy... even for MRI.
76
+ summary: Concurrent processing made easy... even for MRI.
77
77
  test_files:
78
78
  - test/example.rb
79
79
  has_rdoc: