Skip to content

Commit

Permalink
Merge pull request #24107 from akka/wip-Done-serialization-patriknw
Browse files Browse the repository at this point in the history
adds serializer for akka.Done. #23854
  • Loading branch information
patriknw committed Dec 6, 2017
2 parents fb689ba + 2837ebb commit b1632c9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
5 changes: 4 additions & 1 deletion akka-actor/src/main/scala/akka/Done.scala
Expand Up @@ -3,12 +3,15 @@
*/
package akka

import java.io.Serializable
import akka.annotation.DoNotInherit

/**
* Typically used together with `Future` to signal completion
* but there is no actual value completed. More clearly signals intent
* than `Unit` and is available both from Scala and Java (which `Unit` is not).
*/
sealed abstract class Done
@DoNotInherit sealed abstract class Done extends Serializable

case object Done extends Done {
/**
Expand Down
11 changes: 8 additions & 3 deletions akka-docs/src/main/paradox/serialization.md
Expand Up @@ -41,11 +41,16 @@ depending on the akka-remote module), so normally you don't need to add
configuration for that; since `com.google.protobuf.GeneratedMessage`
implements `java.io.Serializable`, protobuf messages will always be
serialized using the protobuf protocol unless specifically overridden. In order
to disable a default serializer, map its marker type to “none”:
to disable a default serializer, see @ref:[Disabling the Java Serializer](remoting.md#disable-java-serializer)

### Enable additional bindings

`akka.Done` is by default serialized by the Java serializer, add the following binding to avoid that.
It's not enabled by default for compatibility reasons.

```
akka.actor.serialization-bindings {
"java.io.Serializable" = none
"akka.Done" = akka-misc
}
```

Expand Down Expand Up @@ -251,4 +256,4 @@ incompatibility as Java serialization does.

[Akka-kryo by Roman Levenstein](https://github.com/romix/akka-kryo-serialization)

[Twitter Chill Scala extensions for Kryo (based on Akka Version 2.3.x but due to backwards compatibility of the Serializer Interface this extension also works with 2.4.x)](https://github.com/twitter/chill)
[Twitter Chill Scala extensions for Kryo (based on Akka Version 2.3.x but due to backwards compatibility of the Serializer Interface this extension also works with 2.4.x)](https://github.com/twitter/chill)
6 changes: 6 additions & 0 deletions akka-remote/src/main/resources/reference.conf
Expand Up @@ -49,6 +49,12 @@ akka {
"com.google.protobuf.GeneratedMessage" = proto

"java.util.Optional" = akka-misc

# akka.Done is handled by the MiscMessageSerializer, but it is not enabled for
# compatibility reasons (it was added in Akka 2.5.8). Enable by adding
# akka.actor.serialization-bindings {
# "akka.Done" = akka-misc
# }
}

# Additional serialization-bindings that are replacing Java serialization are
Expand Down
Expand Up @@ -8,6 +8,7 @@ import java.nio.charset.StandardCharsets
import java.util.Optional
import java.util.concurrent.TimeUnit

import akka.Done
import akka.actor._
import akka.dispatch.Dispatchers
import akka.remote.routing.RemoteRouterConfig
Expand Down Expand Up @@ -43,6 +44,7 @@ class MiscMessageSerializer(val system: ExtendedActorSystem) extends SerializerW
case PoisonPill ParameterlessSerializedMessage
case Kill ParameterlessSerializedMessage
case RemoteWatcher.Heartbeat ParameterlessSerializedMessage
case Done ParameterlessSerializedMessage
case hbrsp: RemoteWatcher.HeartbeatRsp serializeHeartbeatRsp(hbrsp)
case rs: RemoteScope serializeRemoteScope(rs)
case LocalScope ParameterlessSerializedMessage
Expand Down Expand Up @@ -253,6 +255,7 @@ class MiscMessageSerializer(val system: ExtendedActorSystem) extends SerializerW
private val PoisonPillManifest = "P"
private val KillManifest = "K"
private val RemoteWatcherHBManifest = "RWHB"
private val DoneManifest = "DONE"
private val RemoteWatcherHBRespManifest = "RWHR"
private val ActorInitializationExceptionManifest = "AIEX"
private val LocalScopeManifest = "LS"
Expand Down Expand Up @@ -281,6 +284,7 @@ class MiscMessageSerializer(val system: ExtendedActorSystem) extends SerializerW
PoisonPillManifest ((_) PoisonPill),
KillManifest ((_) Kill),
RemoteWatcherHBManifest ((_) RemoteWatcher.Heartbeat),
DoneManifest ((_) Done),
RemoteWatcherHBRespManifest deserializeHeartbeatRsp,
ActorInitializationExceptionManifest deserializeActorInitializationException,
LocalScopeManifest ((_) LocalScope),
Expand Down Expand Up @@ -311,6 +315,7 @@ class MiscMessageSerializer(val system: ExtendedActorSystem) extends SerializerW
case PoisonPill PoisonPillManifest
case Kill KillManifest
case RemoteWatcher.Heartbeat RemoteWatcherHBManifest
case Done DoneManifest
case _: RemoteWatcher.HeartbeatRsp RemoteWatcherHBRespManifest
case LocalScope LocalScopeManifest
case _: RemoteScope RemoteScopeManifest
Expand Down
Expand Up @@ -15,6 +15,7 @@ import scala.concurrent.duration._
import java.util.Optional
import java.io.NotSerializableException

import akka.Done
import akka.remote.routing.RemoteRouterConfig
import akka.routing._

Expand All @@ -23,6 +24,8 @@ object MiscMessageSerializerSpec {
"""
akka.actor.serialization-bindings {
"akka.remote.serialization.MiscMessageSerializerSpec$TestException" = akka-misc
# not enabled by default
"akka.Done" = akka-misc
}
"""

Expand Down Expand Up @@ -85,6 +88,7 @@ class MiscMessageSerializerSpec extends AkkaSpec(MiscMessageSerializerSpec.testC
"PoisonPill" PoisonPill,
"RemoteWatcher.Heartbeat" RemoteWatcher.Heartbeat,
"RemoteWatcher.HertbeatRsp" RemoteWatcher.HeartbeatRsp(65537),
"Done" Done,
"LocalScope" LocalScope,
"RemoteScope" RemoteScope(Address("akka", "system", "localhost", 2525)),
"Config" system.settings.config,
Expand Down

0 comments on commit b1632c9

Please sign in to comment.