@@ -9,63 +9,68 @@ import net.corda.core.cordapp.CordappConfigException
9
9
import net.corda.core.node.ServiceHub
10
10
import org.slf4j.LoggerFactory
11
11
12
- const val CACHE_SIZE_DEFAULT = 1024 // TODO Return good default, for now it's not wired, it will be done in separate PR.
12
+ const val CACHE_SIZE_DEFAULT = 1024
13
+ const val PAGE_SIZE_DEFAULT = 1024
13
14
14
- data class InMemorySelectionConfig @JvmOverloads constructor(val enabled : Boolean ,
15
- val indexingStrategies : List <VaultWatcherService .IndexingType >,
16
- val cacheSize : Int = CACHE_SIZE_DEFAULT ) : StateSelectionConfig {
17
- companion object {
18
- private val logger = LoggerFactory .getLogger(" inMemoryConfigSelectionLogger" )
15
+ data class InMemorySelectionConfig @JvmOverloads constructor(
16
+ val enabled : Boolean ,
17
+ val indexingStrategies : List <VaultWatcherService .IndexingType >,
18
+ val cacheSize : Int = CACHE_SIZE_DEFAULT ,
19
+ val pageSize : Int = 1000
20
+ ) : StateSelectionConfig {
21
+ companion object {
22
+ private val logger = LoggerFactory .getLogger(" inMemoryConfigSelectionLogger" )
19
23
20
- @JvmStatic
21
- fun parse (config : CordappConfig ): InMemorySelectionConfig {
22
- val enabled = if (! config.exists(" stateSelection.inMemory.enabled" )) {
23
- logger.warn(" Did not detect a configuration for InMemory selection - enabling memory usage for token indexing. Please set stateSelection.inMemory.enabled to \" false\" to disable this" )
24
- true
25
- } else {
26
- config.getBoolean(" stateSelection.inMemory.enabled" )
27
- }
28
- val cacheSize = config.getIntOrNull(" stateSelection.inMemory.cacheSize" )
29
- ? : CACHE_SIZE_DEFAULT
30
- val indexingType = try {
31
- (config.get(" stateSelection.inMemory.indexingStrategies" ) as List <Any >).map { VaultWatcherService .IndexingType .valueOf(it.toString()) }
32
- } catch (e: CordappConfigException ) {
33
- logger.warn(" No indexing method specified. Indexes will be created at run-time for each invocation of selectTokens" )
34
- emptyList<VaultWatcherService .IndexingType >()
35
- } catch (e: ClassCastException ) {
36
- logger.warn(" No indexing method specified. Indexes will be created at run-time for each invocation of selectTokens" )
37
- emptyList<VaultWatcherService .IndexingType >()
38
- }
39
- logger.info(" Found in memory token selection configuration with values indexing strategy: $indexingType , cacheSize: $cacheSize " )
40
- return InMemorySelectionConfig (enabled, indexingType, cacheSize)
41
- }
24
+ @JvmStatic
25
+ fun parse (config : CordappConfig ): InMemorySelectionConfig {
26
+ val enabled = if (! config.exists(" stateSelection.inMemory.enabled" )) {
27
+ logger.warn(" Did not detect a configuration for InMemory selection - enabling memory usage for token indexing. Please set stateSelection.inMemory.enabled to \" false\" to disable this" )
28
+ true
29
+ } else {
30
+ config.getBoolean(" stateSelection.inMemory.enabled" )
31
+ }
32
+ val cacheSize = config.getIntOrNull(" stateSelection.inMemory.cacheSize" )
33
+ ? : CACHE_SIZE_DEFAULT
34
+ val pageSize: Int = config.getIntOrNull(" stateSelection.inMemory.cacheSize" )? : PAGE_SIZE_DEFAULT
35
+ val indexingType = try {
36
+ (config.get(" stateSelection.inMemory.indexingStrategies" ) as List <Any >).map { VaultWatcherService .IndexingType .valueOf(it.toString()) }
37
+ } catch (e: CordappConfigException ) {
38
+ logger.warn(" No indexing method specified. Indexes will be created at run-time for each invocation of selectTokens" )
39
+ emptyList<VaultWatcherService .IndexingType >()
40
+ } catch (e: ClassCastException ) {
41
+ logger.warn(" No indexing method specified. Indexes will be created at run-time for each invocation of selectTokens" )
42
+ emptyList<VaultWatcherService .IndexingType >()
43
+ }
44
+ logger.info(" Found in memory token selection configuration with values indexing strategy: $indexingType , cacheSize: $cacheSize " )
45
+ return InMemorySelectionConfig (enabled, indexingType, cacheSize, pageSize)
46
+ }
42
47
43
- fun defaultConfig (): InMemorySelectionConfig {
44
- return InMemorySelectionConfig (true , emptyList())
45
- }
46
- }
48
+ fun defaultConfig (): InMemorySelectionConfig {
49
+ return InMemorySelectionConfig (true , emptyList())
50
+ }
51
+ }
47
52
48
- @Suspendable
49
- override fun toSelector (services : ServiceHub ): LocalTokenSelector {
50
- return try {
51
- val vaultObserver = services.cordaService(VaultWatcherService ::class .java)
52
- LocalTokenSelector (services, vaultObserver, state = null )
53
- } catch (e: IllegalArgumentException ) {
54
- throw IllegalArgumentException (" Couldn't find VaultWatcherService in CordaServices, please make sure that it was installed in node." )
55
- }
56
- }
53
+ @Suspendable
54
+ override fun toSelector (services : ServiceHub ): LocalTokenSelector {
55
+ return try {
56
+ val vaultObserver = services.cordaService(VaultWatcherService ::class .java)
57
+ LocalTokenSelector (services, vaultObserver, state = null )
58
+ } catch (e: IllegalArgumentException ) {
59
+ throw IllegalArgumentException (" Couldn't find VaultWatcherService in CordaServices, please make sure that it was installed in node." )
60
+ }
61
+ }
57
62
}
58
63
59
64
// Helpers for configuration parsing.
60
65
61
66
fun CordappConfig.getIntOrNull (path : String ): Int? {
62
- return try {
63
- getInt(path)
64
- } catch (e: CordappConfigException ) {
65
- if (exists(path)) {
66
- throw IllegalArgumentException (" Provide correct database selection configuration for config path: $path " )
67
- } else {
68
- null
69
- }
70
- }
67
+ return try {
68
+ getInt(path)
69
+ } catch (e: CordappConfigException ) {
70
+ if (exists(path)) {
71
+ throw IllegalArgumentException (" Provide correct database selection configuration for config path: $path " )
72
+ } else {
73
+ null
74
+ }
75
+ }
71
76
}
0 commit comments