Browse code

FEATBL-664 Feat: introduce synckey version

David Phan authored on 05/12/2018 14:47:28
Showing 1 changed files
... ...
@@ -37,6 +37,8 @@ public class StateMachine {
37 37
 
38 38
 	protected static final Logger logger = LoggerFactory.getLogger(StateMachine.class);
39 39
 
40
+	private static final String SYNCKEY_VERSION = "4_0";
41
+
40 42
 	private ISyncStorage store;
41 43
 
42 44
 	public StateMachine(ISyncStorage store) {
... ...
@@ -60,12 +62,7 @@ public class StateMachine {
60 62
 			return null;
61 63
 		}
62 64
 
63
-		Iterator<String> sss = Splitter.on("-").split(syncKey).iterator();
64
-		SyncState ret = new SyncState();
65
-		ret.date = new DateTime(Long.parseLong(sss.next()));
66
-		ret.type = ItemDataType.valueOf(sss.next());
67
-		ret.version = Long.parseLong(sss.next());
68
-		return ret;
65
+		return toSyncState(syncKey);
69 66
 
70 67
 	}
71 68
 
... ...
@@ -88,11 +85,24 @@ public class StateMachine {
88 85
 			return ret;
89 86
 		}
90 87
 
88
+		return toSyncState(syncKey);
89
+	}
90
+
91
+	private SyncState toSyncState(String syncKey) {
91 92
 		Iterator<String> sss = Splitter.on("-").split(syncKey).iterator();
93
+
94
+		String syncKeyVersion = sss.next();
95
+		if (SYNCKEY_VERSION.equals(syncKeyVersion)) {
96
+			logger.warn("SyncKey '{}' version mismatch. Expected: '{}', was '{}'", syncKey, SYNCKEY_VERSION,
97
+					syncKeyVersion);
98
+			return null;
99
+		}
100
+
92 101
 		SyncState ret = new SyncState();
93 102
 		ret.date = new DateTime(Long.parseLong(sss.next()));
94 103
 		ret.type = ItemDataType.valueOf(sss.next());
95 104
 		ret.version = Long.parseLong(sss.next());
105
+
96 106
 		return ret;
97 107
 	}
98 108
 
... ...
@@ -108,6 +118,8 @@ public class StateMachine {
108 118
 
109 119
 		StringBuilder sk = new StringBuilder(64);
110 120
 
121
+		sk.append(SYNCKEY_VERSION);
122
+		sk.append("-");
111 123
 		sk.append(System.currentTimeMillis());
112 124
 		sk.append("-");
113 125
 		sk.append(type.asXmlValue());