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 60
 			return null;
61 61
 		}
62 62
 
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;
63
+		return toSyncState(syncKey);
69 64
 
70 65
 	}
71 66
 
... ...
@@ -88,11 +85,24 @@ public class StateMachine {
88 88
 			return ret;
89 89
 		}
90 90
 
91
+		return toSyncState(syncKey);
92
+	}
93
+
94
+	private SyncState toSyncState(String syncKey) {
91 95
 		Iterator<String> sss = Splitter.on("-").split(syncKey).iterator();
96
+
97
+		String syncKeyVersion = sss.next();
98
+		if (SYNCKEY_VERSION.equals(syncKeyVersion)) {
99
+			logger.warn("SyncKey '{}' version mismatch. Expected: '{}', was '{}'", syncKey, SYNCKEY_VERSION,
100
+					syncKeyVersion);
101
+			return null;
102
+		}
103
+
92 104
 		SyncState ret = new SyncState();
93 105
 		ret.date = new DateTime(Long.parseLong(sss.next()));
94 106
 		ret.type = ItemDataType.valueOf(sss.next());
95 107
 		ret.version = Long.parseLong(sss.next());
108
+
96 109
 		return ret;
97 110
 	}
98 111
 
... ...
@@ -108,6 +118,8 @@ public class StateMachine {
108 108
 
109 109
 		StringBuilder sk = new StringBuilder(64);
110 110
 
111
+		sk.append(SYNCKEY_VERSION);
112
+		sk.append("-");
111 113
 		sk.append(System.currentTimeMillis());
112 114
 		sk.append("-");
113 115
 		sk.append(type.asXmlValue());