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();
}
}
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);
}
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());
}
}
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
}
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);
}
Aggregations