Bug 5740: Add ControlMessage interface to raft messages
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / base / messages / ApplySnapshot.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.raft.base.messages;
10
11 import akka.dispatch.ControlMessage;
12 import com.google.common.base.Preconditions;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
15
16 /**
17  * Internal message, issued by follower to its actor.
18  */
19 public class ApplySnapshot implements ControlMessage {
20     private static final Callback NOOP_CALLBACK = new Callback() {
21         @Override
22         public void onSuccess() {
23             // No-op
24         }
25
26         @Override
27         public void onFailure() {
28             // No-op
29         }
30     };
31
32     private final Snapshot snapshot;
33     private final Callback callback;
34
35     public ApplySnapshot(Snapshot snapshot) {
36         this(snapshot, NOOP_CALLBACK);
37     }
38
39     public ApplySnapshot(@Nonnull Snapshot snapshot, @Nonnull Callback callback) {
40         this.snapshot = Preconditions.checkNotNull(snapshot);
41         this.callback = Preconditions.checkNotNull(callback);
42     }
43
44     @Nonnull
45     public Snapshot getSnapshot() {
46         return snapshot;
47     }
48
49     @Nonnull
50     public Callback getCallback() {
51         return callback;
52     }
53
54     public interface Callback {
55         void onSuccess();
56
57         void onFailure();
58     }
59 }