Top Description Fields Constructors Methods
org.easymock.bytebuddy.dynamic

public Class Nexus

extends WeakReference<ClassLoader>
Class Inheritance
Imports
org.easymock.bytebuddy.utility.nullability.AlwaysNull, .MaybeNull, java.lang.ref.Reference, .ReferenceQueue, .WeakReference, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap

This nexus is a global dispatcher for initializing classes with org.easymock.bytebuddy.implementation.LoadedTypeInitializers. 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.

Note

Availability of the Nexus class and its injection into the system class loader can be disabled entirely by setting the Nexus#PROPERTY system property to false.

Important Note

The nexus must never be accessed directly but only by the 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.

Field Summary

Modifier and TypeField and Description
private final int
classLoaderHashCode

The class loader's hash code upon registration.

private final int
identification

A random value that uniquely identifies a Nexus entry in order to avoid conflicts when applying the self-initialization strategy in multiple transformations.

private final String
name

The name of a type for which a loaded type initializer is registered.

private static final ReferenceQueue<ClassLoader>
NO_QUEUE

An type-safe constant for a non-operational reference queue.

public static final String
PROPERTY

A system property that allows to disable the use of the Nexus class which is normally injected into the system class loader.

private static final ConcurrentMap<Nexus, Object>
TYPE_INITIALIZERS

A map of keys identifying a loaded type by its name and class loader mapping their potential org.easymock.bytebuddy.implementation.LoadedTypeInitializer where the class loader of these initializers is however irrelevant.

Constructor Summary

AccessConstructor and Description
private
Nexus(Class<?>
The loaded type for which a key is to be created.
type
,
int
An identification for the initializer to run.
identification
)

Creates a key for identifying a loaded type initializer.

private
Nexus(String
The name of a type for which a loaded type initializer is registered.
name
,
ClassLoader
The class loader for which a loaded type initializer is registered.
classLoader
,
ReferenceQueue<? super ClassLoader>
The reference queue to notify upon the class loader's collection or null if no queue should be notified.
referenceQueue
,
int
An identification for the initializer to run.
identification
)

Creates a key for identifying a loaded type initializer.

Method Summary

Modifier and TypeMethod and Description
public static void
clean(Reference<? super ClassLoader>
The stale reference to clean.
reference
)

Cleans any stale entries from this nexus.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public static void
initialize(Class<?>
The loaded type to initialize.
type
,
int
An identification for the initializer to run.
identification
)

Initializes a loaded type.

private static String

Returns:

The non-anonymous name of the given class.
nonAnonymous
(String
The name as returned by Class#getName().
typeName
)

Normalizes a type name if it is loaded by an anonymous class loader.

public static void
register(String
The name of the type for the loaded type initializer.
name
,
ClassLoader
The class loader of the type for the loaded type initializer.
classLoader
,
ReferenceQueue<? super ClassLoader>
The reference queue to notify upon the class loader's collection which will be enqueued a reference which can be handed to Nexus#clean(Reference) or null if no reference queue should be notified.
referenceQueue
,
int
An identification for the initializer to run.
identification
,
Object
The type initializer to register. The initializer must be an instance of org.easymock.bytebuddy.implementation.LoadedTypeInitializer where it does however not matter which class loader loaded this latter type.
typeInitializer
)

Registers a new loaded type initializer.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Field Detail

classLoaderHashCodeback to summary
private final int classLoaderHashCode

The class loader's hash code upon registration.

identificationback to summary
private final int identification

A random value that uniquely identifies a Nexus entry in order to avoid conflicts when applying the self-initialization strategy in multiple transformations.

nameback to summary
private final String name

The name of a type for which a loaded type initializer is registered.

NO_QUEUEback to summary
private static final ReferenceQueue<ClassLoader> NO_QUEUE

An type-safe constant for a non-operational reference queue.

Annotations
@AlwaysNull
PROPERTYback to summary
public static final String PROPERTY

A system property that allows to disable the use of the Nexus class which is normally injected into the system class loader.

TYPE_INITIALIZERSback to summary
private static final ConcurrentMap<Nexus, Object> TYPE_INITIALIZERS

A map of keys identifying a loaded type by its name and class loader mapping their potential org.easymock.bytebuddy.implementation.LoadedTypeInitializer where the class loader of these initializers is however irrelevant.

Constructor Detail

Nexusback to summary
private Nexus(Class<?> type, int identification)

Creates a key for identifying a loaded type initializer.

Parameters
type:Class<?>

The loaded type for which a key is to be created.

identification:int

An identification for the initializer to run.

Nexusback to summary
private Nexus(String name, ClassLoader classLoader, ReferenceQueue<? super ClassLoader> referenceQueue, int identification)

Creates a key for identifying a loaded type initializer.

Parameters
name:String

The name of a type for which a loaded type initializer is registered.

classLoader:ClassLoader

The class loader for which a loaded type initializer is registered.

referenceQueue:ReferenceQueue<? super ClassLoader>

The reference queue to notify upon the class loader's collection or null if no queue should be notified.

identification:int

An identification for the initializer to run.

Method Detail

cleanback to summary
public static void clean(Reference<? super ClassLoader> reference)

Cleans any stale entries from this nexus. Entries are considered stale if their class loader was collected before a class was initialized.

Important Note

This method must never be called directly but only by using a NexusAccessor which enforces to access this class for the system class loader to assure a VM global singleton. 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.

Parameters
reference:Reference<? super ClassLoader>

The stale reference to clean.

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
initializeback to summary
public static void initialize(Class<?> type, int identification) throws Exception

Initializes a loaded type. This method must only be invoked via the system class loader.

Important Note

This method must never be called directly but only by using a NexusAccessor.InitializationAppender which enforces to access this class for the system class loader to assure a VM global singleton. 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.

Parameters
type:Class<?>

The loaded type to initialize.

identification:int

An identification for the initializer to run.

Annotations
@SuppressWarnings:unused
Exceptions
Exception:
If an exception occurs.
nonAnonymousback to summary
private static String nonAnonymous(String typeName)

Normalizes a type name if it is loaded by an anonymous class loader.

Parameters
typeName:String

The name as returned by Class#getName().

Returns:String

The non-anonymous name of the given class.

registerback to summary
public static void register(String name, ClassLoader classLoader, ReferenceQueue<? super ClassLoader> referenceQueue, int identification, Object typeInitializer)

Registers a new loaded type initializer.

Important Note

This method must never be called directly but only by using a NexusAccessor which enforces to access this class for the system class loader to assure a VM global singleton. 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.

Parameters
name:String

The name of the type for the loaded type initializer.

classLoader:ClassLoader

The class loader of the type for the loaded type initializer.

referenceQueue:ReferenceQueue<? super ClassLoader>

The reference queue to notify upon the class loader's collection which will be enqueued a reference which can be handed to Nexus#clean(Reference) or null if no reference queue should be notified.

identification:int

An identification for the initializer to run.

typeInitializer:Object

The type initializer to register. The initializer must be an instance of org.easymock.bytebuddy.implementation.LoadedTypeInitializer where it does however not matter which class loader loaded this latter type.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override