Permalink
Browse files

Fix links the same as monitoring

  • Loading branch information...
1 parent 73f34e3 commit c21248de846634efc46582aeef1acd5f69bea139 Robert Newson committed Nov 9, 2012
Showing with 30 additions and 5 deletions.
  1. +24 −4 src/main/scala/scalang/Node.scala
  2. +6 −1 src/main/scala/scalang/node/ProcessAdapter.scala
@@ -480,8 +480,11 @@ class ErlangNode(val name : Symbol, val cookie : String, config : NodeConfig) ex
}
if (isLocal(to)) {
- for (p <- process(to)) {
- p.registerLink(from)
+ process(to) match {
+ case Some(p : ProcessAdapter) =>
+ p.registerLink(from)
+ case None =>
+ break(link, 'noproc)
}
} else {
getOrConnectAndSend(to.node, LinkMessage(from, to), { channel =>
@@ -531,8 +534,13 @@ class ErlangNode(val name : Symbol, val cookie : String, config : NodeConfig) ex
if (!isLocal(from))
links.getOrElseUpdate(channel, new NonBlockingHashSet[Link]).add(link)
case None =>
- if (!isLocal(from))
+ if (isLocal(from)) {
+ log.warn("Try to link non-live process %s to %s", from, to)
+ val link = Link(from, to)
+ break(link, 'noproc)
+ } else {
links.getOrElseUpdate(channel, new NonBlockingHashSet[Link]).add(Link(from, to))
+ }
}
process(to) match {
@@ -542,8 +550,13 @@ class ErlangNode(val name : Symbol, val cookie : String, config : NodeConfig) ex
links.getOrElseUpdate(channel, new NonBlockingHashSet[Link]).add(link)
case None =>
- if (!isLocal(to))
+ if (isLocal(to)) {
+ log.warn("Try to link non-live process %s to %s", to, from)
+ val link = Link(from, to)
+ break(link, 'noproc)
+ } else {
links.getOrElseUpdate(channel, new NonBlockingHashSet[Link]).add(Link(from, to))
+ }
}
}
@@ -776,6 +789,13 @@ class ErlangNode(val name : Symbol, val cookie : String, config : NodeConfig) ex
} else {
getOrConnectAndSend(to.node, ExitMessage(from,to,reason))
}
+ if (isLocal(from)) {
+ for (proc <- process(from)) {
+ proc.handleExit(to, reason)
+ }
+ } else {
+ getOrConnectAndSend(from.node, ExitMessage(to,from,reason))
+ }
}
def process(pidOrProc : Any) : Option[ProcessAdapter] = pidOrProc match {
@@ -143,7 +143,12 @@ trait ProcessAdapter extends ExitListenable with SendListenable with LinkListena
for (listener <- linkListeners) {
l.addLinkListener(listener)
}
- links.add(l)
+ synchronized {
+ if (state != 'alive)
+ l.break('noproc)
+ else
+ links.add(l)
+ }
l
}

0 comments on commit c21248d

Please sign in to comment.