pekko/akka-distributed-data/src/main/scala/akka/cluster/ddata/DistributedData.scala

69 lines
2.2 KiB
Scala
Raw Normal View History

/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package akka.cluster.ddata
import akka.actor.ActorRef
import akka.actor.ActorSystem
import akka.actor.ExtendedActorSystem
import akka.actor.Extension
import akka.actor.ExtensionId
import akka.actor.ExtensionIdProvider
import akka.cluster.{ Cluster, UniqueAddress }
import akka.event.Logging
object DistributedData extends ExtensionId[DistributedData] with ExtensionIdProvider {
override def get(system: ActorSystem): DistributedData = super.get(system)
override def lookup = DistributedData
override def createExtension(system: ExtendedActorSystem): DistributedData =
new DistributedData(system)
}
/**
* Akka extension for convenient configuration and use of the
* [[Replicator]]. Configuration settings are defined in the
* `akka.cluster.ddata` section, see `reference.conf`.
*/
class DistributedData(system: ExtendedActorSystem) extends Extension {
private val settings = ReplicatorSettings(system)
implicit val selfUniqueAddress: SelfUniqueAddress = SelfUniqueAddress(Cluster(system).selfUniqueAddress)
/**
* `ActorRef` of the [[Replicator]] .
*/
val replicator: ActorRef =
if (isTerminated) {
val log = Logging(system, getClass)
if (Cluster(system).isTerminated)
log.warning("Replicator points to dead letters, because Cluster is terminated.")
else
log.warning(
"Replicator points to dead letters. Make sure the cluster node has the proper role. " +
Complete logging with SLF4J in Typed, #26537 * TestAppender interaction with LoggingEventFilter * TestAppender plays the same role as classic TestEventList * replace Sl4jLoggingEvent.java * include MDC in testkit.LoggingEvent to allow for custom filter testing MDC * fix tests * fix log events in BehaviorSetKit, using SubstituteLogger * MDC in EventSourcedBehavior * using raw MDC to set the persistenceId and persistencePhase fields * avoid access to MDC ThreadLocal if log isn't used * Automatically enable eventStream Slf4jLogger for Typed (PR #27583) * amend the ActorSystem config on startup when config akka.use-slf4j=on and akka-slf4j in classpath * akka.use-slf4j is defined in akka-actor-typed reference.conf * also enable the Slf4jLoggingFilter automatically * remove config in tests * Include actor path as akkaSource in MDC (PR #27587) * move logger init to ActorContextImpl since not specific to untyped (ActorContextAdapter) * careful to not access MDC ThreadLocal if logging isn't used (per message) * MDC is cleared (if used) from aroundReceive in ActorAdapter after processing each message * also changed MDC for EventSourcedBehavior to rely on context.log and the outer MDC.clear() * just removing the MDC values is not enough because the empty Map remains in the ThreadLocal * Optimization of MDC interceptor (PR #27610) * Extension methods to Logger as workaround for overload and varargs problem (PR #27605) * "ambiguous reference to overloaded definition" for 2 arg method * varargs not supported for primitive types * providing extension methods info2 and infoN (and friends) via implicit class LoggerOps as more convenient workaround for these problems * New API for Typed LoggingEventFilter (PR #27611) * builder style * will make it easier to add more conditions * all conditions are AND:ed together which makes it easier to define custom filters * simplifies the implementation as a bonus * javadsl * use new api in all tests * leeway setting * verify that occurrences = 0 works * use javadsl in two tests * change interceptLogger, and some other feedback * Testing utility to silence logging until failure (PR #27588) * Logback appender that captures all log events and can flush them later to other appenders * LogCapturing mixin for ScalaTest that flush the captured logging events when a test fails. Also clears the captured events after all tests. * Configuration in logback-test.xml * log capturing for JUnit tests too, using TestRule * Silence initial setup logging from Logback * make LogCapturing public * use LogCapturing in all tests * aside from multi-jvm, and a few extending AkkaSpec, so far * a few doc tests needed debug level * mention in migration guide * rename setLoggerClass to setLoggerName * check for logback dependency to give nicer error message * fix filterKeys, deprecated in 2.13
2019-08-24 08:46:39 +02:00
"Node has roles [{}], Distributed Data is configured for roles [{}].",
Cluster(system).selfRoles.mkString(","),
Complete logging with SLF4J in Typed, #26537 * TestAppender interaction with LoggingEventFilter * TestAppender plays the same role as classic TestEventList * replace Sl4jLoggingEvent.java * include MDC in testkit.LoggingEvent to allow for custom filter testing MDC * fix tests * fix log events in BehaviorSetKit, using SubstituteLogger * MDC in EventSourcedBehavior * using raw MDC to set the persistenceId and persistencePhase fields * avoid access to MDC ThreadLocal if log isn't used * Automatically enable eventStream Slf4jLogger for Typed (PR #27583) * amend the ActorSystem config on startup when config akka.use-slf4j=on and akka-slf4j in classpath * akka.use-slf4j is defined in akka-actor-typed reference.conf * also enable the Slf4jLoggingFilter automatically * remove config in tests * Include actor path as akkaSource in MDC (PR #27587) * move logger init to ActorContextImpl since not specific to untyped (ActorContextAdapter) * careful to not access MDC ThreadLocal if logging isn't used (per message) * MDC is cleared (if used) from aroundReceive in ActorAdapter after processing each message * also changed MDC for EventSourcedBehavior to rely on context.log and the outer MDC.clear() * just removing the MDC values is not enough because the empty Map remains in the ThreadLocal * Optimization of MDC interceptor (PR #27610) * Extension methods to Logger as workaround for overload and varargs problem (PR #27605) * "ambiguous reference to overloaded definition" for 2 arg method * varargs not supported for primitive types * providing extension methods info2 and infoN (and friends) via implicit class LoggerOps as more convenient workaround for these problems * New API for Typed LoggingEventFilter (PR #27611) * builder style * will make it easier to add more conditions * all conditions are AND:ed together which makes it easier to define custom filters * simplifies the implementation as a bonus * javadsl * use new api in all tests * leeway setting * verify that occurrences = 0 works * use javadsl in two tests * change interceptLogger, and some other feedback * Testing utility to silence logging until failure (PR #27588) * Logback appender that captures all log events and can flush them later to other appenders * LogCapturing mixin for ScalaTest that flush the captured logging events when a test fails. Also clears the captured events after all tests. * Configuration in logback-test.xml * log capturing for JUnit tests too, using TestRule * Silence initial setup logging from Logback * make LogCapturing public * use LogCapturing in all tests * aside from multi-jvm, and a few extending AkkaSpec, so far * a few doc tests needed debug level * mention in migration guide * rename setLoggerClass to setLoggerName * check for logback dependency to give nicer error message * fix filterKeys, deprecated in 2.13
2019-08-24 08:46:39 +02:00
settings.roles.mkString(","): Any)
system.deadLetters
} else {
system.systemActorOf(Replicator.props(settings), ReplicatorSettings.name(system, None))
}
/**
* Returns true if this member is not tagged with the role configured for the
* replicas.
*/
def isTerminated: Boolean =
Cluster(system).isTerminated || !settings.roles.subsetOf(Cluster(system).selfRoles)
}
/**
* Cluster non-specific (typed vs classic) wrapper for [[akka.cluster.UniqueAddress]].
*/
@SerialVersionUID(1L)
final case class SelfUniqueAddress(uniqueAddress: UniqueAddress)