Bug 2187: AddServer unit test and bug fixes
[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 com.google.common.base.Preconditions;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.controller.cluster.raft.Snapshot;
14
15 /**
16  * Internal message, issued by follower to its actor
17  */
18 public class ApplySnapshot {
19     private final Snapshot snapshot;
20     private final Callback callback;
21
22     public ApplySnapshot(Snapshot snapshot) {
23         this(snapshot, NOOP_CALLBACK);
24     }
25
26     public ApplySnapshot(@Nonnull Snapshot snapshot, @Nonnull Callback callback) {
27         this.snapshot = Preconditions.checkNotNull(snapshot);
28         this.callback = Preconditions.checkNotNull(callback);
29     }
30
31     @Nonnull
32     public Snapshot getSnapshot() {
33         return snapshot;
34     }
35
36     @Nonnull
37     public Callback getCallback() {
38         return callback;
39     }
40
41     public interface Callback {
42         void onSuccess();
43
44         void onFailure();
45     }
46
47     public static Callback NOOP_CALLBACK = new Callback() {
48         @Override
49         public void onSuccess() {
50         }
51
52         @Override
53         public void onFailure() {
54         }
55     };
56 }