gecko/mobile/android/base/sync/repositories/RepositorySessionBundle.java
Nick Alexander e989e12867 Bug 844347 - Factor logging code that is not Sync-specific out of org.mozilla.gecko.sync. r=rnewman
--HG--
rename : mobile/android/base/sync/GlobalConstants.java.in => mobile/android/base/background/common/GlobalConstants.java.in
rename : mobile/android/base/sync/Logger.java => mobile/android/base/background/common/log/Logger.java
rename : mobile/android/base/sync/log/writers/AndroidLevelCachingLogWriter.java => mobile/android/base/background/common/log/writers/AndroidLevelCachingLogWriter.java
rename : mobile/android/base/sync/log/writers/AndroidLogWriter.java => mobile/android/base/background/common/log/writers/AndroidLogWriter.java
rename : mobile/android/base/sync/log/writers/LevelFilteringLogWriter.java => mobile/android/base/background/common/log/writers/LevelFilteringLogWriter.java
rename : mobile/android/base/sync/log/writers/LogWriter.java => mobile/android/base/background/common/log/writers/LogWriter.java
rename : mobile/android/base/sync/log/writers/PrintLogWriter.java => mobile/android/base/background/common/log/writers/PrintLogWriter.java
rename : mobile/android/base/sync/log/writers/SimpleTagLogWriter.java => mobile/android/base/background/common/log/writers/SimpleTagLogWriter.java
rename : mobile/android/base/sync/log/writers/StringLogWriter.java => mobile/android/base/background/common/log/writers/StringLogWriter.java
rename : mobile/android/base/sync/log/writers/TagLogWriter.java => mobile/android/base/background/common/log/writers/TagLogWriter.java
rename : mobile/android/base/sync/log/writers/ThreadLocalTagLogWriter.java => mobile/android/base/background/common/log/writers/ThreadLocalTagLogWriter.java
2013-02-27 15:44:21 -08:00

56 lines
1.7 KiB
Java

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.sync.repositories;
import java.io.IOException;
import org.json.simple.parser.ParseException;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.ExtendedJSONObject;
import org.mozilla.gecko.sync.NonObjectJSONException;
public class RepositorySessionBundle {
public static final String LOG_TAG = RepositorySessionBundle.class.getSimpleName();
protected static final String JSON_KEY_TIMESTAMP = "timestamp";
protected final ExtendedJSONObject object;
public RepositorySessionBundle(String jsonString) throws IOException, ParseException, NonObjectJSONException {
object = ExtendedJSONObject.parseJSONObject(jsonString);
}
public RepositorySessionBundle(long lastSyncTimestamp) {
object = new ExtendedJSONObject();
this.setTimestamp(lastSyncTimestamp);
}
public long getTimestamp() {
if (object.containsKey(JSON_KEY_TIMESTAMP)) {
return object.getLong(JSON_KEY_TIMESTAMP);
}
return -1;
}
public void setTimestamp(long timestamp) {
Logger.debug(LOG_TAG, "Setting timestamp to " + timestamp + ".");
object.put(JSON_KEY_TIMESTAMP, Long.valueOf(timestamp));
}
public void bumpTimestamp(long timestamp) {
long existing = this.getTimestamp();
if (timestamp > existing) {
this.setTimestamp(timestamp);
} else {
Logger.debug(LOG_TAG, "Timestamp " + timestamp + " not greater than " + existing + "; not bumping.");
}
}
public String toJSONString() {
return object.toJSONString();
}
}