Search in sources :

Example 56 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.

the class CircuitBreakerManagementSample method main.

public static void main(String[] args) throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        @Override
        public // START SNIPPET: jmx
        void assemble(ModuleAssembly module) throws AssemblyException {
            // END SNIPPET: jmx
            CircuitBreaker cb = new CircuitBreaker(3, 250, CircuitBreakers.in(IllegalArgumentException.class));
            module.importedServices(TestService.class).setMetaInfo(new TestService(cb));
            // START SNIPPET: jmx
            // JMX Library
            module.importedServices(MBeanServer.class).importedBy(MBeanServerImporter.class);
            // CircuitBreakers in JMX
            module.services(CircuitBreakerManagement.class).instantiateOnStartup();
        }
    };
    TestService service = assembler.module().<TestService>findService(TestService.class).get();
    // Seconds
    int interval = 1;
    System.out.println("CircuitBreaker JMX Support sample is now started.");
    System.out.println();
    System.out.println("A Service that randomly output some text or fail is called through a CircuitBreaker every " + interval + " seconds.");
    System.out.println("In a few interval the CircuitBreaker will be turned off.");
    System.out.println("Connect with a MBean browser (eg. VisualVM + MBean plugin) to use the turnOn operation on the CircuitBreakers.");
    System.out.println();
    System.out.println("Hit Ctrl-C to stop.");
    System.out.println();
    while (true) {
        try {
            Thread.sleep(interval * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        service.helloWorld();
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) CircuitBreaker(org.qi4j.library.circuitbreaker.CircuitBreaker) ServiceCircuitBreaker(org.qi4j.library.circuitbreaker.service.ServiceCircuitBreaker) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) MBeanServer(javax.management.MBeanServer)

Example 57 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.

the class MutualSecureJettyServiceTest method assemble.

@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
    ModuleAssembly configModule = module;
    new EntityTestAssembler().assemble(configModule);
    new SecureJettyServiceAssembler().withConfig(configModule, Visibility.layer).assemble(module);
    // START SNIPPET: config
    SecureJettyConfiguration config = configModule.forMixin(SecureJettyConfiguration.class).declareDefaults();
    config.hostName().set("127.0.0.1");
    config.port().set(HTTPS_PORT);
    config.keystorePath().set(SERVER_KEYSTORE_PATH);
    config.keystoreType().set("JCEKS");
    config.keystorePassword().set(KS_PASSWORD);
    config.truststorePath().set(TRUSTSTORE_PATH);
    config.truststoreType().set("JCEKS");
    config.truststorePassword().set(KS_PASSWORD);
    config.wantClientAuth().set(Boolean.TRUE);
    // END SNIPPET: config
    addServlets(serve("/hello").with(HelloWorldServletService.class)).to(module);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) EntityTestAssembler(org.qi4j.test.EntityTestAssembler)

Example 58 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.

the class EventsTest method testData.

@Before
public void testData() throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.values(UnitOfWorkDomainEventsValue.class, DomainEventValue.class);
        }
    };
    list = new ArrayList<UnitOfWorkDomainEventsValue>();
    {
        ValueBuilder<UnitOfWorkDomainEventsValue> builder = assembler.module().newValueBuilder(UnitOfWorkDomainEventsValue.class);
        builder.prototype().events().get().add(newDomainEvent(assembler, "Test1"));
        builder.prototype().events().get().add(newDomainEvent(assembler, "Test2"));
        builder.prototype().events().get().add(newDomainEvent(assembler, "Test3"));
        builder.prototype().version().set("1.0");
        builder.prototype().timestamp().set(System.currentTimeMillis());
        builder.prototype().usecase().set("Test");
        list.add(builder.newInstance());
    }
    {
        ValueBuilder<UnitOfWorkDomainEventsValue> builder = assembler.module().newValueBuilder(UnitOfWorkDomainEventsValue.class);
        builder.prototype().events().get().add(newDomainEvent(assembler, "Test4"));
        builder.prototype().events().get().add(newDomainEvent(assembler, "Test5"));
        builder.prototype().events().get().add(newDomainEvent(assembler, "Test6"));
        builder.prototype().version().set("1.0");
        builder.prototype().timestamp().set(System.currentTimeMillis());
        builder.prototype().usecase().set("Test2");
        list.add(builder.newInstance());
    }
}
Also used : ValueBuilder(org.qi4j.api.value.ValueBuilder) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) UnitOfWorkDomainEventsValue(org.qi4j.library.eventsourcing.domain.api.UnitOfWorkDomainEventsValue) Before(org.junit.Before)

Example 59 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.

the class SecureJettyServiceTest method assemble.

@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
    ModuleAssembly configModule = module;
    new EntityTestAssembler().assemble(configModule);
    // START SNIPPET: assemblyssl
    new SecureJettyServiceAssembler().withConfig(configModule, Visibility.layer).assemble(module);
    // END SNIPPET: assemblyssl
    // START SNIPPET: configssl
    SecureJettyConfiguration config = configModule.forMixin(SecureJettyConfiguration.class).declareDefaults();
    config.hostName().set("127.0.0.1");
    config.port().set(HTTPS_PORT);
    config.keystorePath().set(SERVER_KEYSTORE_PATH);
    config.keystoreType().set("JCEKS");
    config.keystorePassword().set(KS_PASSWORD);
    // END SNIPPET: configssl
    // START SNIPPET: assemblyssl
    addServlets(serve("/hello").with(HelloWorldServletService.class)).to(module);
    addFilters(filter("/*").through(UnitOfWorkFilterService.class).on(REQUEST)).to(module);
// END SNIPPET: assemblyssl
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) EntityTestAssembler(org.qi4j.test.EntityTestAssembler)

Example 60 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.

the class VirtualHostJettyServiceTest method assemble.

@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
    ModuleAssembly configModule = module;
    new EntityTestAssembler().assemble(configModule);
    new JettyServiceAssembler().withConfig(configModule, Visibility.layer).assemble(module);
    SecureJettyConfiguration config = configModule.forMixin(SecureJettyConfiguration.class).declareDefaults();
    config.hostName().set("127.0.0.1");
    config.port().set(HTTP_PORT);
    config.virtualHosts().set(HOST1 + "," + HOST2);
    addServlets(serve("/hello").with(HelloWorldServletService.class)).to(module);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) EntityTestAssembler(org.qi4j.test.EntityTestAssembler)

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