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); } }
@Override public void run() { server.shutdownNow(); weld.shutdown(); } }));
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(); }
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); } }
public static void main(final String[] args) throws Exception { weldContainer.instance().select(Workbench.class).get().init(); }
@Override public <T> T getInstance(Class<T> type) { return containerInstance.select(type) .get(); }
/** * * @return a new builder instance * @see ProcessSyntheticObserverMethod */ @SuppressWarnings("serial") public static Builder<ProcessSyntheticObserverMethod<?, ?>> processSyntheticObserverMethod() { return processSyntheticObserverMethod(new TypeLiteral<ProcessSyntheticObserverMethod<?, ?>>() { }.getType()); }
/** * * @return a new builder instance * @see ProcessSyntheticBean */ @SuppressWarnings("serial") public static Builder<ProcessSyntheticBean<?>> processSyntheticBean() { return processSyntheticBean(new TypeLiteral<ProcessSyntheticBean<?>>() { }.getType()); }
/** * * @param callback * @return a new container lifecycle observer * @see BeforeBeanDiscovery */ public static ContainerLifecycleObserver<BeforeBeanDiscovery> beforeBeanDiscovery(Consumer<BeforeBeanDiscovery> callback) { return beforeBeanDiscovery().notify(callback); }
/** * * @param callback * @return a new container lifecycle observer * @see AfterDeploymentValidation */ public static ContainerLifecycleObserver<AfterDeploymentValidation> afterDeploymentValidation(Consumer<AfterDeploymentValidation> callback) { return afterDeploymentValidation().notify(callback); }
/** * * @return a new builder instance * @see ProcessInjectionTarget * */ @SuppressWarnings("serial") public static Builder<ProcessInjectionTarget<?>> processInjectionTarget() { return processInjectionTarget(new TypeLiteral<ProcessInjectionTarget<?>>() { }.getType()); }
/** * * @return a new builder instance * @see ProcessProducer */ @SuppressWarnings("serial") public static Builder<ProcessProducer<?, ?>> processProducer() { return processProducer(new TypeLiteral<ProcessProducer<?, ?>>() { }.getType()); }
public static void main(String[] args) throws Exception { Weld weld = new Weld(); final WeldContainer container = weld.initialize(); RequestContext requestContext= container.instance().select(RequestContext.class, UnboundLiteral.INSTANCE).get(); requestContext.activate(); final MyPojo pojo = container.instance().select(MyPojo.class).get(); Thread t = new Thread() { public void run() { RequestContext requestContext= container.instance().select(RequestContext.class, UnboundLiteral.INSTANCE).get(); requestContext.activate(); System.out.println("1" + pojo.ping()); } }; t.start(); t.join(); System.out.println("2" + pojo.ping()); weld.shutdown(); }
protected static void start() { weld = new Weld(); weld.initialize(); server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createJaxRsApp(), true); }
protected static void stop() { server.shutdownNow(); weld.shutdown(); }
@Override public <T extends Controller> T createController(Class<T> controllerClass) { return weldContainer.instance().select(controllerClass).get(); }
/** * * @return a new builder instance * @see ProcessSyntheticObserverMethod */ @SuppressWarnings("serial") public static Builder<ProcessSyntheticObserverMethod<?, ?>> processSyntheticObserverMethod() { return processSyntheticObserverMethod(new TypeLiteral<ProcessSyntheticObserverMethod<?, ?>>() { }.getType()); }
public static void main(String[] args) { try { System.out.println("\"Hello World\" Jersey Example Weld App"); final Weld weld = new Weld(); weld.initialize(); final ResourceConfig resourceConfig = createJaxRsApp(); final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, false); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { server.shutdownNow(); weld.shutdown(); } })); server.start(); System.out.println(String.format("Application started.\nTry out %s%s\nStop the application using CTRL+C", BASE_URI, ROOT_PATH)); Thread.currentThread().join(); } catch (IOException | InterruptedException ex) { Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex); } }
@Override public void shutdown() { upnpServiceShutdownEvent.fire(new UpnpService.Shutdown()); removeLoggingHandler(); // Disable CDI logging handler before stopping CDI container weld.shutdown(); super.shutdown(); }