Skip to content

Commit 0e14f4f

Browse files
committed
toggle for NonBlockingHashMap
1 parent 15c8e17 commit 0e14f4f

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/main/scala/scalang/Node.scala

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,26 @@ trait Node extends ClusterListener with ClusterPublisher {
184184
def timer : HashedWheelTimer
185185
}
186186

187+
object ErlangNode {
188+
189+
def newConcurrentMap[K,V](config : NodeConfig): ConcurrentMap[K,V] = {
190+
if (config.useNBHM) {
191+
new NonBlockingHashMap[K,V]
192+
} else {
193+
new ConcurrentHashMap[K,V]
194+
}
195+
}
196+
197+
def newAtomicMap[K,V](config : NodeConfig): AtomicMap[K,V] = {
198+
if (config.useNBHM) {
199+
AtomicMap.atomicNBHM[K,V]
200+
} else {
201+
AtomicMap.atomicCHM[K,V]
202+
}
203+
}
204+
205+
}
206+
187207
class ErlangNode(val name : Symbol, val cookie : String, config : NodeConfig) extends Node
188208
with ExitListener
189209
with SendListener
@@ -198,11 +218,11 @@ class ErlangNode(val name : Symbol, val cookie : String, config : NodeConfig) ex
198218
val tickTime = config.tickTime
199219
val poolFactory = config.poolFactory
200220
var creation : Int = 0
201-
val processes = new NonBlockingHashMap[Pid,ProcessAdapter]
202-
val registeredNames = new NonBlockingHashMap[Symbol,Pid]
203-
val channels = AtomicMap.atomicNBHM[Symbol,Channel]
204-
val links = AtomicMap.atomicNBHM[Channel,NonBlockingHashSet[Link]]
205-
val monitors = AtomicMap.atomicNBHM[Channel,NonBlockingHashSet[Monitor]]
221+
val processes = ErlangNode.newConcurrentMap[Pid,ProcessAdapter](config)
222+
val registeredNames = ErlangNode.newConcurrentMap[Symbol,Pid](config)
223+
val channels = ErlangNode.newAtomicMap[Symbol,Channel](config)
224+
val links = ErlangNode.newAtomicMap[Channel,NonBlockingHashSet[Link]](config)
225+
val monitors = ErlangNode.newAtomicMap[Channel,NonBlockingHashSet[Monitor]](config)
206226
val pidCount = new AtomicInteger(0)
207227
val pidSerial = new AtomicInteger(0)
208228
val executor = poolFactory.createActorPool

src/main/scala/scalang/NodeConfig.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ case class NodeConfig(
2424
typeFactory : TypeFactory = NoneTypeFactory,
2525
typeEncoder: TypeEncoder = NoneTypeEncoder,
2626
typeDecoder : TypeDecoder = NoneTypeDecoder,
27-
tickTime : Int = 60)
27+
tickTime : Int = 60,
28+
useNBHM: Boolean = true)
2829

2930
object NoneTypeFactory extends TypeFactory {
3031
def createType(name : Symbol, arity : Int, reader : TermReader) = None

0 commit comments

Comments
 (0)