mirror of
https://github.com/corda/corda.git
synced 2024-12-19 13:08:04 +00:00
Code rewiew:
- add comments - clearer variable names - use constants instead of literal
This commit is contained in:
parent
a4636b0d53
commit
170fde9d71
@ -36,6 +36,10 @@ interface NodeConfiguration : NodeSSLConfiguration {
|
||||
val notary: NotaryConfig?
|
||||
val activeMQServer: ActiveMqServerConfiguration
|
||||
val additionalNodeInfoPollingFrequencyMsec: Long
|
||||
|
||||
companion object {
|
||||
val disableCheckpointCheckerFlag = "disableCheckpointChecker"
|
||||
}
|
||||
}
|
||||
|
||||
fun NodeConfiguration.isDevModeOptionsFlagSet(flag: String):Boolean{
|
||||
|
@ -31,6 +31,7 @@ import net.corda.node.internal.InitiatedFlowFactory
|
||||
import net.corda.node.services.api.Checkpoint
|
||||
import net.corda.node.services.api.CheckpointStorage
|
||||
import net.corda.node.services.api.ServiceHubInternal
|
||||
import net.corda.node.services.config.NodeConfiguration
|
||||
import net.corda.node.services.config.isDevModeOptionsFlagSet
|
||||
import net.corda.node.services.messaging.ReceivedMessage
|
||||
import net.corda.node.services.messaging.TopicSession
|
||||
@ -89,7 +90,9 @@ class StateMachineManagerImpl(
|
||||
private val scheduler = FiberScheduler()
|
||||
private val mutex = ThreadBox(InnerState())
|
||||
// This thread (only enabled in dev mode) deserialises checkpoints in the background to shake out bugs in checkpoint restore.
|
||||
private val checkpointCheckerThread = if (serviceHub.configuration.devMode && !serviceHub.configuration.isDevModeOptionsFlagSet("disableCheckpointChecking")) newNamedSingleThreadExecutor("CheckpointChecker") else null
|
||||
private val checkpointCheckerThread = if (serviceHub.configuration.devMode
|
||||
&& !serviceHub.configuration.isDevModeOptionsFlagSet(NodeConfiguration.disableCheckpointCheckerFlag))
|
||||
newNamedSingleThreadExecutor("CheckpointChecker") else null
|
||||
|
||||
@Volatile private var unrestorableCheckpoints = false
|
||||
|
||||
|
@ -5,15 +5,25 @@ import java.util.concurrent.Executors
|
||||
import java.util.concurrent.ThreadFactory
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
|
||||
/**
|
||||
* Utility class that allows to give threads arbitrary name prefixes when they are created
|
||||
* via an executor. It will use an underlying thread factory to create the actual thread
|
||||
* and then override the thread name with the prefix and an ever increasing number
|
||||
*/
|
||||
class NamedThreadFactory(private val name:String, private val underlyingFactory: ThreadFactory) : ThreadFactory{
|
||||
val threadNumber = AtomicInteger(1)
|
||||
override fun newThread(r: Runnable?): Thread {
|
||||
val t = underlyingFactory.newThread(r)
|
||||
t.name = name + "-" + threadNumber.getAndIncrement()
|
||||
return t
|
||||
override fun newThread(runnable: Runnable?): Thread {
|
||||
val thread = underlyingFactory.newThread(runnable)
|
||||
thread.name = name + "-" + threadNumber.getAndIncrement()
|
||||
return thread
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a single thread executor with a NamedThreadFactory based on the default thread factory
|
||||
* defined in java.util.concurrent.Executors
|
||||
*/
|
||||
fun newNamedSingleThreadExecutor(name: String): ExecutorService {
|
||||
return Executors.newSingleThreadExecutor(NamedThreadFactory(name, Executors.defaultThreadFactory()))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user