jruby_bridge 0.0.1 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5367f5e9bf3e3c2bedc9a87cf8a4aca9689a2b8a
4
- data.tar.gz: 9180d4e1e93394da2f89b0b3425b1fe0c6ee412a
3
+ metadata.gz: f9beee728f6a583e04f6f653479da6e7bec39038
4
+ data.tar.gz: 219edc056495a588e65b91a59e0b787810856d4d
5
5
  SHA512:
6
- metadata.gz: efa6be4f5888e1ab81e64c28820a732aed2a72636b760107b76dd49ea63fe7015ff5378c304d6384b519be0799d467b1f813528d88bf5f2e56619aeee6f7530b
7
- data.tar.gz: 42e0731d46a569210842806b83b569921facd185109ed123aa5488e83ac5d985dfe15b2f58a6191226e057f7e3e3b39ae264f7f62725f1723b11cf9cf72fe8f9
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
- def self.new(*args)
16
- service = Service.new_drb_object
17
- service.proxy_new(self, *args)
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
- end
20
- end
22
+
23
+ end # base.class_eval
24
+ end # self.included
21
25
 
22
26
  end
23
27
  end
@@ -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
- def proxy_new(klass, *args)
26
- klass.new *args
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 stop
30
- DRb.stop_service
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
- cls = self
41
+ _self = self
43
42
  @pid = Process.fork do
44
- exit(cls.exec PORT)
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
- service_send :stop
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
- command = "#{jruby} #{DAEMON} #{port || ''}"
71
- puts "Running #{command}"
72
- Kernel.exec command if jruby
73
-
74
- # Note: a raised exception goes nowhere: instead use exit status
75
- $stderr.puts "No JRUBY found!"
76
- return 1
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
- cls = self
86
- trap('HUP') { DRb.stop_service; cls.drb_start(port) }
87
- trap('INT') { puts 'Stopping jruby service'; DRb.stop_service }
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
 
@@ -1,3 +1,3 @@
1
1
  module JrubyBridge
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
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.1
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-14 00:00:00.000000000 Z
12
+ date: 2013-06-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler