1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.snapshot;
19
20 import java.io.IOException;
21 import java.io.DataInput;
22 import java.io.DataOutput;
23
24 import org.apache.hadoop.io.Writable;
25 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
26 import org.apache.hadoop.hbase.util.Bytes;
27
28
29
30
31 public class HSnapshotDescription implements Writable {
32 private SnapshotDescription proto;
33
34 public HSnapshotDescription() {
35 }
36
37 public HSnapshotDescription(final SnapshotDescription proto) {
38 assert proto != null : "proto must be non-null";
39 this.proto = proto;
40 }
41
42 public String getName() {
43 return this.proto.getName();
44 }
45
46 public SnapshotDescription getProto() {
47 return this.proto;
48 }
49
50 public SnapshotDescription.Type getType() {
51 return this.proto.getType();
52 }
53
54 public String getTable() {
55 return this.proto.getTable();
56 }
57
58 public boolean hasTable() {
59 return this.proto.hasTable();
60 }
61
62 public long getCreationTime() {
63 return this.proto.getCreationTime();
64 }
65
66 public int getVersion() {
67 return this.proto.getVersion();
68 }
69
70 public String toString() {
71 if (this.proto != null) {
72 return this.proto.toString();
73 }
74 return "(no snapshot)";
75 }
76
77 public boolean equals(Object obj) {
78 if (this == obj) {
79 return true;
80 }
81 if (obj == null) {
82 return false;
83 }
84 if (!(obj instanceof HSnapshotDescription)) {
85 return false;
86 }
87 SnapshotDescription oproto = ((HSnapshotDescription)obj).getProto();
88 if (this.proto == oproto) {
89 return true;
90 }
91 if (this.proto == null && oproto != null) {
92 return false;
93 }
94 return this.proto.equals(oproto);
95 }
96
97
98
99
100
101
102 @Override
103 public void readFields(DataInput in) throws IOException {
104 byte[] data = Bytes.readByteArray(in);
105 if (data.length > 0) {
106 this.proto = SnapshotDescription.parseFrom(data);
107 } else {
108 this.proto = null;
109 }
110 }
111
112
113
114
115
116 @Override
117 public void write(DataOutput out) throws IOException {
118 if (this.proto != null) {
119 Bytes.writeByteArray(out, this.proto.toByteArray());
120 } else {
121 Bytes.writeByteArray(out, new byte[0]);
122 }
123 }
124 }