org.curjent.agent
Interface AgentLoader

All Known Implementing Classes:
CustomLoader, DelegatingLoader

public interface AgentLoader

Creates a generated class. See Creating an Agent in the description for Agent.

Java does not provide a means for creating dynamically generated classes without creating a custom ClassLoader or using reflection to call the protected defineClass method of an existing ClassLoader. This interface gives the user and/or designer of an agent the choice of class loading mechanisms.

Using a custom ClassLoader (see CustomLoader) follows the more standard class loading model, but at the expense of creating another class loader branch in the JVM's tree of class loaders, with all the potential complexities that may imply. Reflection, on the other hand, can define and load generated classes within an existing class loader scope (see DelegatingLoader).

See Also:
Agent.newInstance(AgentLoader, Class[], AgentTasks, Class)

Method Summary
 Class<?> defineClass(String name, byte[] bytes)
          Creates a class generated by an agent.
 ClassLoader getClassLoader()
          Returns a non-null reference to the effective class loader.
 

Method Detail

getClassLoader

ClassLoader getClassLoader()
Returns a non-null reference to the effective class loader. The ClassLoader is used to directly and indirectly load classes associated with the agent, including its interfaces and task type (in order to verify accessibility), as well as generated classes.


defineClass

Class<?> defineClass(String name,
                     byte[] bytes)
Creates a class generated by an agent. See the documentation for the protected defineClass method of ClassLoader.

Parameters:
name - The class's fully qualified name.
bytes - The generated bytecodes for the class. The offset is 0, and the length is equal to bytes.length.


Copyright 2009-2011 Tom Landon
Apache License 2.0