public static Ethereum createEthereum(Class ... springConfigs) { logger.info("Starting EthereumJ..."); AbstractApplicationContext context = new AnnotationConfigApplicationContext(springConfigs); context.registerShutdownHook(); return context.getBean(Ethereum.class); } }
private ServerServiceDefinition bindInterceptors(ServerServiceDefinition serviceDefinition, GRpcService gRpcService, Collection<ServerInterceptor> globalInterceptors) { Stream<? extends ServerInterceptor> privateInterceptors = Stream.of(gRpcService.interceptors()) .map(interceptorClass -> { try { return 0 < applicationContext.getBeanNamesForType(interceptorClass).length ? applicationContext.getBean(interceptorClass) : interceptorClass.newInstance(); } catch (Exception e) { throw new BeanCreationException("Failed to create interceptor instance.", e); } }); List<ServerInterceptor> interceptors = Stream.concat( gRpcService.applyGlobalInterceptors() ? globalInterceptors.stream() : Stream.empty(), privateInterceptors) .distinct() .sorted(serverInterceptorOrderComparator()) .collect(Collectors.toList()); return ServerInterceptors.intercept(serviceDefinition, interceptors); }
recoveryCheckpoint.getCheckpointDir().setBase(getCheckpointsDir()); recoveryCheckpoint.getCheckpointDir().setPath(selectedCheckpoint); recoveryCheckpoint.getCheckpointDir().setConfigurer(appCtx.getBean(ConfigPathConfigurer.class)); recoveryCheckpoint.afterPropertiesSet(); setRecoveryCheckpoint(recoveryCheckpoint);
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/helloWorldDemo.xml", HelloWorldApp.class); MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class); PollableChannel outputChannel = context.getBean("outputChannel", PollableChannel.class); inputChannel.send(new GenericMessage<String>("World")); logger.info("==> HelloWorldDemo: " + outputChannel.receive(0).getPayload()); context.close(); }
public static void main(String[] args) throws Exception { AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("/META-INF/spring/integration/orderProcessingSample.xml", BookOrderProcessingTestApp.class); MessageChannel messageChannel = (MessageChannel) applicationContext.getBean("ordersChannel"); GenericMessage<Document> orderMessage = createXmlMessageFromResource("META-INF/spring/integration/order.xml"); messageChannel.send(orderMessage); applicationContext.close(); }
public static void main(String[] args) throws Exception { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "META-INF/spring/integration/04-externalgateway/*.xml"); System.out.println("Please enter zip"); BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); String line = console.readLine(); if (line != null) { String zip = line.trim(); WeatherAndTraffic weatherAndTraffic = context.getBean("wat", WeatherAndTraffic.class); List<String> result = weatherAndTraffic.getByZip(zip); System.out.println(result.get(0) + "\r\n" + result.get(1) + "\r\n"); } else { System.out.println("Console closed"); } context.close(); System.exit(0); } }
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/cafeDemo-control-bus.xml"); WaiterMonitor waiterMonitor = (WaiterMonitor) context.getBean("waiterMonitor"); int totalDeliveries = 0; while (totalDeliveries <= 3) { try { Thread.sleep(1000); } catch (InterruptedException e) { logger.error("Interrupted", e); } totalDeliveries = (Integer)waiterMonitor.sendControlScript("waiter.totalDeliveries"); logger.info("Total cafe deliveries: " + totalDeliveries); if (totalDeliveries > 3) { logger.info("stopping orders..."); waiterMonitor.sendControlScript("cafe.stop()"); logger.info("orders stopped"); } } context.close(); System.exit(0); }
final CoffeeService service = context.getBean(CoffeeService.class);
@Test public void testBeansStart() { AbstractApplicationContext context = new ClassPathXmlApplicationContext("lifecycleTests.xml", getClass()); context.start(); LifecycleTestBean bean1 = (LifecycleTestBean) context.getBean("bean1"); LifecycleTestBean bean2 = (LifecycleTestBean) context.getBean("bean2"); LifecycleTestBean bean3 = (LifecycleTestBean) context.getBean("bean3"); LifecycleTestBean bean4 = (LifecycleTestBean) context.getBean("bean4"); String error = "bean was not started"; assertTrue(error, bean1.isRunning()); assertTrue(error, bean2.isRunning()); assertTrue(error, bean3.isRunning()); assertTrue(error, bean4.isRunning()); }
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/cafeDemo-annotation.xml", CafeDemoApp.class); Cafe cafe = (Cafe) context.getBean("cafe"); for (int i = 1; i <= 100; i++) { Order order = new Order(i); order.addItem(DrinkType.LATTE, 2, false); order.addItem(DrinkType.MOCHA, 3, true); cafe.placeOrder(order); } context.close(); } }
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/cafeDemo-xml.xml", CafeDemoApp.class); Cafe cafe = (Cafe) context.getBean("cafe"); for (int i = 1; i <= 100; i++) { Order order = new Order(i); order.addItem(DrinkType.LATTE, 2, false); order.addItem(DrinkType.MOCHA, 3, true); cafe.placeOrder(order); } context.close(); } }
/** * place some orders * @param context spring context * @param count the number of standard orders */ public static void order(AbstractApplicationContext context, int count){ Cafe cafe = (Cafe) context.getBean("cafe"); for (int i = 1; i <= 100; i++) { Order order = new Order(i); order.addItem(DrinkType.LATTE, 2, false); order.addItem(DrinkType.MOCHA, 3, true); cafe.placeOrder(order); } }
/** * Place some orders. * * @param context spring context * @param count the number of standard orders */ public static void order(AbstractApplicationContext context, int count){ Cafe cafe = (Cafe) context.getBean("cafe"); for (int i = 1; i <= count; i++) { Order order = new Order(i); order.addItem(DrinkType.LATTE, 2, false); order.addItem(DrinkType.MOCHA, 3, true); cafe.placeOrder(order); } }
/** * Place some orders. * * @param context spring context * @param count the number of standard orders */ public static void order(AbstractApplicationContext context, int count){ Cafe cafe = (Cafe) context.getBean("cafe"); for (int i = 1; i <= count; i++) { Order order = new Order(i); order.addItem(DrinkType.LATTE, 2, false); order.addItem(DrinkType.MOCHA, 3, true); cafe.placeOrder(order); } }
@Test public void testStartOrder() { AbstractApplicationContext context = new ClassPathXmlApplicationContext("lifecycleTests.xml", getClass()); context.start(); LifecycleTestBean bean1 = (LifecycleTestBean) context.getBean("bean1"); LifecycleTestBean bean2 = (LifecycleTestBean) context.getBean("bean2"); LifecycleTestBean bean3 = (LifecycleTestBean) context.getBean("bean3"); LifecycleTestBean bean4 = (LifecycleTestBean) context.getBean("bean4"); String notStartedError = "bean was not started"; assertTrue(notStartedError, bean1.getStartOrder() > 0); assertTrue(notStartedError, bean2.getStartOrder() > 0); assertTrue(notStartedError, bean3.getStartOrder() > 0); assertTrue(notStartedError, bean4.getStartOrder() > 0); String orderError = "dependent bean must start after the bean it depends on"; assertTrue(orderError, bean2.getStartOrder() > bean1.getStartOrder()); assertTrue(orderError, bean3.getStartOrder() > bean2.getStartOrder()); assertTrue(orderError, bean4.getStartOrder() > bean2.getStartOrder()); }
@Test public void testBeansStop() { AbstractApplicationContext context = new ClassPathXmlApplicationContext("lifecycleTests.xml", getClass()); context.start(); LifecycleTestBean bean1 = (LifecycleTestBean) context.getBean("bean1"); LifecycleTestBean bean2 = (LifecycleTestBean) context.getBean("bean2"); LifecycleTestBean bean3 = (LifecycleTestBean) context.getBean("bean3"); LifecycleTestBean bean4 = (LifecycleTestBean) context.getBean("bean4"); String startError = "bean was not started"; assertTrue(startError, bean1.isRunning()); assertTrue(startError, bean2.isRunning()); assertTrue(startError, bean3.isRunning()); assertTrue(startError, bean4.isRunning()); context.stop(); String stopError = "bean was not stopped"; assertFalse(stopError, bean1.isRunning()); assertFalse(stopError, bean2.isRunning()); assertFalse(stopError, bean3.isRunning()); assertFalse(stopError, bean4.isRunning()); }
@Test public void testStopOrder() { AbstractApplicationContext context = new ClassPathXmlApplicationContext("lifecycleTests.xml", getClass()); context.start(); context.stop(); LifecycleTestBean bean1 = (LifecycleTestBean) context.getBean("bean1"); LifecycleTestBean bean2 = (LifecycleTestBean) context.getBean("bean2"); LifecycleTestBean bean3 = (LifecycleTestBean) context.getBean("bean3"); LifecycleTestBean bean4 = (LifecycleTestBean) context.getBean("bean4"); String notStoppedError = "bean was not stopped"; assertTrue(notStoppedError, bean1.getStopOrder() > 0); assertTrue(notStoppedError, bean2.getStopOrder() > 0); assertTrue(notStoppedError, bean3.getStopOrder() > 0); assertTrue(notStoppedError, bean4.getStopOrder() > 0); String orderError = "dependent bean must stop before the bean it depends on"; assertTrue(orderError, bean2.getStopOrder() < bean1.getStopOrder()); assertTrue(orderError, bean3.getStopOrder() < bean2.getStopOrder()); assertTrue(orderError, bean4.getStopOrder() < bean2.getStopOrder()); }
/** * Finish the initialization of this context's bean factory, * initializing all remaining singleton beans. */ protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) { // Initialize conversion service for this context. if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME) && beanFactory.isTypeMatch(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)) { beanFactory.setConversionService( beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)); } // Register a default embedded value resolver if no bean post-processor // (such as a PropertyPlaceholderConfigurer bean) registered any before: // at this point, primarily for resolution in annotation attribute values. if (!beanFactory.hasEmbeddedValueResolver()) { beanFactory.addEmbeddedValueResolver(strVal -> getEnvironment().resolvePlaceholders(strVal)); } // Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early. String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false); for (String weaverAwareName : weaverAwareNames) { getBean(weaverAwareName); } // Stop using the temporary ClassLoader for type matching. beanFactory.setTempClassLoader(null); // Allow for caching all bean definition metadata, not expecting further changes. beanFactory.freezeConfiguration(); // Instantiate all remaining (non-lazy-init) singletons. beanFactory.preInstantiateSingletons(); }
/** * Finish the initialization of this context's bean factory, * initializing all remaining singleton beans. */ protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) { // Initialize conversion service for this context. if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME) && beanFactory.isTypeMatch(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)) { beanFactory.setConversionService( beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)); } // Register a default embedded value resolver if no bean post-processor // (such as a PropertyPlaceholderConfigurer bean) registered any before: // at this point, primarily for resolution in annotation attribute values. if (!beanFactory.hasEmbeddedValueResolver()) { beanFactory.addEmbeddedValueResolver(strVal -> getEnvironment().resolvePlaceholders(strVal)); } // Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early. String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false); for (String weaverAwareName : weaverAwareNames) { getBean(weaverAwareName); } // Stop using the temporary ClassLoader for type matching. beanFactory.setTempClassLoader(null); // Allow for caching all bean definition metadata, not expecting further changes. beanFactory.freezeConfiguration(); // Instantiate all remaining (non-lazy-init) singletons. beanFactory.preInstantiateSingletons(); }