use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.
the class QueryPerformanceTest method createConfigurationLayer.
private LayerAssembly createConfigurationLayer(ApplicationAssembly applicationAssembly) throws AssemblyException {
LayerAssembly layer = applicationAssembly.layer(LAYER_CONFIGURATION);
ModuleAssembly configModule = layer.module(MODULE_CONFIG);
configModule.entities(NativeConfiguration.class).visibleIn(Visibility.application);
new EntityTestAssembler().assemble(configModule);
return layer;
}
use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.
the class CompositeCreationPerformanceTest method newInstanceForRegisteredCompositePerformance.
@Test
public void newInstanceForRegisteredCompositePerformance() throws ActivationException, AssemblyException {
SingletonAssembler assembler = new SingletonAssembler() {
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
module.transients(AnyComposite.class);
module.objects(AnyObject.class);
module.values(AnyValue.class);
}
};
int loops = 2;
long t0 = 0;
{
for (int i = 0; i < loops; i++) {
t0 = t0 + testJavaObjectCreationPerformance();
}
t0 = t0 / loops;
}
long t1 = 0;
{
TransientBuilderFactory module = assembler.module();
for (int i = 0; i < loops; i++) {
t1 = t1 + testCompositeCreationPerformance(module);
}
t1 = t1 / loops;
}
long t2 = 0;
{
ObjectFactory objectFactory = assembler.module();
for (int i = 0; i < loops; i++) {
t2 = t2 + testObjectCreationPerformance(objectFactory);
}
t2 = t2 / loops;
}
long t3 = 0;
{
ValueBuilderFactory valueBuilderFactory = assembler.module();
for (int i = 0; i < loops; i++) {
t3 = t3 + testValueCreationPerformance(valueBuilderFactory);
}
t3 = t3 / loops;
}
long t4 = 0;
{
TransientBuilderFactory module = assembler.module();
for (int i = 0; i < loops; i++) {
t4 = t4 + testCompositeCreationWithBuilderPerformance(module);
}
t4 = t4 / loops;
}
long t6 = 0;
{
ValueBuilderFactory valueBuilderFactory = assembler.module();
for (int i = 0; i < loops; i++) {
t6 = t6 + testValueCreationWithBuilderPerformance(valueBuilderFactory);
}
t6 = t6 / loops;
}
System.out.println("Transient: " + (t1 / t0) + "x");
System.out.println("TransientBuilder: " + (t4 / t0) + "x");
System.out.println("Value: " + (t3 / t0) + "x");
System.out.println("ValueBuilder: " + (t6 / t0) + "x");
System.out.println("Object: " + (t2 / t0) + "x");
}
use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.
the class ObjectCreationPerformanceTest method newInstanceForRegisteredObjectPerformance.
@Test
public void newInstanceForRegisteredObjectPerformance() throws ActivationException, AssemblyException {
SingletonAssembler assembler = new SingletonAssembler() {
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
module.objects(AnyObject.class);
}
};
ObjectFactory objectFactory = assembler.module();
for (int i = 0; i < 10; i++) {
testPerformance(objectFactory);
}
}
use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.
the class ServiceInvocationPerformanceTest method testInjectService.
public void testInjectService() throws Exception {
SingletonAssembler assembly = new SingletonAssembler() {
@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
module.services(ServiceInvocationPerformanceTest.MyServiceComposite.class);
module.objects(ServiceInvocationPerformanceTest.class);
}
};
assembly.module().injectTo(this);
// Warmup
for (int i = 0; i < 60000; i++) {
service.test();
}
int rounds = 5;
for (int i = 0; i < rounds; i++) {
performanceCheck(service);
}
}
use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.
the class Main method main.
public static void main(String[] args) throws Exception {
SingletonAssembler assembler = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.transients(BoundPersonComposite.class);
module.transients(AddressTransient.class);
module.values(CityValue.class, CountryValue.class);
new SwingBindingAssembler().assemble(module);
}
};
module = assembler.module();
Address address1 = createAddress("Vista Damai", "Jalan Tun Razak");
Address address2 = createAddress("Mutiara", "Jalan Ceylon");
TransientBuilder<BoundPersonComposite> builder = module.newTransientBuilder(BoundPersonComposite.class);
PersonComposite prototype = builder.prototype();
prototype.address().set(address1);
prototype.firstName().set("Niclas");
final BoundPersonComposite p1 = builder.newInstance();
prototype.address().set(address2);
prototype.firstName().set("Edward");
final BoundPersonComposite p2 = builder.newInstance();
final StateModel<BoundPersonComposite> model = module.newObject(StateModel.class, BoundPersonComposite.class);
Form form = new Form<BoundPersonComposite>(model);
JFrame frame = new JFrame("testing");
frame.add(form, BorderLayout.CENTER);
JPanel checkBoxPanel = new JPanel();
checkBoxPanel.setFocusable(true);
checkBoxPanel.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
System.out.println("Gained!");
}
public void focusLost(FocusEvent e) {
System.out.println("LOst!");
}
});
JCheckBox sw = new JCheckBox("Toggle");
sw.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (((JCheckBox) e.getSource()).isSelected()) {
model.use(p1);
System.out.println(p1.firstName().get());
} else {
model.use(p2);
System.out.println(p2.firstName().get());
}
}
});
checkBoxPanel.add(sw);
frame.add(checkBoxPanel, BorderLayout.EAST);
frame.pack();
System.out.println(model);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
Aggregations