jruby_bridge 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/jruby_bridge/object_proxy.rb +9 -5
- data/lib/jruby_bridge/service.rb +31 -31
- data/lib/jruby_bridge/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9beee728f6a583e04f6f653479da6e7bec39038
|
4
|
+
data.tar.gz: 219edc056495a588e65b91a59e0b787810856d4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3769be6dd75a0457b1d9aedbbe6fb18df18cb1561d835cd4b3c124ef0a3c6150e08305915d32ed38ba7d0f57a9a657cccdeb05714ae4c201b801b0b1edc3ef97
|
7
|
+
data.tar.gz: a01669962d0f067a3adb79445cda681af241ba7cb9a9bcf1d74e312f23de1d9573442cd8d83861715581b07cedcd8669eddd05d37dea9e16907ee52c54a6cb57
|
data/README.md
CHANGED
@@ -28,6 +28,17 @@ Then pat a kitten :tiger:
|
|
28
28
|
```ruby
|
29
29
|
require 'jruby_bridge'
|
30
30
|
|
31
|
+
# Make sure JRuby has the right classes loaded
|
32
|
+
JRubyBridge::Service.remote_require 'kittens', 'puppies'
|
33
|
+
|
34
|
+
# Or, if you've got a Rails stack you want loaded, you could use the
|
35
|
+
# following code in an initializer to make sure JRuby has access to all
|
36
|
+
# your classes.
|
37
|
+
#
|
38
|
+
# # config/initializers/jruby_bridge.rb
|
39
|
+
# JRubyBridge::Service.remote_require File.dirname(__FILE__) + '/../environment'
|
40
|
+
|
41
|
+
|
31
42
|
# Start the JRuby service process
|
32
43
|
JRubyBridge::Service.with_service do
|
33
44
|
|
@@ -10,14 +10,18 @@ new instances to reside on the JRuby DRb service.
|
|
10
10
|
|
11
11
|
def self.included(base)
|
12
12
|
base.class_eval do
|
13
|
+
|
13
14
|
include DRb::DRbUndumped
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
class << self
|
17
|
+
alias :proxied_new :new
|
18
|
+
def new(*args)
|
19
|
+
Service.new_drb_object.remote_proxied_new self, *args
|
20
|
+
end
|
18
21
|
end
|
19
|
-
|
20
|
-
|
22
|
+
|
23
|
+
end # base.class_eval
|
24
|
+
end # self.included
|
21
25
|
|
22
26
|
end
|
23
27
|
end
|
data/lib/jruby_bridge/service.rb
CHANGED
@@ -8,9 +8,6 @@ DRuby to communicate between them.
|
|
8
8
|
=end
|
9
9
|
module JRubyBridge
|
10
10
|
|
11
|
-
class JRubyExecError < StandardError; end
|
12
|
-
class DRbConnectionError < StandardError; end
|
13
|
-
|
14
11
|
=begin rdoc
|
15
12
|
A Ruby-managed JRuby application.
|
16
13
|
=end
|
@@ -22,12 +19,14 @@ A Ruby-managed JRuby application.
|
|
22
19
|
# Time to allow JRuby to initialize, in 100-ms increments
|
23
20
|
TIMEOUT = 300
|
24
21
|
|
25
|
-
|
26
|
-
|
22
|
+
# Objects created from within this instance
|
23
|
+
# reside in the JRuby process
|
24
|
+
def remote_proxied_new(klass, *args)
|
25
|
+
klass.proxied_new *args
|
27
26
|
end
|
28
27
|
|
29
|
-
def
|
30
|
-
|
28
|
+
def self.remote_require(*args)
|
29
|
+
@remote_requires = args
|
31
30
|
end
|
32
31
|
|
33
32
|
def self.with_service(&block)
|
@@ -39,9 +38,9 @@ A Ruby-managed JRuby application.
|
|
39
38
|
|
40
39
|
def self.start
|
41
40
|
return @pid if @pid
|
42
|
-
|
41
|
+
_self = self
|
43
42
|
@pid = Process.fork do
|
44
|
-
exit
|
43
|
+
exit _self.exec(PORT)
|
45
44
|
end
|
46
45
|
# TODO : check child exit status and raise JRubyExecError
|
47
46
|
Process.detach(@pid)
|
@@ -61,19 +60,29 @@ A Ruby-managed JRuby application.
|
|
61
60
|
end
|
62
61
|
|
63
62
|
def self.stop
|
64
|
-
|
63
|
+
new_drb_object.stop
|
64
|
+
end
|
65
|
+
|
66
|
+
def stop
|
67
|
+
DRb.stop_service
|
65
68
|
end
|
66
69
|
|
67
70
|
# Replace current process with JRuby running JRubyBridge::Service
|
68
71
|
def self.exec(port)
|
69
|
-
jruby = get_jruby
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
unless jruby = get_jruby
|
73
|
+
# Note: a raised exception goes nowhere: instead use exit status
|
74
|
+
$stderr.puts "No JRuby found!"
|
75
|
+
return 1
|
76
|
+
end
|
77
|
+
|
78
|
+
command = [
|
79
|
+
jruby,
|
80
|
+
@remote_requires.map { |path| %Q(-r"#{path}") },
|
81
|
+
DAEMON,
|
82
|
+
port
|
83
|
+
].compact.join(' ')
|
84
|
+
|
85
|
+
Kernel.exec command
|
77
86
|
end
|
78
87
|
|
79
88
|
# Called by the server script in JRuby context
|
@@ -82,9 +91,9 @@ A Ruby-managed JRuby application.
|
|
82
91
|
|
83
92
|
DRb.start_service "druby://localhost:#{port.to_i}", self.new
|
84
93
|
|
85
|
-
|
86
|
-
trap('HUP') { DRb.stop_service;
|
87
|
-
trap('INT') {
|
94
|
+
_self = self
|
95
|
+
trap('HUP') { DRb.stop_service; _self.drb_start(port) }
|
96
|
+
trap('INT') { DRb.stop_service }
|
88
97
|
|
89
98
|
DRb.thread.join
|
90
99
|
end
|
@@ -109,17 +118,8 @@ A Ruby-managed JRuby application.
|
|
109
118
|
"rvm #{jruby.strip.split(' ').first} do ruby "
|
110
119
|
end
|
111
120
|
|
112
|
-
# this will return a new DRuby connection
|
113
|
-
def self.service_send(method, *args)
|
114
|
-
begin
|
115
|
-
new_drb_object.tap { |obj| obj.send(method, *args) }
|
116
|
-
rescue DRb::DRbConnError => e
|
117
|
-
# $stderr.puts e.backtrace.join("\n")
|
118
|
-
raise DRbConnectionError.new(e.message)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
121
|
def self.new_drb_object
|
122
|
+
# This returns a proxied instance of Service
|
123
123
|
DRb::DRbObject.new_with_uri(default_uri)
|
124
124
|
end
|
125
125
|
|
data/lib/jruby_bridge/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jruby_bridge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mkfs
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|