Jodd
build: 305
updated: Apr 19 2008
 

SourceForge.net Logo

freebsd  Support this project

home Home | download | home Contact | SourceForge | File Releases releases | News news |  
Petite with Proxetta

Here is how to have Petite IoC container that can make proxies with Proxetta transparently.

PetiteContainer petite = new PetiteContainer() {

	Proxetta proxetta;
	
	@Override
	public void register(String name, Class type, Class scopeType) {
		type = Proxetta.defineProxy(type, pd4log);
		super.register(name, type, scopeType);
	}
};

 

Before the usage, proxetta field has to be populated with valid Proxetta instance that has some aspects assigned. Now, all beans registered in the Petite container will be automatically proxified. That is all.

Petite with source auto-compilation and run-time class replacement

Imagine developer that works on source files of Petite beans. Then, he starts the server or the application, Petite container wires all beans etc. Now, imagine that he is able to change existing source of wired beans, and let the Jodd do the rest: compiles new source, replaces class in the container and replace all its instances. Here is an example:

RuntimeJavaSourceLoader rtjsl =  new RuntimeJavaSourceLoader("...source path...", 1000);
final PetiteContainer petite = new PetiteContainer();
petite.setTrackBeanWiring(true);

petite.register(FooImpl.class);
petite.register(Goo.class);
petite.register(Boo.class);
petite.register(Zoo.class);

rtjsl.registerChangeListener(
	new RuntimeJavaSourceLoader.ChangeListener() {
		public void onCreate(Class type) {
			petite.replace(type);
		}
		public void onChange(Class newType) {
			petite.replace(newType);
		}
	}
);

Iterator<Class> i = petite.classIterator();
while (i.hasNext()) {
	rtjsl.attach(i.next());
}

First, new class loader is created that can monitor sources and automatically compiles new sources using current VM classpath. Then, Petite is created, some beans are manually added. Next step is to register new change listener that will be invoked when new class has been compiled successfully. When this happens, we have to simple replace class in Petite. The last thing is to attach classloader to existing classes, to know what to monitor.

Using this technique may speed up the development (and slow down the application itself;). However, one thing not possible: to change a class that doesn't implement a interface, because new classes will be loaded by new classloader and will not be the same with existing one, so wiring will fails. This only forks for leafs in tree of beans in the container, and only when they are accessed by introspection.