Move dbCloser to MockNode, the only thing that uses it. (#1512)

This commit is contained in:
Andrzej Cichocki 2017-10-02 15:59:55 +01:00 committed by GitHub
parent 383eb2bef8
commit 12982b3034
2 changed files with 7 additions and 5 deletions

View File

@ -146,7 +146,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
protected lateinit var network: MessagingService protected lateinit var network: MessagingService
protected val runOnStop = ArrayList<() -> Any?>() protected val runOnStop = ArrayList<() -> Any?>()
protected lateinit var database: CordaPersistence protected lateinit var database: CordaPersistence
protected var dbCloser: (() -> Any?)? = null
lateinit var cordappProvider: CordappProviderImpl lateinit var cordappProvider: CordappProviderImpl
protected val cordappLoader by lazy { makeCordappLoader() } protected val cordappLoader by lazy { makeCordappLoader() }
@ -476,10 +475,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
database.transaction { database.transaction {
log.info("Connected to ${database.dataSource.connection.metaData.databaseProductName} database.") log.info("Connected to ${database.dataSource.connection.metaData.databaseProductName} database.")
} }
this.database::close.let { runOnStop += database::close
dbCloser = it
runOnStop += it
}
return database.transaction { return database.transaction {
insideTransaction() insideTransaction()
} }

View File

@ -241,6 +241,12 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
// It is used from the network visualiser tool. // It is used from the network visualiser tool.
@Suppress("unused") val place: WorldMapLocation get() = findMyLocation()!! @Suppress("unused") val place: WorldMapLocation get() = findMyLocation()!!
private var dbCloser: (() -> Any?)? = null
override fun <T> initialiseDatabasePersistence(insideTransaction: () -> T) = super.initialiseDatabasePersistence {
dbCloser = database::close
insideTransaction()
}
fun disableDBCloseOnStop() { fun disableDBCloseOnStop() {
runOnStop.remove(dbCloser) runOnStop.remove(dbCloser)
} }