public class LoadService
extends java.lang.Object
First, decide on what name should be used to require the extension. In this purely hypothetical example, this name will be 'active_record/connection_adapters/jdbc_adapter'. Then create the class name for this require-name, by looking at the guidelines above. Our class should be named active_record.connection_adapters.JdbcAdapterService, and implement one of the library-interfaces. The easiest one is BasicLibraryService, where you define the basicLoad-method, which will get called when your library should be loaded.
The next step is to either put your compiled class on JRuby's classpath, or package the class/es inside a jar-file. To package into a jar-file, we first create the file, then rename it to jdbc_adapter.jar. Then we put this jar-file in the directory active_record/connection_adapters somewhere in JRuby's load path. For example, copying jdbc_adapter.jar into JRUBY_HOME/lib/ruby/site_ruby/1.8/active_record/connection_adapters will make everything work. If you've packaged your extension inside a RubyGem, write a setub.rb-script that copies the jar-file to this place.
If you don't want to have the name of your extension-class to be prescribed, you can also put a file called
jruby-ext.properties in your jar-files META-INF directory, where you can use the key
Modifier and Type | Class and Description |
---|---|
static class |
LoadService.AlreadyLoaded |
class |
LoadService.BailoutSearcher |
class |
LoadService.ClassLoaderSearcher |
class |
LoadService.ExtensionSearcher |
static interface |
LoadService.LoadSearcher |
class |
LoadService.NormalSearcher |
class |
LoadService.ScriptClassSearcher |
static class |
LoadService.SearchState |
class |
LoadService.SourceBailoutSearcher |
static class |
LoadService.SuffixType |
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,IAutoloadMethod> |
autoloadMap |
protected java.util.Map<java.lang.String,Library> |
builtinLibraries |
protected boolean |
caseInsensitiveFS |
protected static java.util.regex.Pattern |
extensionPattern |
protected java.util.Map<java.lang.String,java.util.jar.JarFile> |
jarFiles |
protected RubyArray |
loadedFeatures |
protected java.util.List |
loadedFeaturesInternal |
protected RubyArray |
loadPath |
protected java.util.Map |
requireLocks |
protected Ruby |
runtime |
protected java.util.List<LoadService.LoadSearcher> |
searchers |
protected static java.util.regex.Pattern |
sourcePattern |
Constructor and Description |
---|
LoadService(Ruby runtime) |
Modifier and Type | Method and Description |
---|---|
void |
addAutoload(java.lang.String name,
IAutoloadMethod loadMethod) |
void |
addBuiltinLibrary(java.lang.String name,
Library library) |
protected void |
addLoadedFeature(RubyString loadNameRubyString) |
protected void |
addPath(java.lang.String path) |
IRubyObject |
autoload(java.lang.String name) |
IAutoloadMethod |
autoloadFor(java.lang.String name) |
protected java.lang.String |
buildClassName(java.lang.String className) |
protected void |
checkEmptyLoad(java.lang.String file) |
protected Library |
createLibrary(LoadService.SearchState state,
LoadServiceResource resource) |
protected void |
debugLogFound(LoadServiceResource resource) |
protected void |
debugLogFound(java.lang.String what,
java.lang.String msg) |
protected void |
debugLogTry(java.lang.String what,
java.lang.String msg) |
protected boolean |
featureAlreadyLoaded(RubyString loadNameRubyString) |
protected Library |
findBuiltinLibrary(LoadService.SearchState state,
java.lang.String baseName,
LoadService.SuffixType suffixType) |
LoadService.SearchState |
findFileForLoad(java.lang.String file) |
protected LoadServiceResource |
findFileInClasspath(java.lang.String name)
this method uses the appropriate lookup strategy to find a file.
|
protected Library |
findLibraryWithClassloaders(LoadService.SearchState state,
java.lang.String baseName,
LoadService.SuffixType suffixType) |
protected Library |
findLibraryWithoutCWD(LoadService.SearchState state,
java.lang.String baseName,
LoadService.SuffixType suffixType) |
protected LoadServiceResource |
getClassPathResource(java.lang.ClassLoader classLoader,
java.lang.String name) |
protected java.lang.String |
getFileName(JRubyFile file,
java.lang.String namePlusSuffix) |
IRubyObject |
getLoadedFeatures() |
IRubyObject |
getLoadPath() |
void |
init(java.util.List additionalDirectories) |
boolean |
isCaseInsensitiveFS()
Is the jruby home dir on a case-insensitive fs.
|
protected boolean |
isJarfileLibrary(LoadService.SearchState state,
java.lang.String file) |
protected boolean |
isRequireable(java.net.URL loc) |
void |
load(java.lang.String file,
boolean wrap) |
protected boolean |
loadPathLooksLikeJarURL(java.lang.String loadPathEntry) |
boolean |
lockAndRequire(java.lang.String requireName) |
static void |
reflectedLoad(Ruby runtime,
java.lang.String libraryName,
java.lang.String className,
java.lang.ClassLoader classLoader,
boolean wrap)
Load the org.jruby.runtime.load.Library implementation specified by
className.
|
void |
removeAutoLoadFor(java.lang.String name) |
void |
removeBuiltinLibrary(java.lang.String name) |
void |
removeInternalLoadedFeature(java.lang.String name) |
protected void |
removeLoadedFeature(RubyString loadNameRubyString) |
boolean |
require(java.lang.String file) |
protected void |
reraiseRaiseExceptions(java.lang.Throwable e) |
protected java.lang.String |
resolveLoadName(LoadServiceResource foundResource,
java.lang.String previousPath) |
boolean |
smartLoad(java.lang.String file) |
protected boolean |
tryLoadingLibraryOrScript(Ruby runtime,
LoadService.SearchState state) |
protected LoadServiceResource |
tryResourceAsIs(java.lang.String namePlusSuffix) |
protected LoadServiceResource |
tryResourceFromCWD(LoadService.SearchState state,
java.lang.String baseName,
LoadService.SuffixType suffixType) |
protected LoadServiceResource |
tryResourceFromHome(LoadService.SearchState state,
java.lang.String baseName,
LoadService.SuffixType suffixType) |
protected LoadServiceResource |
tryResourceFromJarURL(LoadService.SearchState state,
java.lang.String baseName,
LoadService.SuffixType suffixType) |
protected LoadServiceResource |
tryResourceFromJarURLWithLoadPath(java.lang.String namePlusSuffix,
java.lang.String loadPathEntry) |
protected LoadServiceResource |
tryResourceFromLoadPath(java.lang.String namePlusSuffix,
java.lang.String loadPathEntry) |
protected LoadServiceResource |
tryResourceFromLoadPathOrURL(LoadService.SearchState state,
java.lang.String baseName,
LoadService.SuffixType suffixType) |
protected static final java.util.regex.Pattern sourcePattern
protected static final java.util.regex.Pattern extensionPattern
protected RubyArray loadPath
protected RubyArray loadedFeatures
protected java.util.List loadedFeaturesInternal
protected final java.util.Map<java.lang.String,Library> builtinLibraries
protected final java.util.Map<java.lang.String,java.util.jar.JarFile> jarFiles
protected final java.util.Map<java.lang.String,IAutoloadMethod> autoloadMap
protected final Ruby runtime
protected boolean caseInsensitiveFS
protected java.util.Map requireLocks
protected final java.util.List<LoadService.LoadSearcher> searchers
public LoadService(Ruby runtime)
public void init(java.util.List additionalDirectories)
protected void addLoadedFeature(RubyString loadNameRubyString)
protected void addPath(java.lang.String path)
public void load(java.lang.String file, boolean wrap)
public LoadService.SearchState findFileForLoad(java.lang.String file) throws LoadService.AlreadyLoaded
LoadService.AlreadyLoaded
public boolean lockAndRequire(java.lang.String requireName)
public boolean smartLoad(java.lang.String file)
public boolean require(java.lang.String file)
public static void reflectedLoad(Ruby runtime, java.lang.String libraryName, java.lang.String className, java.lang.ClassLoader classLoader, boolean wrap)
runtime
- The runtime in which to loadlibraryName
- The name of the library, to use for error messagesclassName
- The class of the libraryclassLoader
- The classloader to use to load itwrap
- Whether to wrap top-level in an anonymous modulepublic IRubyObject getLoadPath()
public IRubyObject getLoadedFeatures()
public IAutoloadMethod autoloadFor(java.lang.String name)
public void removeAutoLoadFor(java.lang.String name)
public IRubyObject autoload(java.lang.String name)
public void addAutoload(java.lang.String name, IAutoloadMethod loadMethod)
public void addBuiltinLibrary(java.lang.String name, Library library)
public void removeBuiltinLibrary(java.lang.String name)
public void removeInternalLoadedFeature(java.lang.String name)
protected boolean featureAlreadyLoaded(RubyString loadNameRubyString)
protected boolean isJarfileLibrary(LoadService.SearchState state, java.lang.String file)
protected void removeLoadedFeature(RubyString loadNameRubyString)
protected void reraiseRaiseExceptions(java.lang.Throwable e) throws RaiseException
RaiseException
protected boolean tryLoadingLibraryOrScript(Ruby runtime, LoadService.SearchState state)
protected java.lang.String buildClassName(java.lang.String className)
protected void checkEmptyLoad(java.lang.String file) throws RaiseException
RaiseException
protected void debugLogTry(java.lang.String what, java.lang.String msg)
protected void debugLogFound(java.lang.String what, java.lang.String msg)
protected void debugLogFound(LoadServiceResource resource)
protected Library findBuiltinLibrary(LoadService.SearchState state, java.lang.String baseName, LoadService.SuffixType suffixType)
protected Library findLibraryWithoutCWD(LoadService.SearchState state, java.lang.String baseName, LoadService.SuffixType suffixType)
protected Library findLibraryWithClassloaders(LoadService.SearchState state, java.lang.String baseName, LoadService.SuffixType suffixType)
protected Library createLibrary(LoadService.SearchState state, LoadServiceResource resource)
protected LoadServiceResource tryResourceFromCWD(LoadService.SearchState state, java.lang.String baseName, LoadService.SuffixType suffixType) throws RaiseException
RaiseException
protected LoadServiceResource tryResourceFromHome(LoadService.SearchState state, java.lang.String baseName, LoadService.SuffixType suffixType) throws RaiseException
RaiseException
protected LoadServiceResource tryResourceFromJarURL(LoadService.SearchState state, java.lang.String baseName, LoadService.SuffixType suffixType)
protected LoadServiceResource tryResourceFromLoadPathOrURL(LoadService.SearchState state, java.lang.String baseName, LoadService.SuffixType suffixType)
protected LoadServiceResource tryResourceFromJarURLWithLoadPath(java.lang.String namePlusSuffix, java.lang.String loadPathEntry)
protected boolean loadPathLooksLikeJarURL(java.lang.String loadPathEntry)
protected LoadServiceResource tryResourceFromLoadPath(java.lang.String namePlusSuffix, java.lang.String loadPathEntry) throws RaiseException
RaiseException
protected LoadServiceResource tryResourceAsIs(java.lang.String namePlusSuffix) throws RaiseException
RaiseException
protected LoadServiceResource findFileInClasspath(java.lang.String name)
name
- the file to find, this is a path nameprotected boolean isRequireable(java.net.URL loc)
protected LoadServiceResource getClassPathResource(java.lang.ClassLoader classLoader, java.lang.String name)
protected java.lang.String resolveLoadName(LoadServiceResource foundResource, java.lang.String previousPath)
protected java.lang.String getFileName(JRubyFile file, java.lang.String namePlusSuffix)
public boolean isCaseInsensitiveFS()
Copyright © 2002-2009 JRuby Team. All Rights Reserved.