Search in sources :

Example 71 with ModuleAssembly

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;
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) NativeConfiguration(org.qi4j.library.rdf.repository.NativeConfiguration) LayerAssembly(org.qi4j.bootstrap.LayerAssembly)

Example 72 with ModuleAssembly

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");
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ObjectFactory(org.qi4j.api.object.ObjectFactory) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) ValueBuilderFactory(org.qi4j.api.value.ValueBuilderFactory) TransientBuilderFactory(org.qi4j.api.composite.TransientBuilderFactory) Test(org.junit.Test)

Example 73 with ModuleAssembly

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);
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ObjectFactory(org.qi4j.api.object.ObjectFactory) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 74 with ModuleAssembly

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);
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler)

Example 75 with ModuleAssembly

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);
}
Also used : JPanel(javax.swing.JPanel) SwingBindingAssembler(org.qi4j.lib.swing.binding.SwingBindingAssembler) ActionEvent(java.awt.event.ActionEvent) FocusEvent(java.awt.event.FocusEvent) JCheckBox(javax.swing.JCheckBox) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) FocusListener(java.awt.event.FocusListener)

Aggregations

ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)191 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)87 Test (org.junit.Test)82 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)59 AssemblyException (org.qi4j.bootstrap.AssemblyException)27 Application (org.qi4j.api.structure.Application)26 OrgJsonValueSerializationAssembler (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler)24 Assembler (org.qi4j.bootstrap.Assembler)23 Module (org.qi4j.api.structure.Module)19 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)15 Before (org.junit.Before)12 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)12 Energy4Java (org.qi4j.bootstrap.Energy4Java)12 DataSourceAssembler (org.qi4j.library.sql.assembly.DataSourceAssembler)11 DBCPDataSourceServiceAssembler (org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler)9 IOException (java.io.IOException)8 ApplicationAssemblerAdapter (org.qi4j.bootstrap.ApplicationAssemblerAdapter)8 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)8 File (java.io.File)7 OrgJsonValueSerializationService (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationService)7