Top Description Inners Fields Constructors Methods
org.jruby.util

pack-priv Class JarCache

extends Object
Class Inheritance
Imports
java.io.File, .IOException, .InputStream, java.lang.ref.ReferenceQueue, .SoftReference, java.util.Collections, .Enumeration, .HashMap, .HashSet, .Map, .Set, java.util.concurrent.ConcurrentHashMap, java.util.jar.JarEntry, .JarFile, org.jruby.util.cli.Options

Instances of JarCache provides jar index information.

Implementation is threadsafe. Since loading index information is O(jar-entries) we cache the snapshot in a WeakHashMap. The implementation pays attention to lastModified timestamp of the jar and will invalidate the cache entry if jar has been updated since the snapshot calculation.

****************************************************************************************** DANGER DANGER DANGER DANGER DANGER DANGER DANGER DANGER DANGER DANGER DANGER DANGER DANGER ****************************************************************************************** The spec for this cache is disabled currently for #2655, because of last-modified time oddities on CloudBees. Please be cautious modifying this code and make sure you run the associated spec locally.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
private static class

Field Summary

Modifier and TypeField and Description
private final Map<String, JarCache.SoftJarIndex>
private final ReferenceQueue<JarCache.JarIndex>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
public JarCache.JarIndex
getIndex(String jarPath)

public void
remove(String jarPath)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

indexCacheback to summary
private final Map<String, JarCache.SoftJarIndex> indexCache
indexQueueback to summary
private final ReferenceQueue<JarCache.JarIndex> indexQueue

Constructor Detail

JarCacheback to summary
pack-priv JarCache()

Method Detail

cleanupback to summary
private void cleanup()
getIndexback to summary
public JarCache.JarIndex getIndex(String jarPath)
removeback to summary
public void remove(String jarPath)
org.jruby.util back to summary

pack-priv Class JarCache.JarIndex

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Map<String, String[]>
private final JarFile
private final long
private Long
private static final String

Constructor Summary

AccessConstructor and Description
pack-priv
JarIndex(String jarPath)

Method Summary

Modifier and TypeMethod and Description
private static String
public String[]
getDirEntries(String entryPath)

public InputStream
public JarEntry
getJarEntry(String entryPath)

private long

Returns:

The last modification timestamp.
getLastModified
(String
The path to the JAR file.
jarPath
)

Determines the last modification timestamp of a file.

public boolean
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cachedDirEntriesback to summary
private final Map<String, String[]> cachedDirEntries
jarback to summary
private final JarFile jar
lastModifiedback to summary
private final long lastModified
lastModifiedExpirationback to summary
private Long lastModifiedExpiration
ROOT_KEYback to summary
private static final String ROOT_KEY

Constructor Detail

JarIndexback to summary
pack-priv JarIndex(String jarPath) throws IOException

Method Detail

canonicalJarPathback to summary
private static String canonicalJarPath(String path)
getDirEntriesback to summary
public String[] getDirEntries(String entryPath)
getInputStreamback to summary
public InputStream getInputStream(JarEntry entry) throws IOException, IllegalStateException
getJarEntryback to summary
public JarEntry getJarEntry(String entryPath)
getLastModifiedback to summary
private long getLastModified(String jarPath)

Determines the last modification timestamp of a file.

Note

Getting the value is an expensive operation on Windows systems (see href="https://github.com/jruby/jruby/issues/6730"). Therefore a cached value is used with a maximum lifetime of Options#JAR_CACHE_EXPIRATION milliseconds.

Parameters
jarPath:String

The path to the JAR file.

Returns:long

The last modification timestamp.

isValidback to summary
public boolean isValid()
releaseback to summary
public void release()
org.jruby.util back to summary

private Class JarCache.SoftJarIndex

extends SoftReference<JarCache.JarIndex>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
Inherited from java.lang.ref.SoftReference:
get

Field Detail

keyback to summary
private final String key

Constructor Detail

SoftJarIndexback to summary
public SoftJarIndex(String key, JarCache.JarIndex index)

Method Detail

getKeyback to summary
public String getKey()