diff --git a/remote/src/main/scala/org/apache/pekko/remote/DefaultFailureDetectorRegistry.scala b/remote/src/main/scala/org/apache/pekko/remote/DefaultFailureDetectorRegistry.scala index 914c9721ef3..21174968c73 100644 --- a/remote/src/main/scala/org/apache/pekko/remote/DefaultFailureDetectorRegistry.scala +++ b/remote/src/main/scala/org/apache/pekko/remote/DefaultFailureDetectorRegistry.scala @@ -59,8 +59,8 @@ class DefaultFailureDetectorRegistry[A](detectorFactory: () => FailureDetector) // address below was introduced as a var because of binary compatibility constraints newDetector match { - case phi: PhiAccrualFailureDetector => phi.address = resource.toString - case _ => + case dwa: FailureDetectorWithAddress => dwa.address = resource.toString + case _ => } newDetector.heartbeat() diff --git a/remote/src/main/scala/org/apache/pekko/remote/FailureDetector.scala b/remote/src/main/scala/org/apache/pekko/remote/FailureDetector.scala index de322165ba7..5363a6d2f87 100644 --- a/remote/src/main/scala/org/apache/pekko/remote/FailureDetector.scala +++ b/remote/src/main/scala/org/apache/pekko/remote/FailureDetector.scala @@ -40,6 +40,16 @@ trait FailureDetector { } +trait FailureDetectorWithAddress { + + /** + * Address of observed host will be set after detector creation. + */ + def address_=(addr: String): Unit + + private[pekko] def address: String +} + object FailureDetector { /** @@ -50,6 +60,6 @@ object FailureDetector { abstract class Clock extends (() => Long) implicit val defaultClock: Clock = new Clock { - def apply() = NANOSECONDS.toMillis(System.nanoTime) + def apply(): Long = NANOSECONDS.toMillis(System.nanoTime) } } diff --git a/remote/src/main/scala/org/apache/pekko/remote/PhiAccrualFailureDetector.scala b/remote/src/main/scala/org/apache/pekko/remote/PhiAccrualFailureDetector.scala index 619649dae37..6e195e4cdac 100644 --- a/remote/src/main/scala/org/apache/pekko/remote/PhiAccrualFailureDetector.scala +++ b/remote/src/main/scala/org/apache/pekko/remote/PhiAccrualFailureDetector.scala @@ -73,7 +73,7 @@ class PhiAccrualFailureDetector( eventStream: Option[EventStream])( implicit clock: Clock) - extends FailureDetector { + extends FailureDetector with FailureDetectorWithAddress { /** * Constructor without eventStream to support backwards compatibility @@ -118,8 +118,10 @@ class PhiAccrualFailureDetector( private val acceptableHeartbeatPauseMillis = acceptableHeartbeatPause.toMillis + def address_=(addr: String): Unit = this._address = addr + private[pekko] def address: String = this._address // address below was introduced as a var because of binary compatibility constraints - private[pekko] var address: String = "N/A" + private var _address: String = "N/A" /** * Implement using optimistic lockless concurrency, all state is represented