Refine search
public static void main(String[] args) throws IOException { Weld weld = new Weld(); WeldContainer container = weld.initialize(); Application application = container.instance().select(Application.class).get(); application.run(); weld.shutdown(); }
protected void start(Weld weld) { try { if (weld == null) { weld = new Weld(); } containerInstance = weld.initialize(); } catch (IllegalArgumentException e) { throw new CucumberException(START_EXCEPTION_MESSAGE, e); } }
@BeforeClass public static void beforeClass() { CDITestRunner.setUp(); CDITestRunner.weld = CDITestRunner.createWeld( CDIExamplesTest.class.getName(), Msg.class.getName(), Msg1.class.getName(), Msg2.class.getName(), Message.class.getName(), MessageImpl.class.getName(), Message2.class.getName(), Message2Impl1.class.getName(), Message2Impl2.class.getName(), MessageProducers.class.getName(), MessageProducers2.class.getName() ); CDITestRunner.container = CDITestRunner.weld.initialize(); }
private ExecutorModule() { weld = new Weld(); this.container = weld.initialize(); this.executorService = this.container.instance().select(ExecutorServiceEntryPointImpl.class).get(); //Singleton.. that we need to instantiate //this.container.instance().select(TaskLifeCycleEventListener.class).get(); }
/** * Must be called to initialize the bean manager. */ public void initialize() { weld = new Weld(); container = weld.initialize(); beanManager = container.getBeanManager(); }
@Override public void provide(YggdrasilConfiguration configuration) throws YggdrasilException { logger.info("Initializing Weld container..."); System.setProperty("org.jboss.logging.provider", "slf4j"); Weld weld = new Weld(); weld.property(Weld.ARCHIVE_ISOLATION_SYSTEM_PROPERTY, false); weld.setClassLoader(CDIProvider.class.getClassLoader()); WeldContainer container = weld.initialize(); YggdrasilContext.registerObject(BeanManager.class.getName(), container.getBeanManager()); logger.info(CDIProvider.class.getSimpleName() + " initialized."); }
log.info("Hello from CDI microservice provider!"); final String weldName = String.valueOf(context.getProperties().get(Context.WELD_NAME)); final Weld weld = new Weld(weldName); final MicroservicesCDIExtension microservicesCDIExtension = new MicroservicesCDIExtension(this.context); weld.property("org.jboss.weld.se.archive.isolation", "false"); weld.addExtension(microservicesCDIExtension); final WeldContainer container = weld.initialize(); this.context.getProperties().put(BEAN_MANAGER, container.getBeanManager()); this.context.getProperties().put(CDI_CONTAINER, container); this.context.getProperties().put(Storage.STORAGE, new HashMap<String, Object>()); this.beanManager = container.getBeanManager(); this.deployed = true; container.event().select(MicroservicesInitEvent.class).fire(new MicroservicesInitEvent(this.context, container.getBeanManager(), container)); container.event().select(MicroservicesStartedEvent.class).fire(new MicroservicesStartedEvent(this.context, container.getBeanManager(), container)); this.deployed = false; try { weld.shutdown(); } catch (final IllegalStateException e) {
Weld weld = new Weld(); try { WeldContainer container = weld.initialize(); URI baseUri = UriBuilder.fromUri("http://localhost/").port(8080).build(); ResourceConfig config = ResourceConfig.forApplicationClass(MyApplication.class); Server server = JettyHttpContainerFactory.createServer(baseUri, config); server.join(); } catch (Exception e) { e.printStackTrace(); } finally { weld.shutdown(); }
@Test public void testConsumers() throws InterruptedException { try (WeldContainer weld = new Weld().disableDiscovery().addExtension(new VertxExtension()).addPackage(false, RegisterConsumersAfterBootstrapTest.class) .initialize()) { Vertx vertx = Vertx.vertx(); try { weld.select(VertxExtension.class).get().registerConsumers(vertx, weld.event()); vertx.eventBus().send(HelloObserver.HELLO_ADDRESS, "hello"); assertEquals("hello", SYNCHRONIZER.poll(Timeouts.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)); } finally { vertx.close(); } } }
@Override public void run() { server.shutdownNow(); weld.shutdown(); } }));
@Before public void setUp() throws Exception { // disable git and ssh daemons as they are not needed for the tests System.setProperty("org.uberfire.nio.git.daemon.enabled", "false"); System.setProperty("org.uberfire.nio.git.ssh.enabled", "false"); System.setProperty("org.uberfire.sys.repo.monitor.disabled", "true"); //Bootstrap WELD container weldContainer = new Weld().initialize(); dataModelService = weldContainer.select(DataModelerService.class).get(); moduleService = weldContainer.select(KieModuleService.class).get(); //Ensure URLs use the default:// scheme fs.forceAsDefault(); }
CamelCdiDeployment(TestClass test, CamelCdiContext context) { this.context = context; weld = new Weld() // TODO: check parallel execution .containerId("camel-context-cdi") .property(ConfigurationKey.RELAXED_CONSTRUCTION.get(), true) .property(Weld.SHUTDOWN_HOOK_SYSTEM_PROPERTY, false) .enableDiscovery() .beanClasses(test.getJavaClass().getDeclaredClasses()) .addBeanClass(test.getJavaClass()) .addExtension(new CdiCamelExtension()); // Apply deployment customization provided by the @Beans annotation // if present on the test class if (test.getJavaClass().isAnnotationPresent(Beans.class)) { Beans beans = test.getJavaClass().getAnnotation(Beans.class); weld.addExtension(new CamelCdiTestExtension(beans)); for (Class<?> alternative : beans.alternatives()) { // It is not necessary to add the alternative class with WELD-2218 // anymore, though it's kept for previous versions weld.addBeanClass(alternative) .addAlternative(alternative); } for (Class<?> clazz : beans.classes()) { weld.addBeanClass(clazz); } weld.addPackages(false, beans.packages()); } }
@Override public void start(Future<Void> startFuture) throws Exception { Weld weld = this.weld != null ? this.weld : createDefaultWeld(); if (weld.getContainerId() == null) { weld.containerId(deploymentID()); } weld.addExtension(new VertxExtension(vertx, context)); configureWeld(weld); // Bootstrap can take some time to complete vertx.executeBlocking(future -> { try { this.weldContainer = weld.initialize(); future.complete(); } catch (Exception e) { future.fail(e); } }, result -> { if (result.succeeded()) { LOGGER.info("Weld verticle started for deployment {0}", deploymentID()); startFuture.complete(); } else { startFuture.fail(result.cause()); } }); }
@Override public void evaluate() throws Throwable { WeldContainer container = weld.initialize(); context.setBeanManager(container.getBeanManager()); try { base.evaluate(); } finally { container.shutdown(); context.unsetBeanManager(); } } };
/** * The returned {@link Weld} instance has: * <ul> * <li>automatic discovery disabled</li> * <li>concurrent deployment disabled</li> * </ul> * * @return a new {@link Weld} instance suitable for testing */ public static Weld createWeld() { return new Weld().disableDiscovery().property(ConfigurationKey.CONCURRENT_DEPLOYMENT.get(), false); }
public class WebServiceBinder extends AbstractBinder { @Override protected void configure() { BeanManager bm = getBeanManager(); bind(getBean(bm, StudentRepository.class)) .to(StudentRepository.class); } private BeanManager getBeanManager() { // is there a better way to get the bean manager? return new Weld().getBeanManager(); } private <T> T getBean(BeanManager bm, Class<T> clazz) { Bean<T> bean = (Bean<T>) bm.getBeans(clazz).iterator().next(); CreationalContext<T> ctx = bm.createCreationalContext(bean); return (T) bm.getReference(bean, clazz, ctx); } }
list.add(ResourceFactoryServiceImpl.class.getName()); Weld weld = new Weld(); List<Class<?>> classList = new ArrayList<>(); for (String className : list) { weld.beanClasses(classList.toArray(new Class[0])); weld.addExtension(new KieCDIExtension()); weld.disableDiscovery(); return weld;
@Override public Weld addExtensions(Extension... extensions) { for (Extension extension : extensions) { addExtension(extension); } return this; }
@Override public Weld addProperty(String key, Object value) { property(key, value); return this; }