public class ClassEnhancer
extends java.lang.Object
implements java.lang.instrument.ClassFileTransformer
Entity
or Persistent
.
ClassEnhancer
objects are thread-safe. Multiple threads may
safely call the methods of a shared ClassEnhancer
object.
As described in the package summary, bytecode enhancement may be used either at runtime or offline (at build time).
To use enhancement offline, this class may be used as a main
program
.
It may also be used via an ant task
.
For enhancement at runtime, this class provides the low level support needed to transform class bytes during class loading. To configure runtime enhancement you may use one of the following approaches:
je-<version>.jar
or db.jar
file may be used as
an instrumentation agent as follows:
java -javaagent:<BDB-JAR-FILE>=enhance:packageNames ...
packageNames
is a comma separated list of packages containing
persistent classes. Sub-packages of these packages are also searched. If
packageNames
is omitted then all packages known to the current
classloader are searched.
The "-v" option may be included in the comma separated list to print the name of each class that is enhanced.
enhance(java.lang.String, byte[])
method may be called to implement a class loader
that performs enhancement. Using this approach, it is the developer's
responsibility to implement and configure the class loader.Constructor and Description |
---|
ClassEnhancer()
Creates a class enhancer that searches all packages.
|
ClassEnhancer(java.util.Set<java.lang.String> packageNames)
Creates a class enhancer that searches a given set of packages.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
enhance(java.lang.String className,
byte[] classBytes)
Enhances the given class bytes if the class is annotated with
Entity or Persistent . |
boolean |
getVerbose()
Gets verbose mode.
|
static void |
main(java.lang.String[] args)
Enhances classes in the directories specified.
|
static void |
premain(java.lang.String args,
java.lang.instrument.Instrumentation inst)
Enhances classes as specified by a JVM -javaagent argument.
|
void |
setVerbose(boolean verbose)
Sets verbose mode.
|
byte[] |
transform(java.lang.ClassLoader loader,
java.lang.String className,
java.lang.Class<?> classBeingRedefined,
java.security.ProtectionDomain protectionDomain,
byte[] classfileBuffer) |
public ClassEnhancer()
public ClassEnhancer(java.util.Set<java.lang.String> packageNames)
packageNames
- a set of packages to search for persistent
classes. Sub-packages of these packages are also searched. If empty or
null, all packages known to the current classloader are searched.public static void main(java.lang.String[] args) throws java.lang.Exception
java -cp je-<version>.jar com.sleepycat.persist.model.ClassEnhancer ./classes
The "-v" argument may be specified to print the name of each class file that is enhanced. The total number of class files enhanced will always be printed.
args
- one or more directories containing classes to be enhanced.
Subdirectories of these directories will also be searched. Optionally,
-v may be included to print the name of every class file enhanced.java.lang.Exception
- if a problem occurs.public static void premain(java.lang.String args, java.lang.instrument.Instrumentation inst)
args
- see java.lang.instrument.Instrumentation.inst
- see java.lang.instrument.Instrumentation.Instrumentation
public void setVerbose(boolean verbose)
True may be specified to print the name of each class file that is enhanced. This property is false by default.
verbose
- whether to use verbose mode.public boolean getVerbose()
setVerbose(boolean)
public byte[] transform(java.lang.ClassLoader loader, java.lang.String className, java.lang.Class<?> classBeingRedefined, java.security.ProtectionDomain protectionDomain, byte[] classfileBuffer)
transform
in interface java.lang.instrument.ClassFileTransformer
public byte[] enhance(java.lang.String className, byte[] classBytes)
Entity
or Persistent
.className
- the class name in binary format; for example,
"my.package.MyClass$Name", or null if no filtering by class name
should be performed.classBytes
- are the class file bytes to be enhanced.Copyright (c) 2002, 2017 Oracle and/or its affiliates. All rights reserved.