Permalink
Browse files

Rename JRuby's Cache backend implementation.

  • Loading branch information...
1 parent 4b6c4e3 commit 35ba867f011a85aa2a624505d0c1bd1bc7cd07f9 @thedarkone thedarkone committed Aug 15, 2012
View
@@ -10,7 +10,7 @@ _yardoc
coverage
doc/
lib/bundler/man
-lib/thread_safe/concurrent_cache_backend.jar
+lib/thread_safe/jruby_cache_backend.jar
pkg
rdoc
spec/reports
View
@@ -17,7 +17,7 @@ if defined?(JRUBY_VERSION)
desc "Clean up build artifacts"
task :clean do
rm_rf "pkg/classes"
- rm_rf "lib/thread_safe/concurrent_cache_backend.jar"
+ rm_rf "lib/thread_safe/jruby_cache_backend.jar"
end
desc "Compile the extension"
@@ -29,7 +29,7 @@ if defined?(JRUBY_VERSION)
desc "Build the jar"
task :jar => :compile do
- ant.jar :basedir => "pkg/classes", :destfile => "lib/thread_safe/concurrent_cache_backend.jar", :includes => "**/*.class"
+ ant.jar :basedir => "pkg/classes", :destfile => "lib/thread_safe/jruby_cache_backend.jar", :includes => "**/*.class"
end
task :package => :jar
@@ -12,38 +12,36 @@
import java.io.IOException;
import java.util.Map;
-import static org.jruby.CompatVersion.RUBY1_8;
-import static org.jruby.CompatVersion.RUBY1_9;
import static org.jruby.runtime.Visibility.PRIVATE;
/**
* Native Java implementation to avoid the JI overhead.
*
* @author thedarkone
*/
-public class ConcurrentCacheBackendLibrary implements Library {
+public class JRubyCacheBackendLibrary implements Library {
public void load(Ruby runtime, boolean wrap) throws IOException {
- RubyClass jrubyRefClass = runtime.defineClassUnder("ConcurrentCacheBackend", runtime.getObject(), BACKEND_ALLOCATOR, runtime.getModule("ThreadSafe"));
+ RubyClass jrubyRefClass = runtime.defineClassUnder("JRubyCacheBackend", runtime.getObject(), BACKEND_ALLOCATOR, runtime.getModule("ThreadSafe"));
jrubyRefClass.setAllocator(BACKEND_ALLOCATOR);
- jrubyRefClass.defineAnnotatedMethods(ConcurrentCacheBackend.class);
+ jrubyRefClass.defineAnnotatedMethods(JRubyCacheBackend.class);
}
private static final ObjectAllocator BACKEND_ALLOCATOR = new ObjectAllocator() {
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
- return new ConcurrentCacheBackend(runtime, klazz);
+ return new JRubyCacheBackend(runtime, klazz);
}
};
- @JRubyClass(name="ConcurrentCacheBackend", parent="Object")
- public static class ConcurrentCacheBackend extends RubyObject {
+ @JRubyClass(name="JRubyCacheBackend", parent="Object")
+ public static class JRubyCacheBackend extends RubyObject {
// Defaults used by the CHM
static final int DEFAULT_INITIAL_CAPACITY = 16;
static final float DEFAULT_LOAD_FACTOR = 0.75f;
static final int DEFAULT_CONCURRENCY_LEVEL = 16;
private ComputableConcurrentHashMap<IRubyObject, IRubyObject> map;
- public ConcurrentCacheBackend(Ruby runtime, RubyClass klass) {
+ public JRubyCacheBackend(Ruby runtime, RubyClass klass) {
super(runtime, klass);
}
@@ -144,7 +142,7 @@ public IRubyObject each_pair(ThreadContext context, Block block) {
}
@JRubyMethod(visibility = PRIVATE)
- public ConcurrentCacheBackend initialize_copy(ThreadContext context, IRubyObject other) {
+ public JRubyCacheBackend initialize_copy(ThreadContext context, IRubyObject other) {
this.map = new ComputableConcurrentHashMap<IRubyObject, IRubyObject>();
return this;
}
@@ -1,14 +0,0 @@
-package thread_safe;
-
-import java.io.IOException;
-
-import org.jruby.Ruby;
-import org.jruby.ext.thread_safe.ConcurrentCacheBackendLibrary;
-import org.jruby.runtime.load.BasicLibraryService;
-
-public class ConcurrentCacheBackendService implements BasicLibraryService {
- public boolean basicLoad(final Ruby runtime) throws IOException {
- new ConcurrentCacheBackendLibrary().load(runtime, false);
- return true;
- }
-}
@@ -0,0 +1,15 @@
+package thread_safe;
+
+import java.io.IOException;
+
+import org.jruby.Ruby;
+import org.jruby.ext.thread_safe.JRubyCacheBackendLibrary;
+import org.jruby.runtime.load.BasicLibraryService;
+
+// can't name this JRubyCacheBackendService or else JRuby doesn't pick this up
+public class JrubyCacheBackendService implements BasicLibraryService {
+ public boolean basicLoad(final Ruby runtime) throws IOException {
+ new JRubyCacheBackendLibrary().load(runtime, false);
+ return true;
+ }
+}
View
@@ -1,24 +1,19 @@
require 'thread'
module ThreadSafe
- autoload :ConcurrentCacheBackend, 'thread_safe/concurrent_cache_backend'
+ autoload :JRubyCacheBackend, 'thread_safe/jruby_cache_backend'
autoload :MriCacheBackend, 'thread_safe/mri_cache_backend'
autoload :NonConcurrentCacheBackend, 'thread_safe/non_concurrent_cache_backend'
autoload :SynchronizedCacheBackend, 'thread_safe/synchronized_cache_backend'
- begin
- concurrent_cache_backend = ConcurrentCacheBackend # trigger autoload
- rescue LoadError
- end
-
- unless concurrent_cache_backend
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby'
- ConcurrentCacheBackend = MriCacheBackend
+ ConcurrentCacheBackend =
+ case defined?(RUBY_ENGINE) && RUBY_ENGINE
+ when 'jruby'; JRubyCacheBackend
+ when 'ruby'; MriCacheBackend
else
warn 'ThreadSafe: unsupported Ruby engine, using a fully synchronized ThreadSafe::Cache implementation' if $VERBOSE
- ConcurrentCacheBackend = SynchronizedCacheBackend
+ SynchronizedCacheBackend
end
- end
class Cache < ConcurrentCacheBackend
def initialize(options = nil, &block)

0 comments on commit 35ba867

Please sign in to comment.