- public static void requestSnapshot(final ActorRef snapshotActor, ShardDataTreeSnapshot snapshot,
- final ActorRef replyTo) {
- snapshotActor.tell(new SerializeSnapshot(snapshot, replyTo), ActorRef.noSender());
+ private void onSerializeSnapshot(final SerializeSnapshot request) {
+ Optional<OutputStream> installSnapshotStream = request.getInstallSnapshotStream();
+ if (installSnapshotStream.isPresent()) {
+ try (ObjectOutputStream out = new ObjectOutputStream(installSnapshotStream.get())) {
+ request.getSnapshot().serialize(out);
+ } catch (IOException e) {
+ // TODO - we should communicate the failure in the CaptureSnapshotReply.
+ LOG.error("Error serializing snapshot", e);
+ }
+ }
+
+ request.getReplyTo().tell(new CaptureSnapshotReply(new ShardSnapshotState(request.getSnapshot()),
+ installSnapshotStream), ActorRef.noSender());
+ }
+
+ /**
+ * Sends a request to a ShardSnapshotActor to process a snapshot and send a CaptureSnapshotReply.
+ *
+ * @param snapshotActor the ShardSnapshotActor
+ * @param snapshot the snapshot to process
+ * @param installSnapshotStream Optional OutputStream that is present if the snapshot is to also be installed
+ * on a follower.
+ * @param replyTo the actor to which to send the CaptureSnapshotReply
+ */
+ public static void requestSnapshot(final ActorRef snapshotActor, final ShardDataTreeSnapshot snapshot,
+ final Optional<OutputStream> installSnapshotStream, final ActorRef replyTo) {
+ snapshotActor.tell(new SerializeSnapshot(snapshot, installSnapshotStream, replyTo), ActorRef.noSender());