Refactor WebSocket support to use Redis for pubsub communication.

This commit is contained in:
Moxie Marlinspike
2014-01-24 12:33:40 -08:00
parent 519f982604
commit 7bb505db4c
19 changed files with 670 additions and 23 deletions

View File

@@ -0,0 +1,11 @@
package org.whispersystems.textsecuregcm.websocket;
public class InvalidWebsocketAddressException extends Exception {
public InvalidWebsocketAddressException(String serialized) {
super(serialized);
}
public InvalidWebsocketAddressException(Exception e) {
super(e);
}
}

View File

@@ -0,0 +1,57 @@
package org.whispersystems.textsecuregcm.websocket;
public class WebsocketAddress {
private final long accountId;
private final long deviceId;
public WebsocketAddress(String serialized) throws InvalidWebsocketAddressException {
try {
String[] parts = serialized.split(":");
if (parts == null || parts.length != 2) {
throw new InvalidWebsocketAddressException(serialized);
}
this.accountId = Long.parseLong(parts[0]);
this.deviceId = Long.parseLong(parts[1]);
} catch (NumberFormatException e) {
throw new InvalidWebsocketAddressException(e);
}
}
public WebsocketAddress(long accountId, long deviceId) {
this.accountId = accountId;
this.deviceId = deviceId;
}
public long getAccountId() {
return accountId;
}
public long getDeviceId() {
return deviceId;
}
public String toString() {
return accountId + ":" + deviceId;
}
@Override
public boolean equals(Object other) {
if (other == null) return false;
if (!(other instanceof WebsocketAddress)) return false;
WebsocketAddress that = (WebsocketAddress)other;
return
this.accountId == that.accountId &&
this.deviceId == that.deviceId;
}
@Override
public int hashCode() {
return (int)accountId ^ (int)deviceId;
}
}

View File

@@ -0,0 +1,18 @@
package org.whispersystems.textsecuregcm.websocket;
import com.fasterxml.jackson.annotation.JsonProperty;
public class WebsocketMessage {
@JsonProperty
private long id;
@JsonProperty
private String message;
public WebsocketMessage(long id, String message) {
this.id = id;
this.message = message;
}
}