|
| 1 | +package com.ge.predix.solsvc.fdh.router.boot; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | +import java.util.Iterator; |
| 5 | + |
| 6 | +import org.slf4j.Logger; |
| 7 | +import org.slf4j.LoggerFactory; |
| 8 | +import org.springframework.boot.SpringApplication; |
| 9 | +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
| 10 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 11 | +import org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration; |
| 12 | +import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration; |
| 13 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
| 14 | +import org.springframework.context.ApplicationContext; |
| 15 | +import org.springframework.context.annotation.Bean; |
| 16 | +import org.springframework.context.annotation.ComponentScan; |
| 17 | +import org.springframework.context.annotation.Configuration; |
| 18 | +import org.springframework.context.annotation.ImportResource; |
| 19 | +import org.springframework.context.annotation.PropertySource; |
| 20 | +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; |
| 21 | +import org.springframework.core.env.MutablePropertySources; |
| 22 | +import org.springframework.web.context.support.StandardServletEnvironment; |
| 23 | +import org.springframework.web.socket.config.annotation.EnableWebSocket; |
| 24 | + |
| 25 | +/** |
| 26 | + * DataEchangeRouter routes traffic to FDH Handlers. FDH Handlers implement the exact |
| 27 | + * same API Interface and can be called directly. But this microservice provides |
| 28 | + * a single point of entry for Analytic Service calls and then the calls fan out |
| 29 | + * based on rules. |
| 30 | + * |
| 31 | + * @author predix |
| 32 | + */ |
| 33 | +@SpringBootApplication |
| 34 | +@Configuration |
| 35 | +@ComponentScan(basePackages = "com.ge.predix.solsvc.fdh.handler") |
| 36 | +@EnableAutoConfiguration(exclude = |
| 37 | +{ |
| 38 | + DataSourceAutoConfiguration.class, JpaRepositoriesAutoConfiguration.class, |
| 39 | + PersistenceExceptionTranslationAutoConfiguration.class |
| 40 | +}) |
| 41 | +@ImportResource( |
| 42 | +{ |
| 43 | + "classpath*:META-INF/spring/data-exchange-cxf-context.xml", |
| 44 | + "classpath*:META-INF/spring/data-exchange-scan-context.xml" |
| 45 | +}) |
| 46 | +@PropertySource("classpath:application-default.properties") |
| 47 | +@EnableWebSocket |
| 48 | +public class DataExchangeRouterApplication extends PredixSpringBootInitializer |
| 49 | +{ |
| 50 | + |
| 51 | + private static final Logger log = LoggerFactory.getLogger(DataExchangeRouterApplication.class); |
| 52 | + |
| 53 | + /** |
| 54 | + * @param args |
| 55 | + * - |
| 56 | + */ |
| 57 | + public static void main(String[] args) |
| 58 | + { |
| 59 | + Logger log = LoggerFactory.getLogger(DataExchangeRouterApplication.class); |
| 60 | + |
| 61 | + SpringApplication springApplication = new SpringApplication(DataExchangeRouterApplication.class); |
| 62 | + ApplicationContext ctx = springApplication.run(args); |
| 63 | + |
| 64 | + log.info("Let's inspect the beans provided by Spring Boot:"); //$NON-NLS-1$ |
| 65 | + |
| 66 | + String[] beanNames = ctx.getBeanDefinitionNames(); |
| 67 | + Arrays.sort(beanNames); |
| 68 | + for (String beanName : beanNames) |
| 69 | + { |
| 70 | + log.info(beanName); |
| 71 | + } |
| 72 | + |
| 73 | + // log.info("Let's inspect the profiles provided by Spring Boot:"); |
| 74 | + String profiles[] = ctx.getEnvironment().getActiveProfiles(); |
| 75 | + for (int i = 0; i < profiles.length; i++) |
| 76 | + log.info("profile=" + profiles[i]); //$NON-NLS-1$ |
| 77 | + |
| 78 | + log.info("Let's inspect the properties provided by Spring Boot:"); //$NON-NLS-1$ |
| 79 | + MutablePropertySources propertySources = ((StandardServletEnvironment) ctx.getEnvironment()) |
| 80 | + .getPropertySources(); |
| 81 | + Iterator<org.springframework.core.env.PropertySource<?>> iterator = propertySources.iterator(); |
| 82 | + while (iterator.hasNext()) |
| 83 | + { |
| 84 | + Object propertySourceObject = iterator.next(); |
| 85 | + if ( propertySourceObject instanceof org.springframework.core.env.PropertySource ) |
| 86 | + { |
| 87 | + org.springframework.core.env.PropertySource<?> propertySource = (org.springframework.core.env.PropertySource<?>) propertySourceObject; |
| 88 | + log.info("propertySource=" + propertySource.getName() + " values=" + propertySource.getSource() //$NON-NLS-1$ //$NON-NLS-2$ |
| 89 | + + "class=" + propertySource.getClass()); //$NON-NLS-1$ |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + // Spring is a little bit of a hog on startup, after that it's not too bad. |
| 94 | + System.gc(); |
| 95 | + printMemory(); |
| 96 | + |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * - |
| 101 | + */ |
| 102 | + @SuppressWarnings("nls") |
| 103 | + public static void printMemory() |
| 104 | + { |
| 105 | + Runtime runtime = Runtime.getRuntime(); |
| 106 | + int mb = 1024 * 1024; |
| 107 | + |
| 108 | + log.info("##### Heap utilization statistics [MB] #####"); |
| 109 | + |
| 110 | + // Print used memory |
| 111 | + log.info("Used Memory:" + (runtime.totalMemory() - runtime.freeMemory()) / mb); |
| 112 | + |
| 113 | + // Print free memory |
| 114 | + log.info("Free Memory:" + runtime.freeMemory() / mb); |
| 115 | + |
| 116 | + // Print total available memory |
| 117 | + log.info("Total Memory:" + runtime.totalMemory() / mb); |
| 118 | + |
| 119 | + // Print Maximum available memory |
| 120 | + log.info("Max Memory:" + runtime.maxMemory() / mb); |
| 121 | + |
| 122 | + // log.info("VCAP_SERVICES"+System.getenv("VCAP_SERVICES")); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Add this bean or the @PropertySource above won't kick in |
| 127 | + * |
| 128 | + * @return - |
| 129 | + */ |
| 130 | + @Bean |
| 131 | + public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() |
| 132 | + { |
| 133 | + return new PropertySourcesPlaceholderConfigurer(); |
| 134 | + } |
| 135 | + |
| 136 | +} |
0 commit comments