use of org.qi4j.bootstrap.AssemblyException in project qi4j-sdk by Qi4j.
the class RestServerAssembler method assemble.
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
Properties props = new Properties();
try {
props.load(getClass().getResourceAsStream("/velocity.properties"));
VelocityEngine velocity = new VelocityEngine(props);
module.importedServices(VelocityEngine.class).importedBy(INSTANCE).setMetaInfo(velocity);
} catch (Exception e) {
throw new AssemblyException("Could not load velocity properties", e);
}
freemarker.template.Configuration cfg = new freemarker.template.Configuration();
cfg.setClassForTemplateLoading(AbstractResponseWriter.class, "");
cfg.setObjectWrapper(new ValueCompositeObjectWrapper());
module.importedServices(freemarker.template.Configuration.class).setMetaInfo(cfg);
module.importedServices(MetadataService.class);
module.importedServices(ResponseWriterDelegator.class).identifiedBy("responsewriterdelegator").importedBy(NEW_OBJECT).visibleIn(Visibility.layer);
module.objects(ResponseWriterDelegator.class);
module.importedServices(RequestReaderDelegator.class).identifiedBy("requestreaderdelegator").importedBy(NEW_OBJECT).visibleIn(Visibility.layer);
module.objects(RequestReaderDelegator.class);
module.importedServices(InteractionConstraintsService.class).importedBy(NewObjectImporter.class).visibleIn(Visibility.application);
module.objects(InteractionConstraintsService.class);
// Standard response writers
Iterable<Class<?>> writers = ClassScanner.findClasses(DefaultResponseWriter.class);
Specification<Class<?>> responseWriterClass = isAssignableFrom(ResponseWriter.class);
Specification<Class<?>> isNotAnAbstract = not(hasModifier(Modifier.ABSTRACT));
Iterable<Class<?>> candidates = filter(and(isNotAnAbstract, responseWriterClass), writers);
for (Class<?> responseWriter : candidates) {
module.objects(responseWriter);
}
// Standard request readers
module.objects(DefaultRequestReader.class);
}
use of org.qi4j.bootstrap.AssemblyException in project qi4j-sdk by Qi4j.
the class Qi4jApplicationBootstrapListener method createNewApplication.
private Application createNewApplication(ServletContext context) {
Energy4Java qi4j = new Energy4Java();
// Try create assembler
final ApplicationAssembler assembler = createAssembler();
if (assembler != null) {
try {
return qi4j.newApplication(assembler);
} catch (AssemblyException e) {
throw new IllegalStateException(e);
}
}
return null;
}
use of org.qi4j.bootstrap.AssemblyException in project qi4j-sdk by Qi4j.
the class WebHttpShiroTest method assemble.
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
try {
ModuleAssembly configModule = module;
new EntityTestAssembler().assemble(configModule);
// START SNIPPET: assembly
new JettyServiceAssembler().withConfig(configModule, Visibility.layer).assemble(module);
// END SNIPPET: assembly
port = FreePortFinder.findFreePortOnLoopback();
JettyConfiguration config = module.forMixin(JettyConfiguration.class).declareDefaults();
config.hostName().set("127.0.0.1");
config.port().set(port);
// START SNIPPET: assembly
new HttpShiroAssembler().withConfig(configModule, Visibility.layer).assemble(module);
// END SNIPPET: assembly
configModule.forMixin(ShiroIniConfiguration.class).declareDefaults().iniResourcePath().set("classpath:web-shiro.ini");
} catch (IOException ex) {
throw new AssemblyException("Unable to find free port to bind to", ex);
}
}
use of org.qi4j.bootstrap.AssemblyException in project qi4j-sdk by Qi4j.
the class AbstractEntityStorePerformanceTest method whenCreateEntityWithComplexTypeInBatchThenRecordIterationsPerSecond.
@Test
public void whenCreateEntityWithComplexTypeInBatchThenRecordIterationsPerSecond() throws Exception {
try {
Assembler assembler = new Assembler() {
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
module.entities(ComplexProduct.class);
}
};
createQi4jRuntime(assembler);
profile(new Callable<Void>() {
@Override
public Void call() throws Exception {
Report report = new Report(storeName);
report.start("createEntityInBulkWithComplexType");
int bulk = 0;
UnitOfWork uow = module.newUnitOfWork(newUsecase("createEntityInBulkWithComplexType " + bulk));
for (int i = 0; i < ITERATIONS; i++) {
ComplexProduct product = uow.newEntity(ComplexProduct.class);
String id = product.identity().get();
if (i % 1000 == 0) {
uow.complete();
bulk++;
uow = module.newUnitOfWork(newUsecase("createEntityInBulkWithComplexType " + bulk));
}
}
uow.complete();
report.stop(ITERATIONS);
writeReport(report);
return null;
}
});
} finally {
cleanUp();
}
}
use of org.qi4j.bootstrap.AssemblyException in project qi4j-sdk by Qi4j.
the class AbstractEntityStorePerformanceTest method whenCreateEntityWithSinglePropertyInBatchThenRecordIterationsPerSecond.
@Test
public void whenCreateEntityWithSinglePropertyInBatchThenRecordIterationsPerSecond() throws Exception {
try {
Assembler assembler = new Assembler() {
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
module.entities(SimpleProduct.class);
}
};
createQi4jRuntime(assembler);
profile(new Callable<Void>() {
@Override
public Void call() throws Exception {
Report report = new Report(storeName);
report.start("createEntityInBulkWithSingleProperty");
int bulk = 0;
UnitOfWork uow = module.newUnitOfWork(newUsecase("createEntityInBulkWithSingleProperty " + bulk));
for (int i = 0; i < ITERATIONS; i++) {
SimpleProduct product = uow.newEntity(SimpleProduct.class);
String id = product.identity().get();
if (i % 1000 == 0) {
uow.complete();
bulk++;
uow = module.newUnitOfWork(newUsecase("createEntityInBulkWithSingleProperty " + bulk));
}
}
uow.complete();
report.stop(ITERATIONS);
writeReport(report);
return null;
}
});
} finally {
cleanUp();
}
}
Aggregations