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.
| Modifier and Type | Class and Description |
|---|---|
class |
LoadService.BailoutSearcher
Deprecated.
|
class |
LoadService.ClassLoaderSearcher
Deprecated.
|
class |
LoadService.ExtensionSearcher
Deprecated.
|
static interface |
LoadService.LoadSearcher
Deprecated.
|
private static class |
LoadService.LoadTimer |
class |
LoadService.NormalSearcher
Deprecated.
|
private class |
LoadService.RequireLocks |
private static class |
LoadService.RequireState |
class |
LoadService.ScriptClassSearcher
Deprecated.
|
static class |
LoadService.SearchState |
class |
LoadService.SourceBailoutSearcher
Deprecated.
|
static class |
LoadService.SuffixType |
private static class |
LoadService.TracingLoadTimer |
| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<java.lang.String,Library> |
builtinLibraries |
protected static java.util.regex.Pattern |
extensionPattern |
protected java.util.Map<java.lang.String,java.util.jar.JarFile> |
jarFiles |
protected LibrarySearcher |
librarySearcher |
protected StringArraySet |
loadedFeatures |
protected RubyArray |
loadedFeaturesDup |
private java.util.Map<java.lang.String,java.lang.String> |
loadedFeaturesIndex |
protected RubyArray |
loadPath |
private LoadService.LoadTimer |
loadTimer |
private static Logger |
LOG |
protected LoadService.RequireLocks |
requireLocks |
protected Ruby |
runtime |
protected java.util.List<LoadService.LoadSearcher> |
searchers |
protected static java.util.regex.Pattern |
sourcePattern |
private static java.util.regex.Pattern |
URI_PATTERN |
| Constructor and Description |
|---|
LoadService(Ruby runtime) |
| Modifier and Type | Method and Description |
|---|---|
void |
addBuiltinLibrary(java.lang.String name,
Library library) |
protected void |
addFeatureToIndex(java.lang.String shortName,
java.lang.String name) |
protected void |
addLoadedFeature(java.lang.String name)
Deprecated.
|
protected void |
addLoadedFeature(java.lang.String shortName,
java.lang.String name) |
protected void |
addPath(java.lang.String path) |
void |
addPaths(java.util.List<java.lang.String> additionalDirectories)
Add additional directories to the load path.
|
void |
addPaths(java.lang.String... additionalDirectories)
Add additional directories to the load path.
|
boolean |
autoloadRequire(java.lang.String requireName) |
protected java.lang.String |
buildClassName(java.lang.String className) |
protected void |
checkEmptyLoad(java.lang.String file) |
static java.lang.String |
classpathFilenameFromURL(java.lang.String name,
java.net.URL loc,
boolean isClasspathScheme)
Given a URL to a classloader resource, build an appropriate load string.
|
protected Library |
createLibrary(LoadService.SearchState state,
LoadServiceResource resource)
Deprecated.
|
protected void |
debugLogFound(LoadServiceResource resource)
Deprecated.
|
protected void |
debugLogFound(java.lang.String what,
java.lang.String msg)
Deprecated.
|
protected void |
debugLogTry(java.lang.String what,
java.lang.String msg)
Deprecated.
|
private java.lang.String |
expandRelativeJarPath(java.lang.String path) |
protected boolean |
featureAlreadyLoaded(java.lang.String name) |
protected Library |
findBuiltinLibrary(LoadService.SearchState state,
java.lang.String baseName,
LoadService.SuffixType suffixType)
Deprecated.
|
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.
|
private Library |
findLibraryBySearchState(LoadService.SearchState state) |
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)
Deprecated.
|
protected LoadServiceResource |
getClassPathResource(java.lang.ClassLoader classLoader,
java.lang.String name) |
protected java.lang.String |
getFileName(JRubyFile file,
java.lang.String namePlusSuffix) |
java.util.jar.JarFile |
getJarFile(java.lang.String jarFileName) |
IRubyObject |
getLoadedFeatures() |
IRubyObject |
getLoadPath() |
protected java.lang.String |
getLoadPathEntry(IRubyObject entry) |
void |
init(java.util.List prependDirectories)
Called to initialize the load path with a set of optional prepended
directories and then the standard set of dirs.
|
protected boolean |
isFeatureInIndex(java.lang.String shortName) |
private boolean |
isFeaturesIndexUpToDate() |
protected boolean |
isJarfileLibrary(LoadService.SearchState state,
java.lang.String file) |
protected static boolean |
isRequireable(java.net.URL loc) |
void |
load(java.lang.String file,
boolean wrap) |
void |
loadFromClassLoader(java.lang.ClassLoader classLoader,
java.lang.String file,
boolean wrap) |
protected boolean |
loadPathLooksLikeClasspathURL(java.lang.String loadPathEntry) |
protected boolean |
loadPathLooksLikeJarURL(java.lang.String loadPathEntry) |
private static RaiseException |
newLoadErrorFromThrowable(Ruby runtime,
java.lang.String file,
java.lang.Throwable t) |
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 |
removeBuiltinLibrary(java.lang.String name) |
void |
removeInternalLoadedFeature(java.lang.String name) |
boolean |
require(java.lang.String requireName) |
private LoadService.RequireState |
requireCommon(java.lang.String file,
boolean circularRequireWarning) |
protected void |
reraiseRaiseExceptions(java.lang.Throwable e) |
protected java.lang.String |
resolveLoadName(LoadServiceResource foundResource,
java.lang.String previousPath) |
boolean |
smartLoad(java.lang.String file)
Deprecated.
|
private java.lang.String[] |
splitJarUrl(java.lang.String loadPathEntry) |
protected boolean |
tryLoadingLibraryOrScript(Ruby runtime,
LoadService.SearchState state) |
protected LoadServiceResource |
tryResourceAsIs(java.lang.String namePlusSuffix)
Deprecated.
|
protected LoadServiceResource |
tryResourceAsIs(java.lang.String namePlusSuffix,
java.lang.String debugName)
Deprecated.
|
protected LoadServiceResource |
tryResourceFromCWD(LoadService.SearchState state,
java.lang.String baseName,
LoadService.SuffixType suffixType)
Deprecated.
|
protected LoadServiceResource |
tryResourceFromDotSlash(LoadService.SearchState state,
java.lang.String baseName,
LoadService.SuffixType suffixType)
Deprecated.
|
protected LoadServiceResource |
tryResourceFromHome(LoadService.SearchState state,
java.lang.String baseName,
LoadService.SuffixType suffixType)
Deprecated.
|
protected LoadServiceResource |
tryResourceFromJarURL(LoadService.SearchState state,
java.lang.String baseName,
LoadService.SuffixType suffixType)
Deprecated.
|
protected LoadServiceResource |
tryResourceFromJarURLWithLoadPath(java.lang.String namePlusSuffix,
java.lang.String loadPathEntry)
Deprecated.
|
protected LoadServiceResource |
tryResourceFromLoadPath(java.lang.String namePlusSuffix,
java.lang.String loadPathEntry)
Deprecated.
|
protected LoadServiceResource |
tryResourceFromLoadPathOrURL(LoadService.SearchState state,
java.lang.String baseName,
LoadService.SuffixType suffixType)
Deprecated.
|
protected void |
warnCircularRequire(java.lang.String requireName) |
private static final Logger LOG
private final LoadService.LoadTimer loadTimer
protected static final java.util.regex.Pattern sourcePattern
protected static final java.util.regex.Pattern extensionPattern
protected RubyArray loadPath
protected StringArraySet loadedFeatures
protected RubyArray loadedFeaturesDup
private final java.util.Map<java.lang.String,java.lang.String> loadedFeaturesIndex
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 Ruby runtime
protected final LibrarySearcher librarySearcher
protected final LoadService.RequireLocks requireLocks
protected final java.util.List<LoadService.LoadSearcher> searchers
private static final java.util.regex.Pattern URI_PATTERN
public LoadService(Ruby runtime)
public void init(java.util.List prependDirectories)
prependDirectories - public void addPaths(java.util.List<java.lang.String> additionalDirectories)
additionalDirectories - a List of additional dirs to append to the load pathpublic void addPaths(java.lang.String... additionalDirectories)
additionalDirectories - an array of additional dirs to append to the load pathprotected boolean isFeatureInIndex(java.lang.String shortName)
@Deprecated protected void addLoadedFeature(java.lang.String name)
protected void addLoadedFeature(java.lang.String shortName,
java.lang.String name)
protected void addFeatureToIndex(java.lang.String shortName,
java.lang.String name)
protected void addPath(java.lang.String path)
public void load(java.lang.String file,
boolean wrap)
public void loadFromClassLoader(java.lang.ClassLoader classLoader,
java.lang.String file,
boolean wrap)
public LoadService.SearchState findFileForLoad(java.lang.String file)
public boolean require(java.lang.String requireName)
public boolean autoloadRequire(java.lang.String requireName)
private LoadService.RequireState requireCommon(java.lang.String file, boolean circularRequireWarning)
protected void warnCircularRequire(java.lang.String requireName)
@Deprecated public boolean smartLoad(java.lang.String file)
require(String) instead.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 void addBuiltinLibrary(java.lang.String name,
Library library)
public void removeBuiltinLibrary(java.lang.String name)
public void removeInternalLoadedFeature(java.lang.String name)
private boolean isFeaturesIndexUpToDate()
protected boolean featureAlreadyLoaded(java.lang.String name)
protected boolean isJarfileLibrary(LoadService.SearchState state, java.lang.String file)
protected void reraiseRaiseExceptions(java.lang.Throwable e)
throws RaiseException
RaiseExceptionprotected boolean tryLoadingLibraryOrScript(Ruby runtime, LoadService.SearchState state)
private static RaiseException newLoadErrorFromThrowable(Ruby runtime, java.lang.String file, java.lang.Throwable t)
protected java.lang.String buildClassName(java.lang.String className)
protected void checkEmptyLoad(java.lang.String file)
throws RaiseException
RaiseException@Deprecated
protected void debugLogTry(java.lang.String what,
java.lang.String msg)
@Deprecated
protected void debugLogFound(java.lang.String what,
java.lang.String msg)
@Deprecated protected void debugLogFound(LoadServiceResource resource)
private Library findLibraryBySearchState(LoadService.SearchState state)
@Deprecated protected Library findBuiltinLibrary(LoadService.SearchState state, java.lang.String baseName, LoadService.SuffixType suffixType)
@Deprecated 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)
@Deprecated protected Library createLibrary(LoadService.SearchState state, LoadServiceResource resource)
@Deprecated protected LoadServiceResource tryResourceFromCWD(LoadService.SearchState state, java.lang.String baseName, LoadService.SuffixType suffixType) throws RaiseException
RaiseException@Deprecated protected LoadServiceResource tryResourceFromDotSlash(LoadService.SearchState state, java.lang.String baseName, LoadService.SuffixType suffixType) throws RaiseException
RaiseException@Deprecated protected LoadServiceResource tryResourceFromHome(LoadService.SearchState state, java.lang.String baseName, LoadService.SuffixType suffixType) throws RaiseException
RaiseException@Deprecated protected LoadServiceResource tryResourceFromJarURL(LoadService.SearchState state, java.lang.String baseName, LoadService.SuffixType suffixType)
@Deprecated protected LoadServiceResource tryResourceFromLoadPathOrURL(LoadService.SearchState state, java.lang.String baseName, LoadService.SuffixType suffixType)
protected java.lang.String getLoadPathEntry(IRubyObject entry)
@Deprecated protected LoadServiceResource tryResourceFromJarURLWithLoadPath(java.lang.String namePlusSuffix, java.lang.String loadPathEntry)
public java.util.jar.JarFile getJarFile(java.lang.String jarFileName)
protected boolean loadPathLooksLikeJarURL(java.lang.String loadPathEntry)
protected boolean loadPathLooksLikeClasspathURL(java.lang.String loadPathEntry)
private java.lang.String[] splitJarUrl(java.lang.String loadPathEntry)
@Deprecated protected LoadServiceResource tryResourceFromLoadPath(java.lang.String namePlusSuffix, java.lang.String loadPathEntry) throws RaiseException
RaiseException@Deprecated protected LoadServiceResource tryResourceAsIs(java.lang.String namePlusSuffix) throws RaiseException
RaiseException@Deprecated protected LoadServiceResource tryResourceAsIs(java.lang.String namePlusSuffix, java.lang.String debugName) throws RaiseException
RaiseExceptionprotected LoadServiceResource findFileInClasspath(java.lang.String name)
name - the file to find, this is a path nameprotected static boolean isRequireable(java.net.URL loc)
protected LoadServiceResource getClassPathResource(java.lang.ClassLoader classLoader, java.lang.String name)
public static java.lang.String classpathFilenameFromURL(java.lang.String name,
java.net.URL loc,
boolean isClasspathScheme)
name - the original filename requestedloc - the URL to the resourceisClasspathScheme - whether we're using the classpath: scehemeprivate java.lang.String expandRelativeJarPath(java.lang.String path)
protected java.lang.String resolveLoadName(LoadServiceResource foundResource, java.lang.String previousPath)
protected java.lang.String getFileName(JRubyFile file, java.lang.String namePlusSuffix)