lei-xia commented on a change in pull request #1413:
URL: https://github.com/apache/helix/pull/1413#discussion_r500754642
##########
File path:
helix-core/src/main/java/org/apache/helix/model/ParticipantHistory.java
##########
@@ -153,16 +185,101 @@ private void updateOfflineHistory(long time) {
if (list.size() == HISTORY_SIZE) {
list.remove(0);
}
-
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:SSS");
- df.setTimeZone(TimeZone.getTimeZone("UTC"));
- String dateTime = df.format(new Date(time));
-
- list.add(dateTime);
+ list.add(historyDateLongToString(time));
}
@Override
public boolean isValid() {
return true;
}
+
+ /*
+ * Parses a history date in string format to its millisecond representation.
+ * Returns -1 if parsing fails.
+ */
+ private static long historyDateStringToLong(String dateString) {
+ SimpleDateFormat simpleDateFormat = new
SimpleDateFormat(HISTORY_DATE_FORMAT);
+ simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ try {
+ Date date = simpleDateFormat.parse(dateString);
+ return date.getTime();
+ } catch (ParseException e) {
+ LOG.warn("Failed to parse participant history date string: " +
dateString);
+ return -1;
+ }
+ }
+
+ /*
+ * Parses a history date in millisecond to string.
+ */
+ private static String historyDateLongToString(long dateLong) {
+ DateFormat df = new SimpleDateFormat(HISTORY_DATE_FORMAT);
+ df.setTimeZone(TimeZone.getTimeZone("UTC"));
+ return df.format(new Date(dateLong));
+ }
+
+ /**
+ * Parses the session entry map that has been converted to string back to a
map.
+ * NOTE TO CALLER: This assumes the divider between entries is ", " and the
divider between
+ * key/value is "="; if the string is malformed, parsing correctness is not
guaranteed. Always
+ * check if a key is contained before using the key.
+ */
+ public static Map<String, String> parseSessionHistoryStringToMap(String
sessionHistoryString) {
Review comment:
Let us follow the name convention of another method, such as
sessionHistoryStringToMap()?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]