-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds remaining changes (excluding tests from #842 Changes are received as is and only some name refactorings were made. You should check the linked PR to see individual commits. Tests will be added in subsequent PRs
- Loading branch information
Showing
12 changed files
with
314 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
lib/src/main/java/io/ably/lib/realtime/ConnectionRecoveryKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.ably.lib.realtime; | ||
|
||
import com.google.gson.JsonSyntaxException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import io.ably.lib.util.Log; | ||
import io.ably.lib.util.Serialisation; | ||
|
||
public class ConnectionRecoveryKey { | ||
private static final String TAG = "RecoveryKey"; | ||
|
||
private final String connectionKey; | ||
private final long msgSerial; | ||
/** | ||
* Key - channel name | ||
* <p> | ||
* Value - channelSerial | ||
*/ | ||
private final Map<String, String> serials = new HashMap<>(); | ||
|
||
public ConnectionRecoveryKey(String connectionKey, long msgSerial) { | ||
this.connectionKey = connectionKey; | ||
this.msgSerial = msgSerial; | ||
} | ||
|
||
public String getConnectionKey() { | ||
return connectionKey; | ||
} | ||
|
||
public long getMsgSerial() { | ||
return msgSerial; | ||
} | ||
|
||
public Map<String, String> getSerials() { | ||
return serials; | ||
} | ||
|
||
public void setSerials(Map<String, String> serials) { | ||
this.serials.clear(); | ||
this.serials.putAll(serials); | ||
} | ||
|
||
public void addSerial(String channelName, String channelSerial) { | ||
this.serials.put(channelName, channelSerial); | ||
} | ||
|
||
public String asJson() { | ||
return Serialisation.gson.toJson(this); | ||
} | ||
|
||
public static ConnectionRecoveryKey fromJson(String json) { | ||
try { | ||
return Serialisation.gson.fromJson(json, ConnectionRecoveryKey.class); | ||
} catch (JsonSyntaxException e) { | ||
Log.e(TAG, "Cannot create recovery key from json: " + e.getMessage()); | ||
return null; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.