mikka 1.1.0-java → 1.1.1-java
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/.rvmrc +1 -1
- data/examples/remoting.rb +61 -7
- data/lib/mikka.rb +44 -25
- data/lib/mikka/version.rb +1 -1
- metadata +41 -62
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm --create use jruby-1.6.
|
1
|
+
rvm --create use jruby-1.6.5@mikka
|
data/examples/remoting.rb
CHANGED
@@ -1,16 +1,70 @@
|
|
1
1
|
$: << File.expand_path('../../lib', __FILE__)
|
2
2
|
|
3
|
+
# Run this with the argument 'server' to start a server, then run again
|
4
|
+
# without argument to run a client
|
5
|
+
|
3
6
|
require 'mikka'
|
4
7
|
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
SERVICE_NAME = 'translation-service'
|
10
|
+
SERVER_PORT = 1337
|
11
|
+
|
12
|
+
|
13
|
+
if ARGV.any? && ARGV.first == 'server'
|
14
|
+
# this is the server, it spawns the actor, starts a server and registers the
|
15
|
+
# actor with the server
|
16
|
+
|
17
|
+
class ServerActor < Mikka::Actor
|
18
|
+
TRANSLATIONS = {
|
19
|
+
'bonjour' => 'hello'
|
20
|
+
}
|
21
|
+
|
22
|
+
def receive(message)
|
23
|
+
context.reply_safe(TRANSLATIONS[message])
|
24
|
+
end
|
9
25
|
end
|
10
26
|
|
11
|
-
server
|
12
|
-
|
27
|
+
# start the server, the host can be specified with :host and defaults to
|
28
|
+
# localhost (the port defaults to 2552, but 1337 is cooler)
|
29
|
+
server = Mikka::Remote.start(:port => SERVER_PORT)
|
30
|
+
|
31
|
+
# create and register an actor with the server, this ID is used by the
|
32
|
+
# client to get a reference to the actor
|
33
|
+
server.register(SERVICE_NAME, Mikka.actor_of(ServerActor))
|
34
|
+
|
35
|
+
# now we're just waiting for messages
|
13
36
|
else
|
14
|
-
|
15
|
-
|
37
|
+
# this is the client code, it connects to the remote actor and sends it a message
|
38
|
+
|
39
|
+
class ClientActor < Mikka::Actor
|
40
|
+
def initialize(word)
|
41
|
+
super() # remember to use super with parentheses!
|
42
|
+
@word = word
|
43
|
+
end
|
44
|
+
|
45
|
+
def pre_start
|
46
|
+
# this gets an actor reference to the remote actor, you need to supply
|
47
|
+
# the ID the actor was registered with, and the host and port where it's
|
48
|
+
# running (these default to localhost and 2552)
|
49
|
+
@translation_actor = Mikka::Remote.actor_for(SERVICE_NAME, :port => SERVER_PORT)
|
50
|
+
@translation_actor << @word
|
51
|
+
end
|
52
|
+
|
53
|
+
def receive(message)
|
54
|
+
if message
|
55
|
+
puts "#{@word} means #{message}"
|
56
|
+
else
|
57
|
+
puts "#{@word} has no meaning"
|
58
|
+
end
|
59
|
+
context.exit
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# if you want to receive replies you need to start a server on the client
|
64
|
+
# side too, but you can use the no-args constructor to use the defaults
|
65
|
+
# (just don't use the defaults for both server and client)
|
66
|
+
Mikka::Remote.start
|
67
|
+
|
68
|
+
client = Mikka.actor_of { ClientActor.new('bonjour') }
|
69
|
+
client.start
|
16
70
|
end
|
data/lib/mikka.rb
CHANGED
@@ -34,14 +34,23 @@ module Mikka
|
|
34
34
|
end
|
35
35
|
|
36
36
|
module Remote
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
DEFAULT_HOST = 'localhost'
|
38
|
+
DEFAULT_PORT = 2552
|
39
|
+
|
40
|
+
def self.start(options=nil)
|
41
|
+
if options
|
42
|
+
then remote_support.start(options.fetch(:host, DEFAULT_HOST), options.fetch(:port, DEFAULT_PORT))
|
43
|
+
else remote_support.start
|
44
|
+
end
|
40
45
|
end
|
41
46
|
|
42
47
|
def self.actor_for(id, options={})
|
43
|
-
|
44
|
-
|
48
|
+
remote_support.actor_for(id, options.fetch(:host, DEFAULT_HOST), options.fetch(:port, DEFAULT_PORT))
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def self.remote_support
|
53
|
+
Akka::Actors.remote
|
45
54
|
end
|
46
55
|
end
|
47
56
|
|
@@ -60,26 +69,34 @@ module Mikka
|
|
60
69
|
end
|
61
70
|
|
62
71
|
module ImplicitSender
|
72
|
+
def onReceive(*args)
|
73
|
+
capture_current_actor { super }
|
74
|
+
end
|
75
|
+
|
76
|
+
def preStart(*args)
|
77
|
+
capture_current_actor { super }
|
78
|
+
end
|
79
|
+
|
80
|
+
def postStop(*args)
|
81
|
+
capture_current_actor { super }
|
82
|
+
end
|
83
|
+
|
84
|
+
def preRestart(*args)
|
85
|
+
capture_current_actor { super }
|
86
|
+
end
|
87
|
+
|
88
|
+
def postRestart(*args)
|
89
|
+
capture_current_actor { super }
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
63
94
|
def capture_current_actor
|
64
95
|
Thread.current[:mikka_current_actor] = context
|
65
96
|
yield
|
66
97
|
ensure
|
67
98
|
Thread.current[:mikka_current_actor] = nil
|
68
99
|
end
|
69
|
-
|
70
|
-
def self.included(mod)
|
71
|
-
mod.class_eval do
|
72
|
-
[:onReceive, :preStart, :postStop, :preRestart, :postRestart].each do |method_name|
|
73
|
-
actual_method_name = :"__actual_#{method_name}"
|
74
|
-
alias_method actual_method_name, method_name
|
75
|
-
define_method method_name do |*args|
|
76
|
-
capture_current_actor do
|
77
|
-
send(actual_method_name, *args)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
100
|
end
|
84
101
|
|
85
102
|
module SupervisionDsl
|
@@ -103,12 +120,14 @@ module Mikka
|
|
103
120
|
end
|
104
121
|
|
105
122
|
def life_cycle(type)
|
106
|
-
@life_cycle =
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
123
|
+
@life_cycle = begin
|
124
|
+
case type
|
125
|
+
when :permanent then Akka::Config::Supervision.permanent
|
126
|
+
when :temporary then Akka::Config::Supervision.temporary
|
127
|
+
when :undefined then Akka::Config::Supervision.undefined_life_cycle
|
128
|
+
else raise ArgumentError, 'type must be one of :permanent, :temporary or :undefined'
|
129
|
+
end
|
130
|
+
end
|
112
131
|
end
|
113
132
|
|
114
133
|
def registered_life_cycle
|
data/lib/mikka/version.rb
CHANGED
metadata
CHANGED
@@ -1,60 +1,45 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mikka
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
version: 1.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.1.1
|
10
6
|
platform: java
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Theo Hultberg
|
13
|
-
autorequire:
|
9
|
+
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-10-25 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: akka-actor-jars
|
22
|
-
|
23
|
-
|
24
|
-
requirements:
|
16
|
+
version_requirements: &2056 !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
25
18
|
- - ~>
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 2
|
30
|
-
- 0
|
19
|
+
- !ruby/object:Gem::Version
|
31
20
|
version: 1.2.0
|
21
|
+
none: false
|
22
|
+
requirement: *2056
|
23
|
+
prerelease: false
|
32
24
|
type: :runtime
|
33
|
-
|
34
|
-
- !ruby/object:Gem::Dependency
|
25
|
+
- !ruby/object:Gem::Dependency
|
35
26
|
name: akka-remote-jars
|
36
|
-
|
37
|
-
|
38
|
-
requirements:
|
27
|
+
version_requirements: &2074 !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
39
29
|
- - ~>
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 1
|
43
|
-
- 2
|
44
|
-
- 0
|
30
|
+
- !ruby/object:Gem::Version
|
45
31
|
version: 1.2.0
|
32
|
+
none: false
|
33
|
+
requirement: *2074
|
34
|
+
prerelease: false
|
46
35
|
type: :runtime
|
47
|
-
version_requirements: *id002
|
48
36
|
description: Mikka adapts Akka's Java API to fit better with Ruby
|
49
|
-
email:
|
37
|
+
email:
|
50
38
|
- theo@iconara.net
|
51
39
|
executables: []
|
52
|
-
|
53
40
|
extensions: []
|
54
|
-
|
55
41
|
extra_rdoc_files: []
|
56
|
-
|
57
|
-
files:
|
42
|
+
files:
|
58
43
|
- .gitignore
|
59
44
|
- .rvmrc
|
60
45
|
- Gemfile
|
@@ -71,35 +56,29 @@ files:
|
|
71
56
|
- lib/mikka.rb
|
72
57
|
- lib/mikka/version.rb
|
73
58
|
- mikka.gemspec
|
74
|
-
has_rdoc: true
|
75
59
|
homepage: http://github.com/iconara/mikka
|
76
60
|
licenses: []
|
77
|
-
|
78
|
-
post_install_message:
|
61
|
+
post_install_message:
|
79
62
|
rdoc_options: []
|
80
|
-
|
81
|
-
require_paths:
|
63
|
+
require_paths:
|
82
64
|
- lib
|
83
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
- 0
|
96
|
-
version: "0"
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
none: false
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
none: false
|
97
77
|
requirements: []
|
98
|
-
|
99
78
|
rubyforge_project: mikka
|
100
|
-
rubygems_version: 1.
|
101
|
-
signing_key:
|
79
|
+
rubygems_version: 1.8.9
|
80
|
+
signing_key:
|
102
81
|
specification_version: 3
|
103
82
|
summary: Mikka is a JRuby wrapper for Akka
|
104
83
|
test_files: []
|
105
|
-
|
84
|
+
...
|