ApplicationBuilder anyone??

12 views
Skip to first unread message

Niclas Hedhman

unread,
Dec 20, 2013, 1:18:28 AM12/20/13
to qi4j...@googlegroups.com

Hi, 
I have just created a nice little generic ApplicationBuilder, which simplifies the creation of Application Structure, either by a more fluid DSL or from a JSON file.

ApplicationBuilder builder = new ApplicationBuilder("Test App");

builder.withLayer( "interface layer" )
    .uses( "model layer" )
    .withModule( "rest module" )
    .withAssembler( assembler )

and so on... (where assembler is an instance, Class or class name).

It also has a 

Application app = ApplicationBuilder.fromJson( json );

and a "public static void main( String[] args )" that takes Json from System.in.

Json can be seen below....


So, shall I integrate this into core/bootstrap ???


{
    "name": "Build from JSON test.",
    "layers": [
        {
            "name": "layer1",
            "uses": [ "layer2", "layer3"]
        },
        {
            "name": "layer2"
        },
        {
            "name": "layer3",
            "modules" : [
                {
                    "name" : "test module",
                    "assemblers" : [
                            "org.qi4j.bootstrap.builder.ApplicationBuilderTest.TestServiceAssembler"
                    ]
                }
            ]
        }
    ]
}

--
Niclas Hedhman, Software Developer
河南南路555弄15号1901室。
http://www.qi4j.org - New Energy for Java

I live here; http://tinyurl.com/3xugrbk
I work here; http://tinyurl.com/6a2pl4j
I relax here; http://tinyurl.com/2cgsug

Jiri Jetmar

unread,
Dec 20, 2013, 3:21:45 AM12/20/13
to Niclas Hedhman, qi4j...@googlegroups.com
Hello Niclas, 

thanks ! I would argue to put it to the Qi4j code base. I;m using a similar concept to "bake" Test applications where a
main() is required. 

Cheers,
Jiri


2013/12/20 Niclas Hedhman <nic...@hedhman.org>

--
You received this message because you are subscribed to the Google Groups "qi4j-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qi4j-dev+u...@googlegroups.com.
To post to this group, send email to qi4j...@googlegroups.com.
Visit this group at http://groups.google.com/group/qi4j-dev.
For more options, visit https://groups.google.com/groups/opt_out.

Paul Merlin

unread,
Dec 20, 2013, 5:16:20 AM12/20/13
to qi4j...@googlegroups.com
Niclas,

Niclas Hedhman a écrit :
We really need such an ApplicationBuilder!
It definitely belongs in core/bootstrap.

One thing to take into account will be configuration
assembly. If an assembly contains ConfigurationEntities
(several do) it then needs two target modules (hence two
visibilities).

How would the DSL and JSON formats support this ?
 

/Paul

Niclas Hedhman

unread,
Dec 20, 2013, 7:56:07 AM12/20/13
to Paul Merlin, qi4j...@googlegroups.com

Ah, it doesn't. Makes things far too complicated and I don't want to create a new Spring.

Instead, what I am doing in my own app is this,

public class EntityStoreAssembler extends NavigatableAssembler
    implements Assembler
{
    @Override
    public void assemble( ModuleAssembly module )
        throws AssemblyException
    {
        ModuleAssembly configModule = find( module, ConfigLayerAssembly.NAME, InfraConfigModule.NAME  );
        new LevelDBEntityStoreAssembler()
            .visibleIn( Visibility.application )
            .withConfig( configModule, Visibility.application )
            .identifiedBy( "storage" )
            .assemble( module );
    }
}

And the "find()" method sits in the superclass, but could just have been in a static utility


    protected ModuleAssembly find( ModuleAssembly current, String layer, String module )
    {
        return current.layer().application().layer( layer ).module(  module );
    }


I have still not come to terms with the 'granularity' of these wrapping Assemblers, whether they should be small or large, the entire module or each chunk of functionality.

I am also trying to figure out how I can do this modular enough, so I can put each "function" in a different sub-project, and have it assembled nicely in some aggregate.


Niclas


--
You received this message because you are subscribed to the Google Groups "qi4j-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qi4j-dev+u...@googlegroups.com.
To post to this group, send email to qi4j...@googlegroups.com.
Visit this group at http://groups.google.com/group/qi4j-dev.
For more options, visit https://groups.google.com/groups/opt_out.

Paul Merlin

unread,
Dec 20, 2013, 11:33:35 AM12/20/13
to qi4j...@googlegroups.com
Niclas Hedhman a écrit :
> Ah, it doesn't. Makes things far too complicated and I don't want to
> create a new Spring.
>
> Instead, what I am doing in my own app is this,
>
> public class EntityStoreAssembler extends NavigatableAssembler
> implements Assembler
> {
> @Override
> public void assemble( ModuleAssembly module )
> throws AssemblyException
> {
> ModuleAssembly configModule = find( module,
> ConfigLayerAssembly.NAME, InfraConfigModule.NAME );
> new LevelDBEntityStoreAssembler()
> .visibleIn( Visibility.application )
> .withConfig( configModule, Visibility.application )
> .identifiedBy( "storage" )
> .assemble( module );
> }
> }
>
> And the "find()" method sits in the superclass, but could just have
> been in a static utility
>
>
> protected ModuleAssembly find( ModuleAssembly current, String
> layer, String module )
> {
> return current.layer().application().layer( layer ).module(
> module );
> }
That's a nice way of doing it, simple and effective!
Ok for staying away of complexity.
A static utility seems more appropriate.

Cheers

/Paul


Niclas Hedhman

unread,
Dec 20, 2013, 8:07:11 PM12/20/13
to Paul Merlin, qi4j...@googlegroups.com
So, you think we should put in the find() method into Qi4j as well??

If so, wouldn't it make most sense to put it into ModuleAssembly?

    ModuleAssembly configModule = module.find( "layer", "module" );




/Paul


--
You received this message because you are subscribed to the Google Groups "qi4j-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qi4j-dev+unsubscribe@googlegroups.com.

To post to this group, send email to qi4j...@googlegroups.com.
Visit this group at http://groups.google.com/group/qi4j-dev.
For more options, visit https://groups.google.com/groups/opt_out.

Paul Merlin

unread,
Dec 21, 2013, 3:57:49 AM12/21/13
to qi4j...@googlegroups.com
Niclas Hedhman a écrit :
So, you think we should put in the find() method into Qi4j as well??

If so, wouldn't it make most sense to put it into ModuleAssembly?

    ModuleAssembly configModule = module.find( "layer", "module" );
Looks like a good place for it, yes.

Paul Merlin

unread,
Dec 23, 2013, 8:45:27 AM12/23/13
to qi4j...@googlegroups.com
Niclas,

I have used the ApplicationBuilder to write PassivationExceptionTest
and needed it to create a non-activated Application.

I pushed a commit (17a0f42188cb9b4f22d0244ccfcbd0784bf89773) that
make newApplication() return a non-activated Application and
add a method to create and activate an Application:

Application passive = builder.newApplication();
Application activated = builder.newActivatedApplication();

This, while still honoring existing beforeActivation() and
afterActivation() protected methods intended for inheritance.
As we already have ActivationEvents and Activators, I wonder if
thoses protected methods in ApplicationBuilder should be
removed. WDYT?


Niclas Hedhman a écrit :
So, you think we should put in the find() method into Qi4j as well??

If so, wouldn't it make most sense to put it into ModuleAssembly?

    ModuleAssembly configModule = module.find( "layer", "module" );
I added both:
- ModuleAssembly aModule = applicationAssembly.module( "layer", "module" );
- ModuleAssembly aModule = moduleAssembly.module( "layer", "module" );

I did not name it "find" as, like other assembly methods it create the
ModuleAssembly on demand (ad0cadd57d93f9618bc3f0f666936eb099f47bf6).

/Paul

Paul Merlin

unread,
Jan 5, 2014, 7:15:31 AM1/5/14
to qi4j...@googlegroups.com
Niclas,

Niclas Hedhman a écrit :
> Can you explain the usecase of a non-Activated application, where the
> builder override is not suitable??
I needed to register an ActivationEventListener before application
activation. I reverted my changes to ApplicationBuilder and made
it implements ActivationEventListenerRegistration so listeners can
be registered before creating the Application.

> As for the findModule() vs module() --> yes, an "interesting" side
> effect is that if the module doesn't exist it will be created.
Sure, as with other parts of Assembly. This is clearly stated in
the javadoc.

Cheers

/Paul

Reply all
Reply to author
Forward
0 new messages