1
1
package ginyu .db ;
2
2
3
3
import ginyu .core .ClientTimeoutWrapper ;
4
+ import ginyu .core .Snapshot ;
4
5
import ginyu .event .BlockEvent ;
5
6
import ginyu .object .Dict ;
6
7
import ginyu .object .RedisObject ;
7
8
import lombok .Getter ;
8
- import lombok .NoArgsConstructor ;
9
9
import lombok .Setter ;
10
10
11
11
import java .util .Set ;
18
18
* @description:
19
19
*/
20
20
@ SuppressWarnings ("all" )
21
- public class Database {
21
+ public class Database implements Snapshot {
22
22
23
23
@ Getter
24
24
@ Setter
@@ -30,7 +30,7 @@ public class Database {
30
30
31
31
@ Getter
32
32
@ Setter
33
- private ConcurrentSkipListMap <String , Long > expired ;
33
+ private Dict <String , Long > expired ;
34
34
35
35
private Dict <String , ConcurrentSkipListSet <BlockEvent >> blockingDict ;
36
36
@@ -45,15 +45,15 @@ public Database() {
45
45
public Database (Integer id ) {
46
46
this .id = id ;
47
47
this .dict = new Dict <>();
48
- this .expired = new ConcurrentSkipListMap <>();
48
+ this .expired = new Dict <>();
49
49
this .blockingDict = new Dict <>();
50
50
this .timeoutSets = new ConcurrentSkipListSet <>();
51
51
}
52
52
53
53
public Database (Database database ) {
54
54
this .id = database .id ;
55
55
this .dict = new Dict <>(database .getDict ());
56
- this .expired = new ConcurrentSkipListMap <>(database .getExpired ());
56
+ this .expired = new Dict <>(database .getExpired ());
57
57
this .blockingDict = new Dict <>();
58
58
this .timeoutSets = new ConcurrentSkipListSet <>();
59
59
}
@@ -156,4 +156,13 @@ public void deleteIfNeeded(String key) {
156
156
public void removeBlockKey (String blockKey ) {
157
157
this .blockingDict .remove (blockKey );
158
158
}
159
+
160
+ @ Override
161
+ public String toSnapshot () {
162
+ StringBuilder sb = new StringBuilder ();
163
+ sb .append (this .id );
164
+ sb .append (this .dict .toSnapshot ());
165
+ sb .append (this .expired .toSnapshot ());
166
+ return sb .toString ();
167
+ }
159
168
}
0 commit comments