format source with scalafmt
This commit is contained in:
parent
0f40491d42
commit
ce404e4f53
1669 changed files with 43208 additions and 35404 deletions
|
|
@ -26,6 +26,7 @@ sealed abstract class CollectionControlMessage extends Serializable
|
|||
*/
|
||||
@SerialVersionUID(1L)
|
||||
case object CollectionStartMessage extends CollectionControlMessage {
|
||||
|
||||
/** Java API */
|
||||
def getInstance = CollectionStartMessage
|
||||
}
|
||||
|
|
@ -35,6 +36,7 @@ case object CollectionStartMessage extends CollectionControlMessage {
|
|||
*/
|
||||
@SerialVersionUID(1L)
|
||||
case object CollectionStopMessage extends CollectionControlMessage {
|
||||
|
||||
/** Java API */
|
||||
def getInstance = CollectionStopMessage
|
||||
}
|
||||
|
|
@ -59,7 +61,8 @@ private[metrics] class ClusterMetricsSupervisor extends Actor with ActorLogging
|
|||
if (CollectorEnabled) {
|
||||
self ! CollectionStartMessage
|
||||
} else {
|
||||
log.warning(s"Metrics collection is disabled in configuration. Use subtypes of ${classOf[CollectionControlMessage].getName} to manage collection at runtime.")
|
||||
log.warning(
|
||||
s"Metrics collection is disabled in configuration. Use subtypes of ${classOf[CollectionControlMessage].getName} to manage collection at runtime.")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -87,6 +90,7 @@ trait ClusterMetricsEvent
|
|||
* Current snapshot of cluster node metrics.
|
||||
*/
|
||||
final case class ClusterMetricsChanged(nodeMetrics: Set[NodeMetrics]) extends ClusterMetricsEvent {
|
||||
|
||||
/** Java API */
|
||||
def getNodeMetrics: java.lang.Iterable[NodeMetrics] =
|
||||
scala.collection.JavaConverters.asJavaIterableConverter(nodeMetrics).asJava
|
||||
|
|
@ -107,8 +111,9 @@ private[metrics] trait ClusterMetricsMessage extends Serializable
|
|||
* Envelope adding a sender address to the cluster metrics gossip.
|
||||
*/
|
||||
@SerialVersionUID(1L)
|
||||
private[metrics] final case class MetricsGossipEnvelope(from: Address, gossip: MetricsGossip, reply: Boolean) extends ClusterMetricsMessage
|
||||
with DeadLetterSuppression
|
||||
private[metrics] final case class MetricsGossipEnvelope(from: Address, gossip: MetricsGossip, reply: Boolean)
|
||||
extends ClusterMetricsMessage
|
||||
with DeadLetterSuppression
|
||||
|
||||
/**
|
||||
* INTERNAL API.
|
||||
|
|
@ -129,7 +134,7 @@ private[metrics] class ClusterMetricsCollector extends Actor with ActorLogging {
|
|||
import Member.addressOrdering
|
||||
import context.dispatcher
|
||||
val cluster = Cluster(context.system)
|
||||
import cluster.{ selfAddress, scheduler }
|
||||
import cluster.{ scheduler, selfAddress }
|
||||
import cluster.ClusterLogger._
|
||||
val metrics = ClusterMetricsExtension(context.system)
|
||||
import metrics.settings._
|
||||
|
|
@ -152,16 +157,16 @@ private[metrics] class ClusterMetricsCollector extends Actor with ActorLogging {
|
|||
/**
|
||||
* Start periodic gossip to random nodes in cluster
|
||||
*/
|
||||
val gossipTask = scheduler.schedule(
|
||||
PeriodicTasksInitialDelay max CollectorGossipInterval,
|
||||
CollectorGossipInterval, self, GossipTick)
|
||||
val gossipTask =
|
||||
scheduler.schedule(PeriodicTasksInitialDelay max CollectorGossipInterval, CollectorGossipInterval, self, GossipTick)
|
||||
|
||||
/**
|
||||
* Start periodic metrics collection
|
||||
*/
|
||||
val sampleTask = scheduler.schedule(
|
||||
PeriodicTasksInitialDelay max CollectorSampleInterval,
|
||||
CollectorSampleInterval, self, MetricsTick)
|
||||
val sampleTask = scheduler.schedule(PeriodicTasksInitialDelay max CollectorSampleInterval,
|
||||
CollectorSampleInterval,
|
||||
self,
|
||||
MetricsTick)
|
||||
|
||||
override def preStart(): Unit = {
|
||||
cluster.subscribe(self, classOf[MemberEvent], classOf[ReachabilityEvent])
|
||||
|
|
@ -186,7 +191,7 @@ private[metrics] class ClusterMetricsCollector extends Actor with ActorLogging {
|
|||
}
|
||||
|
||||
override def postStop: Unit = {
|
||||
cluster unsubscribe self
|
||||
cluster.unsubscribe(self)
|
||||
gossipTask.cancel()
|
||||
sampleTask.cancel()
|
||||
collector.close()
|
||||
|
|
@ -202,7 +207,7 @@ private[metrics] class ClusterMetricsCollector extends Actor with ActorLogging {
|
|||
*/
|
||||
def removeMember(member: Member): Unit = {
|
||||
nodes -= member.address
|
||||
latestGossip = latestGossip remove member.address
|
||||
latestGossip = latestGossip.remove(member.address)
|
||||
publish()
|
||||
}
|
||||
|
||||
|
|
@ -210,7 +215,7 @@ private[metrics] class ClusterMetricsCollector extends Actor with ActorLogging {
|
|||
* Updates the initial node ring for those nodes that are [[akka.cluster.MemberStatus]] `Up`.
|
||||
*/
|
||||
def receiveState(state: CurrentClusterState): Unit =
|
||||
nodes = (state.members diff state.unreachable) collect {
|
||||
nodes = (state.members.diff(state.unreachable)).collect {
|
||||
case m if m.status == MemberStatus.Up || m.status == MemberStatus.WeaklyUp => m.address
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +238,7 @@ private[metrics] class ClusterMetricsCollector extends Actor with ActorLogging {
|
|||
// remote node might not have same view of member nodes, this side should only care
|
||||
// about nodes that are known here, otherwise removed nodes can come back
|
||||
val otherGossip = envelope.gossip.filter(nodes)
|
||||
latestGossip = latestGossip merge otherGossip
|
||||
latestGossip = latestGossip.merge(otherGossip)
|
||||
// changes will be published in the period collect task
|
||||
if (!envelope.reply)
|
||||
replyGossipTo(envelope.from)
|
||||
|
|
@ -242,7 +247,7 @@ private[metrics] class ClusterMetricsCollector extends Actor with ActorLogging {
|
|||
/**
|
||||
* Gossip to peer nodes.
|
||||
*/
|
||||
def gossip(): Unit = selectRandomNode((nodes - selfAddress).toVector) foreach gossipTo
|
||||
def gossip(): Unit = selectRandomNode((nodes - selfAddress).toVector).foreach(gossipTo)
|
||||
|
||||
def gossipTo(address: Address): Unit =
|
||||
sendGossip(address, MetricsGossipEnvelope(selfAddress, latestGossip, reply = false))
|
||||
|
|
@ -254,11 +259,11 @@ private[metrics] class ClusterMetricsCollector extends Actor with ActorLogging {
|
|||
context.actorSelection(self.path.toStringWithAddress(address)) ! envelope
|
||||
|
||||
def selectRandomNode(addresses: immutable.IndexedSeq[Address]): Option[Address] =
|
||||
if (addresses.isEmpty) None else Some(addresses(ThreadLocalRandom.current nextInt addresses.size))
|
||||
if (addresses.isEmpty) None else Some(addresses(ThreadLocalRandom.current.nextInt(addresses.size)))
|
||||
|
||||
/**
|
||||
* Publishes to the event stream.
|
||||
*/
|
||||
def publish(): Unit = context.system.eventStream publish ClusterMetricsChanged(latestGossip.nodes)
|
||||
def publish(): Unit = context.system.eventStream.publish(ClusterMetricsChanged(latestGossip.nodes))
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue