public class Nexus extends Object
This nexus is a global dispatcher for initializing classes with
LoadedTypeInitializer
s. To do so, this class is to be loaded
by the system class loader in an explicit manner. Any instrumented class is then injected a code
block into its static type initializer that makes a call to this very same nexus which had the
loaded type initializer registered before hand.
Important: The nexus must never be accessed directly but only by its
AgentBuilder.Default.InitializationStrategy.SelfInjection.NexusAccessor
which makes sure that the nexus is loaded by the system class loader. Otherwise, a class might not
be able to initialize itself if it is loaded by different class loader that does not have the
system class loader in its hierarchy.
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
int |
hashCode() |
static void |
initialize(Class<?> type,
int identification)
Initializes a loaded type.
|
static void |
register(String name,
ClassLoader classLoader,
int identification,
Object typeInitializer)
Registers a new loaded type initializer.
|
String |
toString() |
public static void initialize(Class<?> type, int identification) throws Exception
type
- The loaded type to initialize.identification
- An identification for the initializer to run.Exception
- If an exception occurs.public static void register(String name, ClassLoader classLoader, int identification, Object typeInitializer)
Registers a new loaded type initializer.
Important: This method must never be called directly but only by using a
AgentBuilder.InitializationStrategy.SelfInjection.NexusAccessor
which enforces to access this class for the
system class loader where a Java agent always registers its instances. This avoids a duplication of the class if this nexus is loaded by different
class loaders. For this reason, the last parameter must not use a Byte Buddy specific type as those types can be loaded by different class loaders,
too. Any access of the instance is done using Java reflection instead.
name
- The name of the type for the loaded type initializer.classLoader
- The class loader of the type for the loaded type initializer.identification
- An identification for the initializer to run.typeInitializer
- The type initializer to register. The initializer must be an instance
of LoadedTypeInitializer
where
it does however not matter which class loader loaded this latter type.Copyright © 2014–2016. All rights reserved.