|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface SharedClassURLHelper
Shared Class Helper API that stores and finds classes using URL paths.
- Description
A SharedClassURLHelper is obtained by calling getSharedClassURLHelper(ClassLoader) on a SharedClassHelperFactory.
The SharedClassURLHelper is designed for ClassLoaders which load classes from many different locations, without the concept of a classpath.
A ClassLoader may find and store classes in the cache using any URL.
- Usage
The ClassLoader should call findSharedClass after looking in its local cache and asking its parent (if one exists).
If findSharedClass does not return null, the ClassLoader should call defineClass on the byte[] returned.
The ClassLoader should call storeSharedClass immediately after a class has been defined, but NOT if the class being defined was loaded from the shared cache.
The ClassLoader is reponsible for coordinating the creation and use of partition Strings, if partitions are required (see below).
Classes can only be stored using URLs which have "file" or "jar" protocols and which refer to existing resources.
- Dynamic Cache Updates
Since the shared cache is persistent beyond the lifetime of a JVM, classes in the shared cache may become out-of-date ("stale").
Classes in the cache are automatically kept up-to-date by default:
If findSharedClass is called for a class which exists in the cache but which has been updated on the filesystem since it was stored,
then the old version in the cache is automatically marked stale and findSharedClass will return null.
The ClassLoader should then store the updated version of the class.
Note that jar/zip updates will cause all cache entries loaded from that jar/zip to be marked stale.
(This behaviour can be disabled using the correct command-line option. See -Xshareclasses:help)
It is also assumed that the ClassLoader will maintain a read lock on jar/zip files opened during its lifetime, preventing their modification.
This prevents the cache from having to constantly check for updates.
- Partitions
A partition may be used when finding or storing a class, which allows modified versions of the same class
to be stored in the cache, effectively creating "partitions" in the cache.
Partitions are designed for bytecode modification such as the use of Aspects. It is the responsibility of the ClassLoader
to create partitions which describe the type of modification performed on the class bytes.
If a class is updated on the filesystem and automatic dynamic updates are enabled, then all versions of the class across
all partitions will be marked stale.
- Class Metadata
A ClassLoader may create metadata when loading and defining classes, such as a jar manifest or security data. None of this metadata may be stored in the cache, so if a ClassLoader is finding classes in the shared cache, it must load any metadata that it needs from disk before defining the classes.
- Security
A SharedClassHelper will only allow classes to be stored in the cache which were defined by the ClassLoader that owns the SharedClassHelper.
If a SecurityManager is installed, SharedClassPermissions must be used to permit read/write access to the shared class cache.
Permissions are granted by ClassLoader classname in the java.policy file and are fixed when the SharedClassHelper is created.
Note also that if the createClassLoader RuntimePermission is not granted, ClassLoaders cannot be created
which in turn means that SharedClassHelpers cannot be created.
- Compatibility with other SharedClassHelpers
Classes stored using the SharedClassURLHelper can be retrieved using the SharedClassURLClasspathHelper and vice-versa. This is also true for partitions which can be used across these two helpers.
SharedClassURLHelper
,
SharedClassHelperFactory
,
SharedClassPermission
Method Summary | |
---|---|
byte[] |
findSharedClass(java.lang.String partition,
java.net.URL path,
java.lang.String className)
Find a class in the shared cache using a specific URL, class name and user-defined partition (see "Partitions" above). |
byte[] |
findSharedClass(java.net.URL path,
java.lang.String className)
Find a class in the shared cache using a specific URL and class name. |
boolean |
setMinimizeUpdateChecks()
Minimize update checking on jar files for optimal performance |
boolean |
storeSharedClass(java.lang.String partition,
java.net.URL path,
java.lang.Class clazz)
Store a class in the shared cache using the URL location it was loaded from and a user-defined partition (see "Partitions" above). |
boolean |
storeSharedClass(java.net.URL path,
java.lang.Class clazz)
Store a class in the shared cache using the URL location it was loaded from. |
Methods inherited from interface com.ibm.oti.shared.SharedClassHelper |
---|
getSharingFilter, setSharingFilter |
Methods inherited from interface com.ibm.oti.shared.SharedHelper |
---|
getClassLoader |
Method Detail |
---|
byte[] findSharedClass(java.net.URL path, java.lang.String className)
A class will be returned if it was stored against the same URL.
Null is returned if the class cannot be found or if it is stale (see "Dynamic Cache Updates" above).
To obtain an instance of the class, the byte[] returned must be passed to defineClass by the caller ClassLoader.
Also returns false if the URL at foundAtIndex is not a file URL or if the resource it refers to does not exist.
path
- URL
A URL path. Cannot be null.className
- String
The name of the class to be found
byte[] findSharedClass(java.lang.String partition, java.net.URL path, java.lang.String className)
A class will only be returned if it was stored against the same URL and using the same partition.
Null is returned if the class cannot be found or if it is stale (see "Dynamic Cache Updates" above).
To obtain an instance of the class, the byte[] returned must be passed to defineClass by the caller ClassLoader.
Also returns false if the URL at foundAtIndex is not a file URL or if the resource it refers to does not exist.
partition
- String.
User-defined partition if finding modified bytecode (see "Partitions" above).
Passing null is equivalent of calling non-partition findSharedClass call.path
- URL.
A URL path. Cannot be null.className
- String.
The name of the class to be found
boolean storeSharedClass(java.net.URL path, java.lang.Class clazz)
The class being stored must have been defined by the caller ClassLoader and must exist in the URL location specified.
Returns true if the class is stored successfully or false otherwise.
Will return false if the class being stored was not defined by the caller ClassLoader.
Also returns false if the URL at foundAtIndex is not a file URL or if the resource it refers to does not exist.
path
- URL.
The URL path that the class was loaded from. Cannot be null.clazz
- Class.
The class to store in the shared cache
boolean storeSharedClass(java.lang.String partition, java.net.URL path, java.lang.Class clazz)
The class being stored must have been defined by the caller ClassLoader and must exist in the URL location specified.
Returns true if the class is stored successfully or false otherwise.
Will return false if the class being stored was not defined by the caller ClassLoader.
Also returns false if the URL at foundAtIndex is not a file URL or if the resource it refers to does not exist.
partition
- String.
User-defined partition if storing modified bytecode (see "Partitions" above).
Passing null is equivalent of calling non-partition storeSharedClass call.path
- URL.
The URL path that the class was loaded from. Cannot be null.clazz
- Class.
The class to store in the shared cache
boolean setMinimizeUpdateChecks()
By default, when a class is loaded from the shared class cache, the timestamp of the container it was originally loaded from is
compared with the timestamp of the actual container on the filesystem. If the two do not match, the original class is marked stale
and is not returned by findSharedClass(). These checks are not performed if the container is held open by the ClassLoader.
If the ClassLoader does not want to open the container, but doesn't want the timestamp to be constantly checked when
classes are loaded, it should call this function immediately after the SharedClassURLHelper object has been created.
Once this function has been called, each container timestamp is checked once and then is not checked again for the lifetime
of the SharedClassURLHelper.
This feature cannot be unset.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |