Search in sources :

Example 1 with TransientBuilderFactory

use of org.qi4j.api.composite.TransientBuilderFactory 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 2 with TransientBuilderFactory

use of org.qi4j.api.composite.TransientBuilderFactory in project qi4j-sdk by Qi4j.

the class HelloWorldTest method setUp.

@Before
public void setUp() throws Exception {
    SingletonAssembler assembly = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(HelloWorldComposite.class);
        }
    };
    TransientBuilderFactory builderFactory = assembly.module();
    TransientBuilder<HelloWorldComposite> builder = builderFactory.newTransientBuilder(HelloWorldComposite.class);
    builder.prototype().name().set("Hello");
    builder.prototype().phrase().set("World");
    helloWorld = builder.newInstance();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) TransientBuilderFactory(org.qi4j.api.composite.TransientBuilderFactory) Before(org.junit.Before)

Example 3 with TransientBuilderFactory

use of org.qi4j.api.composite.TransientBuilderFactory in project qi4j-sdk by Qi4j.

the class HelloWorldTest method setUp.

@Before
public void setUp() throws Exception {
    SingletonAssembler assembly = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(HelloWorldComposite.class);
        }
    };
    TransientBuilderFactory builderFactory = assembly.module();
    TransientBuilder<HelloWorldComposite> builder = builderFactory.newTransientBuilder(HelloWorldComposite.class);
    builder.prototype().name().set("Hello");
    builder.prototype().phrase().set("World");
    helloWorld = builder.newInstance();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) TransientBuilderFactory(org.qi4j.api.composite.TransientBuilderFactory) Before(org.junit.Before)

Aggregations

TransientBuilderFactory (org.qi4j.api.composite.TransientBuilderFactory)3 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)3 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)3 Before (org.junit.Before)2 Test (org.junit.Test)1 ObjectFactory (org.qi4j.api.object.ObjectFactory)1 ValueBuilderFactory (org.qi4j.api.value.ValueBuilderFactory)1