1 /*
2 * Copyright (C) 2016, Google Inc. and others
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Distribution License v. 1.0 which is available at
6 * https://www.eclipse.org/org/documents/edl-v10.php.
7 *
8 * SPDX-License-Identifier: BSD-3-Clause
9 */
10
11 package org.eclipse.jgit.internal.ketch;
12
13 import java.util.Date;
14
15 import org.eclipse.jgit.annotations.Nullable;
16 import org.eclipse.jgit.lib.ObjectId;
17
18 /**
19 * A snapshot of a replica.
20 *
21 * @see LeaderSnapshot
22 */
23 public class ReplicaSnapshot {
24 final KetchReplica replica;
25 ObjectId accepted;
26 ObjectId committed;
27 KetchReplica.State state;
28 String error;
29 long retryAtMillis;
30
31 ReplicaSnapshot(KetchReplica replica) {
32 this.replica = replica;
33 }
34
35 /**
36 * Get the replica this snapshot describes the state of
37 *
38 * @return the replica this snapshot describes the state of
39 */
40 public KetchReplica getReplica() {
41 return replica;
42 }
43
44 /**
45 * Get current state of the replica
46 *
47 * @return current state of the replica
48 */
49 public KetchReplica.State getState() {
50 return state;
51 }
52
53 /**
54 * Get last known Git commit at {@code refs/txn/accepted}
55 *
56 * @return last known Git commit at {@code refs/txn/accepted}
57 */
58 @Nullable
59 public ObjectId getAccepted() {
60 return accepted;
61 }
62
63 /**
64 * Get last known Git commit at {@code refs/txn/committed}
65 *
66 * @return last known Git commit at {@code refs/txn/committed}
67 */
68 @Nullable
69 public ObjectId getCommitted() {
70 return committed;
71 }
72
73 /**
74 * Get error message
75 *
76 * @return if {@link #getState()} ==
77 * {@link org.eclipse.jgit.internal.ketch.KetchReplica.State#OFFLINE}
78 * an optional human-readable message from the transport system
79 * explaining the failure.
80 */
81 @Nullable
82 public String getErrorMessage() {
83 return error;
84 }
85
86 /**
87 * Get when the leader will retry communication with the offline or lagging
88 * replica
89 *
90 * @return time (usually in the future) when the leader will retry
91 * communication with the offline or lagging replica; null if no
92 * retry is scheduled or necessary.
93 */
94 @Nullable
95 public Date getRetryAt() {
96 return retryAtMillis > 0 ? new Date(retryAtMillis) : null;
97 }
98 }