Make sure Serialization.currentTransportInformation is always set, #25067
* The ThreadLocal Serialization.currentTransportInformation is used for serializing local actor refs, but it's also useful when a serializer library e.g. custom serializer/deserializer in Jackson need access to the current ActorSystem. * We set this in a rather ad-hoc way from remoting and in some persistence plugins, but it's only set for serialization and not deserialization, and it's easy for Persistence plugins or other libraries to forget this when using Akka serialization directly. * This change is automatically setting the info when using the ordinary serialize and deserialize methods. * It's also set when LocalActorRefProvider, which wasn't always the case previously. * Keep a cached instance of Serialization.Information in the provider to avoid creating new instances all the time. * Added optional Persistence TCK tests to verify that the plugin is setting this if it's using some custom calls to the serializer.
This commit is contained in:
parent
6ec46e762f
commit
e6633f17fa
36 changed files with 579 additions and 146 deletions
|
|
@ -39,12 +39,6 @@ class MessageSerializer(val system: ExtendedActorSystem) extends BaseSerializer
|
|||
|
||||
override val includeManifest: Boolean = true
|
||||
|
||||
private lazy val transportInformation: Option[Serialization.Information] = {
|
||||
val address = system.provider.getDefaultAddress
|
||||
if (address.hasLocalScope) None
|
||||
else Some(Serialization.Information(address, system))
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes persistent messages. Delegates serialization of a persistent
|
||||
* message's payload to a matching `akka.serialization.Serializer`.
|
||||
|
|
@ -175,11 +169,12 @@ class MessageSerializer(val system: ExtendedActorSystem) extends BaseSerializer
|
|||
builder
|
||||
}
|
||||
|
||||
// serialize actor references with full address information (defaultAddress)
|
||||
transportInformation match {
|
||||
case Some(ti) ⇒ Serialization.currentTransportInformation.withValue(ti) { payloadBuilder() }
|
||||
case None ⇒ payloadBuilder()
|
||||
}
|
||||
val oldInfo = Serialization.currentTransportInformation.value
|
||||
try {
|
||||
if (oldInfo eq null)
|
||||
Serialization.currentTransportInformation.value = system.provider.serializationInformation
|
||||
payloadBuilder()
|
||||
} finally Serialization.currentTransportInformation.value = oldInfo
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue