Pending Transaction - save in external datasource

context init logging added.
This commit is contained in:
eugene-shevchenko 2015-03-30 12:15:35 +03:00
parent f2bf688f85
commit a7b0fa1c7b
1 changed files with 21 additions and 9 deletions

View File

@ -38,28 +38,40 @@ public class CommonConfig {
private RedisConnection redisConnection; private RedisConnection redisConnection;
@Bean @Bean
Repository repository(){ Repository repository() {
return new RepositoryImpl(keyValueDataSource(), keyValueDataSource()); return new RepositoryImpl(keyValueDataSource(), keyValueDataSource());
} }
@Bean @Bean
@Scope("prototype") @Scope("prototype")
public KeyValueDataSource keyValueDataSource(){ public KeyValueDataSource keyValueDataSource() {
if (CONFIG.getKeyValueDataSource().equals("redis")) { String dataSource = CONFIG.getKeyValueDataSource();
if (redisConnection.isAvailable()) { try {
if ("redis".equals(dataSource) && redisConnection.isAvailable()) {
// Name will be defined before initialization // Name will be defined before initialization
return redisConnection.createDataSource(""); return redisConnection.createDataSource("");
} }
}
return new LevelDbDataSource(); dataSource = "leveldb";
return new LevelDbDataSource();
} finally {
logger.info(dataSource + " key-value data source created.");
}
} }
@Bean @Bean
public Set<Transaction> pendingTransactions() { public Set<Transaction> pendingTransactions() {
return redisConnection.isAvailable() String storage = "Redis";
? redisConnection.createTransactionSet("pendingTransactions") try {
: Collections.synchronizedSet(new HashSet<Transaction>()); if (redisConnection.isAvailable()) {
return redisConnection.createTransactionSet("pendingTransactions");
}
storage = "In memory";
return Collections.synchronizedSet(new HashSet<Transaction>());
} finally {
logger.info(storage + " 'pendingTransactions' storage created.");
}
} }
@Bean @Bean