Shutdown/cleanup cluster extension if actor init fails, see #3162

* Stop ClusterDaemon if init of core actor fails.
* Activate jmx-enabled setting
* Adjust the err msg of InvalidActorNameException to match conventions
This commit is contained in:
Patrik Nordwall 2013-03-19 17:36:36 +01:00
parent 83541e8abf
commit 08d2dec785
2 changed files with 19 additions and 8 deletions

View file

@ -29,6 +29,7 @@ import akka.remote.FailureDetector
import com.typesafe.config.Config
import akka.event.LoggingAdapter
import java.util.concurrent.ThreadFactory
import scala.util.control.NonFatal
/**
* Cluster Extension Id and factory for creating Cluster extension.
@ -86,6 +87,8 @@ class Cluster(val system: ExtendedActorSystem) extends Extension {
private val _isTerminated = new AtomicBoolean(false)
private val log = Logging(system, "Cluster")
// ClusterJmx is initialized as the last thing in the constructor
private var clusterJmx: Option[ClusterJmx] = None
log.info("Cluster Node [{}] - is starting up...", selfAddress)
@ -157,7 +160,14 @@ class Cluster(val system: ExtendedActorSystem) extends Extension {
*/
private[cluster] val clusterCore: ActorRef = {
implicit val timeout = system.settings.CreationTimeout
Await.result((clusterDaemons ? InternalClusterAction.GetClusterCoreRef).mapTo[ActorRef], timeout.duration)
try {
Await.result((clusterDaemons ? InternalClusterAction.GetClusterCoreRef).mapTo[ActorRef], timeout.duration)
} catch {
case NonFatal(e)
log.error(e, "Failed to startup Cluster")
shutdown()
throw e
}
}
@volatile
@ -170,11 +180,12 @@ class Cluster(val system: ExtendedActorSystem) extends Extension {
system.registerOnTermination(shutdown())
private val clusterJmx: Option[ClusterJmx] = {
val jmx = new ClusterJmx(this, log)
jmx.createMBean()
Some(jmx)
}
if (JmxEnabled)
clusterJmx = {
val jmx = new ClusterJmx(this, log)
jmx.createMBean()
Some(jmx)
}
log.info("Cluster Node [{}] - has started up successfully", selfAddress)