At this point, where an ApplicationInstance exists, it is possible to initialize the application components with instances created in, data computed in or received from, the controlling bootstrap code.
Once the initialization phase is complete, the bootstrap controller will call the ApplicationInstance.activate() method to start things up.
Recap of sequence;
ObjectBuilderFactory factory = assembly.getObjectBuilderFactory();
Stuff stuff = factory.newObjectBuilder( Stuff.class ).newInstance();
public static void Main( String[] args )
{
instance = new Main();
instance.setUp();
// assuming some code has a non-daemon thread.
}
private void setUp()
{
Qi4jRuntime is = new Energy4Java();
runtime = is;
ApplicationAssemblyFactory assemblyFactory =
new ApplicationAssemblyFactory();
ApplicationFactory factory =
new ApplicationFactory( runtime, assemblyFactory );
ApplicationAssembly app = createAssembly( assemblyFactory );
ApplicationContext context = factory.newApplication( assembly );
String applicationName = "Example Application";
ApplicationInstance instance =
context.newApplicationInstance( applicationName );
}
private ApplicationAssembly createAssembly(
ApplicationAssemblyFactory factory )
{
ApplicationAssembly app = factory.newApplicationAssembly();
LayerAssembly webLayer = createWebLayer( app );
LayerAssembly domainLayer = createDomainLayer( app );
LayerAssembly infraLayer = createInfrastructureLayer( app );
webLayer.uses( domainLayer );
webLayer.uses( infraLayer ); // Accesses the WebService
domainLayer.uses( infraLayer ); // For persistence
return app;
}
private LayerAssembly createWebLayer(
ApplicationAssembly application )
{
LayerAssembly layer = application.newLayerAssembly();
createCustomerWebModule( layer );
return layer;
}
private LayerAssembly createDomainLayer(
ApplicationAssembly application )
{
LayerAssembly layer = application.newLayerAssembly();
createCustomerDomainModule( layer );
// :
// :
return layer;
}
private LayerAssembly createInfrastructureLayer(
ApplicationAssembly application )
{
LayerAssembly layer = application.newLayerAssembly();
createWebServiceModule( layer );
createPersistenceModule( layer );
return layer;
}
private void createCustomerWebModule( LayerAssembly layer )
{
ModuleAssembly assembly = layer.newModuleAssembly();
assembly.addComposites( CustomerViewComposite.class );
assembly.addComposites( CustomerEditComposite.class );
assembly.addComposites( CustomerListViewComposite.class );
assembly.addComposites( CustomerSearchComposite.class );
}
private void createCustomerDomainModule( LayerAssembly layer )
{
ModuleAssembly assembly = layer.newModuleAssembly();
assembly.addEntities( CustomerEntity.class );
assembly.addEntities( CountryEntity.class );
assembly.addComposites( AddressComposite.class );
}
private void createWebServiceModule( LayerAssembly layer )
{
ModuleAssembly assembly = layer.newModuleAssembly();
// Someone has created an assembler for a Jetty Web Service.
JettyAssembler jetty = new JettyAssembler( 8080 );
assembly.addAssembler( neo );
}
private void createPersistenceModule( LayerAssembly layer )
{
ModuleAssembly assembly = layer.newModuleAssembly();
// Someone has created an assembler for the Neo EntityStore
NeoAssembler neo = new NeoAssembler( "./neostore" );
assembly.addAssembler( neo );
}
}