*/
package org.opendaylight.controller.cluster.datastore.actors;
+import static java.util.Objects.requireNonNull;
+
import akka.actor.ActorRef;
import akka.actor.Props;
-import com.google.common.base.Preconditions;
import java.io.IOException;
+import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.Optional;
import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActorWithMetering;
import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot;
import org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState;
import org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* This is an offload actor, which is given an isolated snapshot of the data tree. It performs the potentially
* @author Robert Varga
*/
public final class ShardSnapshotActor extends AbstractUntypedActorWithMetering {
- private static final Logger LOG = LoggerFactory.getLogger(ShardSnapshotActor.class);
-
// Internal message
private static final class SerializeSnapshot {
private final ShardDataTreeSnapshot snapshot;
SerializeSnapshot(final ShardDataTreeSnapshot snapshot, final Optional<OutputStream> installSnapshotStream,
final ActorRef replyTo) {
- this.snapshot = Preconditions.checkNotNull(snapshot);
- this.installSnapshotStream = Preconditions.checkNotNull(installSnapshotStream);
- this.replyTo = Preconditions.checkNotNull(replyTo);
+ this.snapshot = requireNonNull(snapshot);
+ this.installSnapshotStream = requireNonNull(installSnapshotStream);
+ this.replyTo = requireNonNull(replyTo);
}
ShardDataTreeSnapshot getSnapshot() {
}
@Override
- protected void handleReceive(final Object message) throws Exception {
+ protected void handleReceive(final Object message) {
if (message instanceof SerializeSnapshot) {
onSerializeSnapshot((SerializeSnapshot) message);
} else {
}
}
- private void onSerializeSnapshot(SerializeSnapshot request) {
+ private void onSerializeSnapshot(final SerializeSnapshot request) {
Optional<OutputStream> installSnapshotStream = request.getInstallSnapshotStream();
if (installSnapshotStream.isPresent()) {
- try {
- request.getSnapshot().serialize(installSnapshotStream.get());
+ 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);