List of usage examples for com.amazonaws.internal EC2MetadataClient readResource
public String readResource(String resourcePath) throws IOException, SdkClientException
From source file:org.wallride.autoconfigure.WallRideCacheConfiguration.java
License:Apache License
@Bean @Override// w w w . ja va 2 s.c o m public CacheManager cacheManager() { // JGroups settings String jgroupsConfigurationFile = environment.getRequiredProperty("jgroups.configurationFile"); if ("jgroups-ec2.xml".equals(jgroupsConfigurationFile)) { ClassConfigurator.addProtocol((short) 1000, S3_CLIENT_PING.class); EC2MetadataClient metadataClient = new EC2MetadataClient(); String ipAddress; try { ipAddress = metadataClient.readResource("/latest/meta-data/local-ipv4"); } catch (IOException e) { throw new RuntimeException(e); } logger.info("jgroups.tcp.address -> {}", ipAddress); System.setProperty("jgroups.tcp.address", ipAddress); System.setProperty("jgroups.s3.bucket", environment.getRequiredProperty("jgroups.s3.bucket")); } Resource hibernateSearchConfig = new ClassPathResource( DefaultCacheManagerService.DEFAULT_INFINISPAN_CONFIGURATION_RESOURCENAME); ParserRegistry parserRegistry = new ParserRegistry(); ConfigurationBuilderHolder holder; try { holder = parserRegistry.parse(hibernateSearchConfig.getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } // GlobalConfiguration // @formatter:off GlobalConfigurationBuilder globalBuilder = holder.getGlobalConfigurationBuilder(); globalBuilder.globalJmxStatistics().allowDuplicateDomains(true).transport().defaultTransport() .addProperty("configurationFile", jgroupsConfigurationFile); // @formatter:on // DefaultConfiguration // @formatter:off for (ConfigurationBuilder luceneIndexesBuilder : holder.getNamedConfigurationBuilders().values()) { if ("mysql".equals(dataSourceProperties.getPlatform())) { luceneIndexesBuilder.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class) .preload(true).shared(true).key2StringMapper(LuceneKey2StringMapper.class).table() .tableNamePrefix("ispn_string_table").idColumnName("id_column").idColumnType("varchar(255)") .dataColumnName("data_column").dataColumnType("longblob") .timestampColumnName("timestamp_column").timestampColumnType("bigint").dropOnExit(false) .createOnStart(true).async().enable().threadPoolSize(10).fetchPersistentState(true) .ignoreModifications(false).purgeOnStartup(false) .connectionFactory(InfinispanDataSourceConnectionFactoryConfigurationBuilder.class) .dataSource(dataSource); } else if ("postgresql".equals(dataSourceProperties.getPlatform())) { luceneIndexesBuilder.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class) .preload(true).shared(true).key2StringMapper(LuceneKey2StringMapper.class).table() .tableNamePrefix("ispn_string_table").idColumnName("id_column").idColumnType("varchar(255)") .dataColumnName("data_column").dataColumnType("bytea") .timestampColumnName("timestamp_column").timestampColumnType("bigint").dropOnExit(false) .createOnStart(true).async().enable().threadPoolSize(10).fetchPersistentState(true) .ignoreModifications(false).purgeOnStartup(false) .connectionFactory(InfinispanDataSourceConnectionFactoryConfigurationBuilder.class) .dataSource(dataSource); } else { throw new IllegalStateException(); } } // @formatter:on // @formatter:off ConfigurationBuilder cacheBuilder = new ConfigurationBuilder(); cacheBuilder.clustering().cacheMode(CacheMode.REPL_SYNC).eviction().type(EvictionType.COUNT) .strategy(EvictionStrategy.LIRS).size(1000); // .indexing() // .index(Index.NONE); // @formatter:on holder.getNamedConfigurationBuilders().put(BLOG_CACHE, cacheBuilder); // holder.getNamedConfigurationBuilders().put("settings", cacheBuilder); holder.getNamedConfigurationBuilders().put(POPULAR_POST_CACHE, cacheBuilder); holder.getNamedConfigurationBuilders().put(ARTICLE_CACHE, cacheBuilder); holder.getNamedConfigurationBuilders().put(PAGE_CACHE, cacheBuilder); holder.getNamedConfigurationBuilders().put(CATEGORY_CACHE, cacheBuilder); holder.getNamedConfigurationBuilders().put(CUSTOM_FIELD_CACHE, cacheBuilder); holder.getNamedConfigurationBuilders().put(MEDIA_CACHE, cacheBuilder); holder.getNamedConfigurationBuilders().put(BANNER_CACHE, cacheBuilder); holder.getNamedConfigurationBuilders().put(USER_CACHE, cacheBuilder); EmbeddedCacheManager embeddedCacheManager = new DefaultCacheManager(holder, true); InfinispanSingletonCacheManagerDirectoryProvider.cacheManager = embeddedCacheManager; return new SpringEmbeddedCacheManager(embeddedCacheManager); }