ara 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +45 -0
- data/VERSION +1 -1
- data/ara.gemspec +6 -2
- data/examples/ws-client.rb +5 -0
- data/examples/ws.rb +10 -0
- data/lib/ara.rb +2 -0
- data/lib/ara/actors.rb +17 -12
- data/lib/ara/remote.rb +45 -0
- data/lib/ara/remote_actor.rb +12 -0
- metadata +14 -10
data/README.rdoc
CHANGED
@@ -51,6 +51,51 @@ Because of akka[http://akka.io/] and my two parakeets ;)
|
|
51
51
|
sleep 1
|
52
52
|
end
|
53
53
|
|
54
|
+
=== Create remote actor
|
55
|
+
|
56
|
+
Server :
|
57
|
+
|
58
|
+
# Server
|
59
|
+
require 'ara'
|
60
|
+
|
61
|
+
class SimpleMessage < Actor
|
62
|
+
def receive(message)
|
63
|
+
reply "@ #{Time.now} : Hello #{message}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
Ara::Remote.server("localhost", 9292).register("simple_actor", Actors.actor_of(SimpleMessage)).start
|
68
|
+
|
69
|
+
Client :
|
70
|
+
|
71
|
+
# Client
|
72
|
+
require 'ara'
|
73
|
+
|
74
|
+
actor = Actors.actor_for("simple_actor", "localhost", 9292)
|
75
|
+
puts actor << "World"
|
76
|
+
|
77
|
+
=== Use scheduler
|
78
|
+
|
79
|
+
require 'ara'
|
80
|
+
|
81
|
+
class MySimpleActor < SimpleActor
|
82
|
+
def receive( message )
|
83
|
+
puts "Actor #{self} receive message : #{message}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
my_actor = Actors.actor_of(MySimpleActor).start
|
88
|
+
|
89
|
+
my_scheduler = Scheduler.schedule(my_actor, "Hello World! (every 1 second)", 1, 1, Scheduler::SECOND)
|
90
|
+
|
91
|
+
sleep 10
|
92
|
+
|
93
|
+
my_scheduler.shutdown
|
94
|
+
puts "-- Scheduler has been shutdown! We wait 5 second to be sure ;)"
|
95
|
+
|
96
|
+
sleep 5
|
97
|
+
|
98
|
+
my_actor.stop
|
54
99
|
|
55
100
|
== Changelog
|
56
101
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/ara.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ara}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gregoire Lejeune"]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-15}
|
13
13
|
s.description = %q{Ara is a tiny class that’s allow you to use actors in Ruby}
|
14
14
|
s.email = %q{gregoire.lejeune@free.fr}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -36,11 +36,15 @@ Gem::Specification.new do |s|
|
|
36
36
|
"examples/simple_scheduler.rb",
|
37
37
|
"examples/sync_actor.rb",
|
38
38
|
"examples/test_actor.rb",
|
39
|
+
"examples/ws-client.rb",
|
40
|
+
"examples/ws.rb",
|
39
41
|
"lib/ara.rb",
|
40
42
|
"lib/ara/actor.rb",
|
41
43
|
"lib/ara/actors.rb",
|
42
44
|
"lib/ara/exception.rb",
|
43
45
|
"lib/ara/logger.rb",
|
46
|
+
"lib/ara/remote.rb",
|
47
|
+
"lib/ara/remote_actor.rb",
|
44
48
|
"lib/ara/scheduler.rb",
|
45
49
|
"lib/ara/simple_actor.rb",
|
46
50
|
"lib/ext/binding_of_caller.rb",
|
data/examples/ws.rb
ADDED
data/lib/ara.rb
CHANGED
data/lib/ara/actors.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
|
+
require 'ara/remote_actor'
|
1
2
|
# Actors class
|
2
3
|
class Actors
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
# Create a new Actor with class klass
|
5
|
+
#
|
6
|
+
# class MyActor < Actor
|
7
|
+
# def receive(message)
|
8
|
+
# ...
|
9
|
+
# end
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# myActor = Actors.actor_of(MyActor)
|
13
|
+
def self.actor_of(klass)
|
14
|
+
return klass.new()
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.actor_for(route, host, port)
|
18
|
+
return RemoteActor.new(route, host, port)
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
data/lib/ara/remote.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rack'
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
class ActorMap
|
6
|
+
def initialize(actor)
|
7
|
+
@actor = actor.start
|
8
|
+
end
|
9
|
+
|
10
|
+
def call( env )
|
11
|
+
response = Rack::Response.new
|
12
|
+
request = Rack::Request.new(env)
|
13
|
+
message = request.params["message"]
|
14
|
+
response.write @actor << message
|
15
|
+
response.finish
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Ara
|
21
|
+
module Remote
|
22
|
+
def self.server(host, port)
|
23
|
+
return Server.new(host, port)
|
24
|
+
end
|
25
|
+
|
26
|
+
class Server
|
27
|
+
def initialize(host, port)
|
28
|
+
@host = host
|
29
|
+
@port = port
|
30
|
+
@routes = {}
|
31
|
+
end
|
32
|
+
|
33
|
+
def register(route, actor)
|
34
|
+
@routes["/#{route}"] = Rack::ActorMap.new(actor)
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def start
|
39
|
+
app = Rack::URLMap.new(@routes)
|
40
|
+
app = Rack::ContentLength.new(app)
|
41
|
+
Rack::Handler::WEBrick.run( app, {:Port => @port} )
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-07-
|
12
|
+
date: 2011-07-15 00:00:00.000000000 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: shoulda
|
17
|
-
requirement: &
|
17
|
+
requirement: &2153397620 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2153397620
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bundler
|
28
|
-
requirement: &
|
28
|
+
requirement: &2153396300 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2153396300
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: jeweler
|
39
|
-
requirement: &
|
39
|
+
requirement: &2153395040 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.6.2
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2153395040
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rcov
|
50
|
-
requirement: &
|
50
|
+
requirement: &2153393200 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2153393200
|
59
59
|
description: Ara is a tiny class that’s allow you to use actors in Ruby
|
60
60
|
email: gregoire.lejeune@free.fr
|
61
61
|
executables: []
|
@@ -83,11 +83,15 @@ files:
|
|
83
83
|
- examples/simple_scheduler.rb
|
84
84
|
- examples/sync_actor.rb
|
85
85
|
- examples/test_actor.rb
|
86
|
+
- examples/ws-client.rb
|
87
|
+
- examples/ws.rb
|
86
88
|
- lib/ara.rb
|
87
89
|
- lib/ara/actor.rb
|
88
90
|
- lib/ara/actors.rb
|
89
91
|
- lib/ara/exception.rb
|
90
92
|
- lib/ara/logger.rb
|
93
|
+
- lib/ara/remote.rb
|
94
|
+
- lib/ara/remote_actor.rb
|
91
95
|
- lib/ara/scheduler.rb
|
92
96
|
- lib/ara/simple_actor.rb
|
93
97
|
- lib/ext/binding_of_caller.rb
|