javax.enterprise.inject.se.SeContainer Java Examples

The following examples show how to use javax.enterprise.inject.se.SeContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MeecrowaveSeContainerInitializer.java    From openwebbeans-meecrowave with Apache License 2.0 6 votes vote down vote up
@Override
protected SeContainer newContainer(final WebBeansContext context) {
    final Meecrowave meecrowave = new Meecrowave(builder);
    if (!services.containsKey(ContextsService.class.getName())) { // forced otherwise we mess up the env with owb-se
        context.registerService(ContextsService.class, new WebContextsService(context));
    }
    return new OWBContainer(context, meecrowave) {
        {
            meecrowave.bake();
        }

        @Override
        protected void doClose() {
            meecrowave.close();
        }
    };
}
 
Example #2
Source File: Task.java    From Java-EE-8-and-Angular with MIT License 6 votes vote down vote up
public static void main(String... args) {
    try (SeContainer container = SeContainerInitializer
            .newInstance().initialize()) {
        Task appInstance = container
                .select(Task.class)
                .get();
        //Test normal CDI
        appInstance.useInjected();
        
        //Test programmatic approach using RequestContextController
        //For each of below requests a new LoginBean is injected
        appInstance.doWorkInRequest("programmatic");            
        appInstance.doWorkInRequest("programmatic");
        
        //Test annotation approach using @ActivateRequestContext
        //For each of below requests a new LoginBean is injected
        appInstance.doWorkInRequest();
        appInstance.doWorkInRequest();
    }
}
 
Example #3
Source File: DemoApplication.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    SeContainerInitializer containerInit = SeContainerInitializer.newInstance();
    SeContainer container = containerInit.initialize();

    TestService testService = container.select(TestService.class).get();

    testService.test();

    System.out.println(testService.hello(-1));
    System.out.println(testService.hello(1));

    System.out.println(testService.helloAnother("bad"));

    try {
        System.out.println(testService.helloAnother("foo"));
    } catch (IllegalStateException e) {
        System.err.println(e.getMessage());
    }

    System.out.println(testService.helloAnother("weld"));

    container.close();
    System.exit(0);
}
 
Example #4
Source File: AccountApplication.java    From cdi with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) {
    SeContainerInitializer initializer = SeContainerInitializer.newInstance();

    try (SeContainer container = initializer.initialize()) {
        container.select(AccountApplication.class).get().run();
    }
}
 
Example #5
Source File: App.java    From Java-EE-8-and-Angular with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    try (SeContainer container = SeContainerInitializer
            .newInstance().initialize()) {
        App appInstance = container
                .select(App.class)
                .get();
        appInstance.doCRUD();
    }
}
 
Example #6
Source File: CdiTest.java    From Java-EE-8-and-Angular with MIT License 5 votes vote down vote up
@Test
public void injection_test() {
    try (SeContainer container = SeContainerInitializer.newInstance().initialize()) {
        CdiTest appInstance = container.select(CdiTest.class).get();
        String msg = appInstance.doSomething();

        assertNotNull(msg);
    }
}
 
Example #7
Source File: AccountService.java    From Java-EE-8-and-Angular with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    try (SeContainer container = SeContainerInitializer
            .newInstance().initialize()) {
        AccountService appInstance = container
                .select(AccountService.class)
                .get();
        
        appInstance.login(1,"AG007");
        appInstance.login(2,"AG007");
        //3rd event should lock account and then send SMS
        appInstance.login(3,"AG007");
    }
}
 
Example #8
Source File: Test.java    From Java-EE-8-and-Angular with MIT License 5 votes vote down vote up
public static void main(String... args) {
    try (SeContainer container = SeContainerInitializer
            .newInstance().initialize()) {
        Test appInstance = container
                .select(Test.class)
                .get();
        //Invoke action which raises an event that an observer listens to
        appInstance.doSomething();
    }
}
 
Example #9
Source File: BootCDI.java    From Java-EE-8-and-Angular with MIT License 5 votes vote down vote up
public static void main(String... args) {
    //Use try-with-resources for closing the SeContainer instance
    try (SeContainer container = SeContainerInitializer
            .newInstance().initialize()) {
        //Lookup the BootCDI instance by its type.
        BootCDI appInstance = container
                .select(BootCDI.class)
                .get();
        //Once BootCDI instance is obtained we can invoke its methods
        appInstance.doSomething();
    }
}
 
Example #10
Source File: Test.java    From Java-EE-8-and-Angular with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    try (SeContainer container = SeContainerInitializer
            .newInstance().initialize()) {
        Test appInstance = container
                .select(Test.class)
                .get();

        appInstance.doWork();
    }
}
 
Example #11
Source File: TestDynamicQualifier.java    From Java-EE-8-and-Angular with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    try (SeContainer container = SeContainerInitializer
            .newInstance().initialize()) {
        Test appInstance = container
                .select(Test.class)
                .get();

        appInstance.doWork();
    }
}
 
Example #12
Source File: GreeterTest.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
@Test
public void bootBasicContainer() {
    SeContainerInitializer initializer = SeContainerInitializer.newInstance();
    try (SeContainer container = initializer.initialize()) {
        assertTrue(container.isRunning());
        Set<Bean<?>> greeters = container.getBeanManager().getBeans("greeter");
        assertTrue(greeters.size() == 1);
    }
}
 
Example #13
Source File: PublisherShapeTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private void assertThatProducerWasPublished(SeContainer container) {
    assertThat(registry(container).getIncomingNames()).contains("producer");
    List<PublisherBuilder<? extends Message<?>>> producer = registry(container).getPublishers("producer");
    assertThat(producer).isNotEmpty();
    List<String> list = producer.get(0).map(Message::getPayload)
            .map(i -> (String) i)
            .toList().run().toCompletableFuture().join();
    assertThat(list).containsExactly("a", "b", "c");
}
 
Example #14
Source File: SubscriberShapeTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void assertThatSubscriberWasPublished(SeContainer container) {
    assertThat(registry(container).getOutgoingNames()).contains("subscriber");
    List<SubscriberBuilder<? extends Message<?>, Void>> subscriber = registry(container).getSubscribers("subscriber");
    assertThat(subscriber).isNotEmpty();
    List<String> list = new ArrayList<>();
    Multi.createFrom().items("a", "b", "c").map(Message::of)
            .onItem().invoke(m -> list.add(m.getPayload()))
            .subscribe(((SubscriberBuilder<Message<?>, Void>) subscriber.get(0)).build());
    assertThat(list).containsExactly("a", "b", "c");
}
 
Example #15
Source File: MeecrowaveSeContainerInitializerTest.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
@Test
public void run() {
    try (final SeContainer container = SeContainerInitializer.newInstance()
            .addProperty("httpPort", new Meecrowave.Builder().randomHttpPort().getHttpPort())
            .disableDiscovery()
            .addBeanClasses(Configured.class)
            .initialize()) {
        final Client client = ClientBuilder.newClient();
        assertNotNull(container.select(Meecrowave.class).get());
        assertEquals("configured", client
                .target(String.format("http://localhost:%d/configured", container.select(Meecrowave.Builder.class).get().getHttpPort()))
                .request(TEXT_PLAIN_TYPE)
                .get(String.class));
    }
}
 
Example #16
Source File: HammockInitializer.java    From hammock with Apache License 2.0 5 votes vote down vote up
@Override
protected SeContainer newContainer(WebBeansContext context) {
    SingletonService<WebBeansContext> singletonService = WebBeansFinder.getSingletonService();
    if(singletonService instanceof HolderSingletonService) {
        ((HolderSingletonService) singletonService).register(context);
    } else {
        try {
            WebBeansFinder.setSingletonService(new HolderSingletonService(context));
        } catch (Exception e) {
            logger.info("Unable to override OWB SingletonService", e);
        }
    }
    return super.newContainer(context);
}
 
Example #17
Source File: Weld3Bootstrapper.java    From hammock with Apache License 2.0 4 votes vote down vote up
public SeContainer getSeContainer() {
    return seContainer;
}
 
Example #18
Source File: MainApp.java    From tutorials with MIT License 4 votes vote down vote up
public static void main(String[] args) {
    SeContainerInitializer initializer = SeContainerInitializer.newInstance();
    try (SeContainer container = initializer.initialize()) {
    }
}
 
Example #19
Source File: WeldTestBase.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
protected ChannelRegistry registry(SeContainer container) {
    return container.select(ChannelRegistry.class).get();
}
 
Example #20
Source File: BootstrappingApplication.java    From tutorials with MIT License 4 votes vote down vote up
public static void main(String... args) {
    SeContainerInitializer containerInitializer = SeContainerInitializer.newInstance();
    try (SeContainer container = containerInitializer.initialize()) {
        container.getBeanManager().fireEvent(new ExampleEvent("Welcome to Baeldung!"));
    }
}
 
Example #21
Source File: OrderedObserver.java    From javaee8-cookbook with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    SeContainer container = SeContainerInitializer.newInstance().initialize();
    container.getBeanManager().fireEvent(new MyEvent("event -> " + System.currentTimeMillis()));
}
 
Example #22
Source File: WeldTestBaseWithoutTails.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
protected ChannelRegistry registry(SeContainer container) {
    return container.select(ChannelRegistry.class).get();
}
 
Example #23
Source File: Main.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    SeContainer container = SeContainerInitializer.newInstance().initialize();
    container.getBeanManager().createInstance().select(BeanUsingAnEmitter.class).get().periodicallySendMessage();
}
 
Example #24
Source File: Main.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    SeContainer container = SeContainerInitializer.newInstance().initialize();

    container.getBeanManager().createInstance().select(BeanUsingAnEmitter.class).get().periodicallySendMessage();
}
 
Example #25
Source File: Main.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    SeContainer container = SeContainerInitializer.newInstance().initialize();
    container.getBeanManager().createInstance().select(BeanUsingAnEmitter.class).get().periodicallySendMessage();
}
 
Example #26
Source File: Main.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    SeContainer container = SeContainerInitializer.newInstance().initialize();

    container.getBeanManager().createInstance().select(BeanUsingAnEmitter.class).get().periodicallySendMessage();
}
 
Example #27
Source File: Main.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    SeContainer container = SeContainerInitializer.newInstance().initialize();

    container.getBeanManager().createInstance().select(BeanUsingAnEmitter.class).get().periodicallySendMessageToKafka();
}
 
Example #28
Source File: Main.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    SeContainer container = SeContainerInitializer.newInstance().initialize();

    container.getBeanManager().createInstance().select(BeanUsingAnEmitter.class).get().periodicallySendMqttMessage();
}