Package org.zeroturnaround.javarebel
Interface ClassBytecodeProcessorCache
public interface ClassBytecodeProcessorCache
This interface allows
class bytecode processors to cache their transformations between
runs. A typical usage will look something like this:
public class MyCBP implements ClassBytecodeProcessor {
public byte[] process(ClassLoader cl, String classname, byte[] bytecode) {
ClassBytecodeProcessorCache cache = IntegrationFactory.getInstance().getClassBytecodeProcessorCache();
String key = cache.computeKey(cl, classname, bytecode, null);
if (key != null) {
byte[] cachedBytes = cache.get(key);
if (cachedBytes != null)
return cachedBytes;
}
// ... do actual processing ...
if (key != null)
cache.put(key, processedBytes);
return processedBytes;
}
}
-
Method Summary
Modifier and TypeMethodDescriptioncomputeKey(String className, byte[] bytecode, ClassBytecodeProcessor processor, String tag) Computes the cache key for the given arguments.byte[]voidStores given bytes associated with the given key.
-
Method Details
-
computeKey
Computes the cache key for the given arguments.- Parameters:
className- the name of the processed classbytecode- the class bytes that are to be processedprocessor- the processortag- a custom tag to differentiate distinct processor configurations- Returns:
- a cache key, or
nullif the class loader is not cache capable
-
get
- Parameters:
key- the key- Returns:
- the cached bytes corresponding to the given key.
-
put
Stores given bytes associated with the given key.- Parameters:
key- the keybytes- the bytes to cache
-