Pentagaia toolbox - Start

Back to start-docs .

Class loading

We customize the class loading and provide additional interfaces that every extension can use to utilize the kernel. You may implement interface IPdsClassLoaderExtension to influence the class loading. You must have a look at the performance since class loading should be very fast.

But how does it work? First of all every kernel instance lives in its own namespace. In other words: Every kernel instance gets its own class loader instance. Some classes may be "global". That means they are visible from bootstrap class loader and they should be visible to multiple kernel instances. This can be useful if you want to access statics across multiple kernel instances. You can return a set of classes in method getGlobalClassSet . Return a complete class name to make a class global. Return a suffix .* to let a package be private. Return a suffix .** to let a package and all of the sub packages be private.

Whenever the class loader tries to load a class it will ask the extensions to do it. The method loadClassFirst to return the byte array that represents the class file. If no extensions returns a byte array for this class it will try to load the class file itself. It will have a look at the bootstrap jar files and at the jar files specified by configuration property com.pentagaia.tb.start.Boot.Path .

If this fails, we will ask the extensions again and invoke method loadClass . The reason why we provide two methods is simple: Some extensions may want to define the classes before the class loader looks for itself. That means the can replace even the pds kernel implementations. And other extensions may want to define classes after the class loader failed.

Now that we got the byte array we will invoke method refactorClass on every extension. This is a good point to "hack" the byte code that is used by a class. There may be several situations when you need this, f.e. if you are enabling AspectJ.

The class loading will provide a fallback. External class loader may define a class whenever the class loader failed. Implement loadClassExternal and delegate the class loading to your own custom class loader. But be aware of endless loops if you are routing back to the kernel's class loader. It will reask your extension to load the class externally. Pentagaia uses this method to route the call to the OSGi class loader.

There are several methods to find resources. But they should be familiar if you already know how to create/ use class loaders. They use the same semantics.