mirror of
https://github.com/corda/corda.git
synced 2024-12-19 21:17:58 +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 notary: NotaryConfig?
|
||||||
val activeMQServer: ActiveMqServerConfiguration
|
val activeMQServer: ActiveMqServerConfiguration
|
||||||
val additionalNodeInfoPollingFrequencyMsec: Long
|
val additionalNodeInfoPollingFrequencyMsec: Long
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val disableCheckpointCheckerFlag = "disableCheckpointChecker"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun NodeConfiguration.isDevModeOptionsFlagSet(flag: String):Boolean{
|
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.Checkpoint
|
||||||
import net.corda.node.services.api.CheckpointStorage
|
import net.corda.node.services.api.CheckpointStorage
|
||||||
import net.corda.node.services.api.ServiceHubInternal
|
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.config.isDevModeOptionsFlagSet
|
||||||
import net.corda.node.services.messaging.ReceivedMessage
|
import net.corda.node.services.messaging.ReceivedMessage
|
||||||
import net.corda.node.services.messaging.TopicSession
|
import net.corda.node.services.messaging.TopicSession
|
||||||
@ -89,7 +90,9 @@ class StateMachineManagerImpl(
|
|||||||
private val scheduler = FiberScheduler()
|
private val scheduler = FiberScheduler()
|
||||||
private val mutex = ThreadBox(InnerState())
|
private val mutex = ThreadBox(InnerState())
|
||||||
// This thread (only enabled in dev mode) deserialises checkpoints in the background to shake out bugs in checkpoint restore.
|
// 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
|
@Volatile private var unrestorableCheckpoints = false
|
||||||
|
|
||||||
|
@ -5,15 +5,25 @@ import java.util.concurrent.Executors
|
|||||||
import java.util.concurrent.ThreadFactory
|
import java.util.concurrent.ThreadFactory
|
||||||
import java.util.concurrent.atomic.AtomicInteger
|
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{
|
class NamedThreadFactory(private val name:String, private val underlyingFactory: ThreadFactory) : ThreadFactory{
|
||||||
val threadNumber = AtomicInteger(1)
|
val threadNumber = AtomicInteger(1)
|
||||||
override fun newThread(r: Runnable?): Thread {
|
override fun newThread(runnable: Runnable?): Thread {
|
||||||
val t = underlyingFactory.newThread(r)
|
val thread = underlyingFactory.newThread(runnable)
|
||||||
t.name = name + "-" + threadNumber.getAndIncrement()
|
thread.name = name + "-" + threadNumber.getAndIncrement()
|
||||||
return t
|
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 {
|
fun newNamedSingleThreadExecutor(name: String): ExecutorService {
|
||||||
return Executors.newSingleThreadExecutor(NamedThreadFactory(name, Executors.defaultThreadFactory()))
|
return Executors.newSingleThreadExecutor(NamedThreadFactory(name, Executors.defaultThreadFactory()))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user