format source with scalafmt

This commit is contained in:
Auto Format 2019-03-11 10:38:24 +01:00 committed by Patrik Nordwall
parent 0f40491d42
commit ce404e4f53
1669 changed files with 43208 additions and 35404 deletions

View file

@ -8,7 +8,17 @@ import java.net.URISyntaxException
import java.util.concurrent.TimeoutException
import akka.actor._
import akka.persistence.{ AtomicWrite, DeleteMessagesFailure, DeleteSnapshotFailure, DeleteSnapshotsFailure, JournalProtocol, NonPersistentRepr, Persistence, SaveSnapshotFailure, SnapshotProtocol }
import akka.persistence.{
AtomicWrite,
DeleteMessagesFailure,
DeleteSnapshotFailure,
DeleteSnapshotsFailure,
JournalProtocol,
NonPersistentRepr,
Persistence,
SaveSnapshotFailure,
SnapshotProtocol
}
import akka.util.Helpers.Requiring
import com.typesafe.config.Config
@ -51,8 +61,11 @@ class PersistencePluginProxyExtensionImpl(system: ActorSystem) extends Extension
PersistencePluginProxy.start(system)
}
object PersistencePluginProxyExtension extends ExtensionId[PersistencePluginProxyExtensionImpl] with ExtensionIdProvider {
override def createExtension(system: ExtendedActorSystem): PersistencePluginProxyExtensionImpl = new PersistencePluginProxyExtensionImpl(system)
object PersistencePluginProxyExtension
extends ExtensionId[PersistencePluginProxyExtensionImpl]
with ExtensionIdProvider {
override def createExtension(system: ExtendedActorSystem): PersistencePluginProxyExtensionImpl =
new PersistencePluginProxyExtensionImpl(system)
override def lookup(): ExtensionId[_ <: Extension] = PersistencePluginProxyExtension
override def get(system: ActorSystem): PersistencePluginProxyExtensionImpl = super.get(system)
}
@ -96,7 +109,8 @@ final class PersistencePluginProxy(config: Config) extends Actor with Stash with
log.info("Setting target {} address to {}", pluginType.qualifier, targetAddress)
PersistencePluginProxy.setTargetLocation(context.system, AddressFromURIString(targetAddress))
} catch {
case _: URISyntaxException => log.warning("Invalid URL provided for target {} address: {}", pluginType.qualifier, targetAddress)
case _: URISyntaxException =>
log.warning("Invalid URL provided for target {} address: {}", pluginType.qualifier, targetAddress)
}
}
@ -107,8 +121,10 @@ final class PersistencePluginProxy(config: Config) extends Actor with Stash with
private val selfAddress: Address =
context.system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress
private def timeoutException() = new TimeoutException(s"Target ${pluginType.qualifier} not initialized. " +
s"Use `PersistencePluginProxy.setTargetLocation` or set `target-${pluginType.qualifier}-address`")
private def timeoutException() =
new TimeoutException(
s"Target ${pluginType.qualifier} not initialized. " +
s"Use `PersistencePluginProxy.setTargetLocation` or set `target-${pluginType.qualifier}-address`")
def receive = init
@ -117,7 +133,10 @@ final class PersistencePluginProxy(config: Config) extends Actor with Stash with
context.setReceiveTimeout(1.second) // for retries
context.become(identifying(address))
case InitTimeout =>
log.info("Initialization timed-out (after {}), Use `PersistencePluginProxy.setTargetLocation` or set `target-{}-address`", initTimeout, pluginType.qualifier)
log.info(
"Initialization timed-out (after {}), Use `PersistencePluginProxy.setTargetLocation` or set `target-{}-address`",
initTimeout,
pluginType.qualifier)
context.become(initTimedOut)
unstashAll() // will trigger appropriate failures
case Terminated(_) =>
@ -137,18 +156,19 @@ final class PersistencePluginProxy(config: Config) extends Actor with Stash with
sel ! Identify(targetPluginId)
}
def identifying(address: Address): Receive = ({
case ActorIdentity(`targetPluginId`, Some(target)) =>
log.info("Found target {} at [{}]", pluginType.qualifier, address)
context.setReceiveTimeout(Duration.Undefined)
context.watch(target)
unstashAll()
context.become(active(target, address == selfAddress))
case _: ActorIdentity => // will retry after ReceiveTimeout
case Terminated(_) =>
case ReceiveTimeout =>
sendIdentify(address)
}: Receive).orElse(init)
def identifying(address: Address): Receive =
({
case ActorIdentity(`targetPluginId`, Some(target)) =>
log.info("Found target {} at [{}]", pluginType.qualifier, address)
context.setReceiveTimeout(Duration.Undefined)
context.watch(target)
unstashAll()
context.become(active(target, address == selfAddress))
case _: ActorIdentity => // will retry after ReceiveTimeout
case Terminated(_) =>
case ReceiveTimeout =>
sendIdentify(address)
}: Receive).orElse(init)
def active(targetJournal: ActorRef, targetAtThisNode: Boolean): Receive = {
case TargetLocation(address) =>
@ -160,44 +180,45 @@ final class PersistencePluginProxy(config: Config) extends Actor with Stash with
case Terminated(_) =>
case InitTimeout =>
case msg =>
targetJournal forward msg
targetJournal.forward(msg)
}
def initTimedOut: Receive = {
case req: JournalProtocol.Request => req match { // exhaustive match
case WriteMessages(messages, persistentActor, actorInstanceId) =>
persistentActor ! WriteMessagesFailed(timeoutException)
messages.foreach {
case a: AtomicWrite =>
a.payload.foreach { p =>
persistentActor ! WriteMessageFailure(p, timeoutException, actorInstanceId)
}
case r: NonPersistentRepr =>
persistentActor ! LoopMessageSuccess(r.payload, actorInstanceId)
}
case ReplayMessages(fromSequenceNr, toSequenceNr, max, persistenceId, persistentActor) =>
persistentActor ! ReplayMessagesFailure(timeoutException)
case DeleteMessagesTo(persistenceId, toSequenceNr, persistentActor) =>
persistentActor ! DeleteMessagesFailure(timeoutException, toSequenceNr)
}
case req: JournalProtocol.Request =>
req match { // exhaustive match
case WriteMessages(messages, persistentActor, actorInstanceId) =>
persistentActor ! WriteMessagesFailed(timeoutException)
messages.foreach {
case a: AtomicWrite =>
a.payload.foreach { p =>
persistentActor ! WriteMessageFailure(p, timeoutException, actorInstanceId)
}
case r: NonPersistentRepr =>
persistentActor ! LoopMessageSuccess(r.payload, actorInstanceId)
}
case ReplayMessages(fromSequenceNr, toSequenceNr, max, persistenceId, persistentActor) =>
persistentActor ! ReplayMessagesFailure(timeoutException)
case DeleteMessagesTo(persistenceId, toSequenceNr, persistentActor) =>
persistentActor ! DeleteMessagesFailure(timeoutException, toSequenceNr)
}
case req: SnapshotProtocol.Request => req match { // exhaustive match
case LoadSnapshot(persistenceId, criteria, toSequenceNr) =>
sender() ! LoadSnapshotFailed(timeoutException)
case SaveSnapshot(metadata, snapshot) =>
sender() ! SaveSnapshotFailure(metadata, timeoutException)
case DeleteSnapshot(metadata) =>
sender() ! DeleteSnapshotFailure(metadata, timeoutException)
case DeleteSnapshots(persistenceId, criteria) =>
sender() ! DeleteSnapshotsFailure(criteria, timeoutException)
}
case req: SnapshotProtocol.Request =>
req match { // exhaustive match
case LoadSnapshot(persistenceId, criteria, toSequenceNr) =>
sender() ! LoadSnapshotFailed(timeoutException)
case SaveSnapshot(metadata, snapshot) =>
sender() ! SaveSnapshotFailure(metadata, timeoutException)
case DeleteSnapshot(metadata) =>
sender() ! DeleteSnapshotFailure(metadata, timeoutException)
case DeleteSnapshots(persistenceId, criteria) =>
sender() ! DeleteSnapshotsFailure(criteria, timeoutException)
}
case TargetLocation(address) =>
becomeIdentifying(address)
case Terminated(_) =>
case other =>
val e = timeoutException()
log.error(e, "Failed PersistencePluginProxy request: {}", e.getMessage)