Hi,
I've created a new class:
public class CustomMongoMapEntityStoreAssembler extends
Assemblers.VisibilityIdentityConfig<CustomMongoMapEntityStoreAssembler>
{
@Override
public void assemble(ModuleAssembly module) throws AssemblyException
{
module.services(UuidIdentityGeneratorService.class)
.visibleIn(visibility());
ServiceDeclaration service =
module.services(MongoMapEntityStoreService.class)
.withConcerns(MongoEntityStoreConfigurationConcern.class)
.visibleIn(visibility());
if (hasIdentity()) {
service.identifiedBy(identity());
}
if (hasConfig()) {
configModule().entities(MongoEntityStoreConfiguration.class)
.visibleIn(configVisibility());
}
}
}
and then a concern as you suggest:
public abstract class MongoEntityStoreConfigurationConcern
extends ConcernOf<Configuration<MongoEntityStoreConfiguration>>
implements Configuration<MongoEntityStoreConfiguration>
{
@Override
public MongoEntityStoreConfiguration get()
{
try {
MongoEntityStoreConfiguration conf = next.get();
List<ServerAddress> serverAddresses = new ArrayList<>();
serverAddresses.add(new ServerAddress("1.1.1.5", 27017));
serverAddresses.add(new ServerAddress("1.1.1.6", 27017));
serverAddresses.add(new ServerAddress("1.1.1.7", 27017));
conf.nodes()
.set(serverAddresses);
return conf;
}
catch (UnknownHostException err) {
throw new RuntimeException(err);
}
}
}
and I called it as:
new
CustomMongoMapEntityStoreAssembler().withConfig(configModule,
Visibility.application)
.visibleIn(Visibility.application)
.identifiedBy("mongodb.booking.store")
.assemble(module);
But then I get back the following error:
org.qi4j.bootstrap.AssemblyException: Unable to create Application Model.
at
org.qi4j.bootstrap.Energy4Java.newApplicationModel(Energy4Java.java:76)
at org.qi4j.bootstrap.Energy4Java.newApplication(Energy4Java.java:83)
at
com.projectbeagle.gateway.kernel.scope.wiring.ApplicationPool.fillUp(ApplicationPool.java:74)
... 47 more
Caused by: org.qi4j.api.common.InvalidApplicationException: Could not register
[interface org.qi4j.entitystore.mongodb.MongoMapEntityStoreService]
at
org.qi4j.runtime.bootstrap.ServiceAssemblyImpl.newServiceModel(ServiceAssemblyImpl.java:74)
at
org.qi4j.runtime.bootstrap.ModuleAssemblyImpl.assembleModule(ModuleAssemblyImpl.java:544)
at
org.qi4j.runtime.bootstrap.ApplicationModelFactoryImpl.newApplicationModel(ApplicationModelFactoryImpl.java:86)
at
org.qi4j.bootstrap.Energy4Java.newApplicationModel(Energy4Java.java:72)
... 49 more
Caused by: java.lang.ClassCastException:
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to
java.lang.Class
at
org.qi4j.runtime.injection.DependencyModel.extractRawInjectionClass(DependencyModel.java:132)
at
org.qi4j.runtime.injection.DependencyModel.extractRawInjectionClass(DependencyModel.java:119)
at
org.qi4j.runtime.injection.DependencyModel.<init>(DependencyModel.java:96)
at
org.qi4j.runtime.injection.InjectedFieldsModel.addModel(InjectedFieldsModel.java:81)
at
org.qi4j.runtime.injection.InjectedFieldsModel.<init>(InjectedFieldsModel.java:56)
at
org.qi4j.runtime.composite.AbstractModifierModel.<init>(AbstractModifierModel.java:57)
at org.qi4j.runtime.composite.ConcernModel.<init>(ConcernModel.java:27)
at
org.qi4j.runtime.bootstrap.AssemblyHelper.getConcernModel(AssemblyHelper.java:52)
at
org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.concernsFor(CompositeAssemblyImpl.java:591)
at
org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.implementMixinType(CompositeAssemblyImpl.java:215)
at
org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.buildComposite(CompositeAssemblyImpl.java:181)
at
org.qi4j.runtime.bootstrap.ServiceAssemblyImpl.newServiceModel(ServiceAssemblyImpl.java:64)
... 52 more
Στις 3:29 μ.μ. Παρασκευή, 5 Μαΐου 2017, ο/η Niclas Hedhman
<[email protected]> έγραψε:
Yes, the registration of values(ServerAddress.class) should not be there.
That was an oversight on my behalf.
A few things that could be a work-around.
1. Create a Concern that intercepts the configuration and populates the
nodes. You add the Concern in your own Assembler (copy source from
MongoDbEntityStoreAssembler), so instead of;
ServiceDeclaration service = module
.services( MongoMapEntityStoreService.class )
.visibleIn( visibility() );
add the Concern as;
ServiceDeclaration service = module
.services( MongoMapEntityStoreService.class )
.withConcerns( MyConfigurationConcern.class )
.visibleIn( visibility() );
Then your MyConfigurationConcern would be something like;
public abstract class MyConfigurationConcern extends
ConcernOf<Configuration<MongoEntityStoreConfiguration>>
implements Configuration<MongoEntityStoreConfiguration>
{
@Override
public MongoEntityStoreConfiguration get()
{
MongoEntityStoreConfiguration conf = next.get();
conf.nodes().set( MY_NODES );
return conf;
}
}
2. Maybe you want your own Configuration store. Create (or use) an Entity
Store that does not require any Polygene Configuration, and drop that into
the Configuration Module. Perhaps read configuration from "Java
Preferences", maybe a configured Zookeeper cluster or maybe ETCD. And if
the configuration entity store is populated, then there will be no fallback
to properties/yaml files.
This is of course a fairly advanced option, but I would recommend it for
production setup.
But I am sure Paul will say; "Just ..." :-)
Cheers
Niclas
On Fri, May 5, 2017 at 7:55 PM, Apostolos Krionidis <[email protected]>
wrote:
> Yes you are right ServerAddress is a Immutable POJO but here the problem
> seems to by before
> json serialization, in ValueComposite registration.
>
> Is there any other way to set prices in the nodes() property after the
> .property file loading?
>
>
>
>
> Στις 2:44 μ.μ. Παρασκευή, 5 Μαΐου 2017, ο/η Niclas Hedhman <
> [email protected]> έγραψε:
>
>
> Of course... ServerAddress is a pojo, and it doesn't have a POJO
> compatible format for Jackson et al.
>
> Paul, how was this supposed to work?
>
> Cheers
>
>
> --
> Niclas Hedhman, Software Developer
> http://polygene.apache.org - New Energy for Java
>
>
>
--
Niclas Hedhman, Software Developer
http://polygene.apache.org - New Energy for Java