polygene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niclas Hedhman <nic...@hedhman.org>
Subject Re: Entity Store
Date Sun, 28 Aug 2016 00:50:18 GMT
In 2.1 and earlier, the assembly was quite tedious and error-prone. For the
'develop' branch (to become 3.0), we are working at making it easier.

1. The LayeredApplicationAssembler with its associated LayerAssembler and
ModuleAssembler, tries to make it a lot easier (and keep it a lot neater)
to create layered application assembly. See
https://zest.apache.org/java/2.1/core-bootstrap-assembly.html and find
section "Layered Application Assembler (RECOMMENDED)"

2. I am currently working on a Yeoman generator, which will set up the
application skeleton using the LayeredApplicationAssembler mentioned above.
Answer a couple of questions and you have a project structure, build system
and possibly an sample application created for you. This needs help to test
out and expand. See below what is generated at the moment, incl a "heroes"
webapp sample

3. In general, I am against scanning for classes, as it both slows
everything down and that it becomes unpredictable and fragile.

Ok, so for MongoDB you do two things,

1. You need to use an assembler and do something like this;
public class MongoDBStorageModule
    implements ModuleAssembler
    public static final String NAME = "MongoDB Storage Module";
    private final ModuleAssembly configModule;

    public MongoDBStorageModule( ModuleAssembly configModule )
        this.configModule = configModule;

    public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly
module )
        throws AssemblyException
        new MongoDBEntityStoreAssembler()
            .visibleIn( Visibility.application  )
            .withConfig( configModule, Visibility.application )
            .identifiedBy( "MongoDBstore" )
            .assemble( module );
        return module;
(The above is generated in my new Yeoman generator)

The identifiedBy("MongoDBstore") is the key to find the bootstrap
configuration for the service.
If you look at
org.apache.zest.entitystore.mongodb.MongoEntityStoreConfiguration it
contains the configuration that has been made available.
Configuration can be initialized from files in the classpath, and the
location is from the identifiedBy() above. We are trying to support
properties, json, yaml and xml files as the configuration bootstrap format.
So you could create a MongoDBstore.json file with the following content;

    "hostname" : "n1.hedhman.org",
    "port" : 27017,
    "username" : "mongo",
    "password" : "secret",
    "database" : "heroes_app",
    "collection" : "heroes",
    "writeConcern" : "NORMAL"

I just realize that the nodes() property in the configuration can probably
not be initialized from file at the moment, as it takes a ServerAddress
list as argument. That should be fixed...

A general note though; Be careful with MongoDB... It is not particularly
resilient to failures.

Hope this helps.


niclas-249:heroes2 niclas$ find .

On Sun, Aug 28, 2016 at 5:45 AM, Prince Arora <aroraprince151@gmail.com>

> Hi Everyone,
> I just started using zest and creating an application with MongoDB as data
> storage. I have gone through the documentations Its all good i understood
> the consent of application, mixins, concerns and all. But not sure how i
> can configure and entity store using Mongodb extension. How do i define the
> mongo connections configurations for Mongo assembler?
> I have gone through Zest core apis and documents and seems a good framework
> to develop applications. The only thing that can be a pain is the
> Application assembly. As the applications goes bigger the assembly will get
> more harder to manage for developers as we have to add all entities,
> concerns and everything we are using inside our application/module. Are we
> developing any configurations system to assemble applications or do we have
> one? And also we can make it easier if we add an option register these
> composites with package name. Like for entity one can give a package name
> where we can scan all the entities and register them for that module. It is
> just a suggestion though. Let me know what others think about this.
> I will keep working on this and will write if i find any other issue or
> suggestions. Since this is my first contribution to a open source project i
> will not be much of help in starting and plus i am also learning zest from
> scratch but i will try my best to contribute as much as i can.
> Thanks,

Niclas Hedhman, Software Developer
http://zest.apache.org - New Energy for Java

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message