Get Nuts Rolling

Prepare

Starting up Nuts in Java is simple.
You need to make sure the following jar files are in the classpath:

  • jfunutil.jar
  • yan.jar
  • xml-apis.jar

Wire up

Then, call the jfun.yan.xml.NutsProcessor class to start up:

final NutsProcessor processor = new NutsProcessor();
processor.processFile("myapp_nuts.xml");

//now instantiate the components
final Container container = processor.getContainer();
final TopLevelApplication app = (TopLevelApplication)container.getInstance("application");

The above code assumes that the top level application object is named "application". Of course, the naming convention is all up to you.
By instantiating this object, the entire object graph should have been initialized and wired up properly.

Instantiate eagerly initialized components

Nuts support eager-initialization via the "eager-init" attribute. Any global components marked as eager-init="true" is going to be eagerly instantiated even when it is not exported by the module.

The NutsProcessor.preInstantiate() method is responsible for instantiating these eager components.

The simplest form to instantiate eager components is:

processor.preInstantiate();

This method has other overloaded versions to allow instantiation with dependencies resolved in an alternative container. For example, we may use a container hierarchy to resolve dependencies:

pocessor.preInstantiate(processor.getContainer().inherit(some_parent_container));

Start up

processor.getLifecycleManager().start();

Stop it

processor.getLifecycleManager().stop();

Aloha and Clean up.

processor.getLifecycleManager().dispose();

Labels

 
(None)