This repository was archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathDeepstreamClientAbstract.java
More file actions
65 lines (54 loc) · 2.49 KB
/
DeepstreamClientAbstract.java
File metadata and controls
65 lines (54 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package io.deepstream;
import com.google.j2objc.annotations.ObjectiveCName;
import com.google.gson.JsonElement;
abstract class DeepstreamClientAbstract {
private UtilAckTimeoutRegistry utilAckTimeoutRegistry;
private DeepstreamRuntimeErrorHandler deepstreamRuntimeErrorHandler;
@ObjectiveCName("addConnectionChangeListener:")
abstract DeepstreamClientAbstract addConnectionChangeListener(ConnectionStateListener connectionStateListener);
@ObjectiveCName("removeConnectionChangeListener:")
abstract DeepstreamClientAbstract removeConnectionChangeListener(ConnectionStateListener connectionStateListener);
abstract ConnectionState getConnectionState();
abstract LoginResult login();
@ObjectiveCName("login:")
abstract LoginResult login(JsonElement data);
abstract DeepstreamClientAbstract close();
abstract String getUid();
UtilAckTimeoutRegistry getAckTimeoutRegistry() {
if( utilAckTimeoutRegistry == null ) {
utilAckTimeoutRegistry = new UtilAckTimeoutRegistry( this );
}
return utilAckTimeoutRegistry;
}
/**
* Adds a {@link DeepstreamRuntimeErrorHandler} that will catch all RuntimeErrors such as AckTimeouts and allow
* the user to gracefully handle them.
*
* @param deepstreamRuntimeErrorHandler The listener to set
*/
@ObjectiveCName("setRuntimeErrorHandler:")
public void setRuntimeErrorHandler(DeepstreamRuntimeErrorHandler deepstreamRuntimeErrorHandler) {
this.deepstreamRuntimeErrorHandler = deepstreamRuntimeErrorHandler;
}
@ObjectiveCName("onError:event:msg:")
void onError(Topic topic, Event event, String msg) throws DeepstreamException {
/*
* Help to diagnose the problem quicker by checking for
* some mon problems
*/
if (event != null) {
if( event.equals( Event.ACK_TIMEOUT ) || event.equals( Event.RESPONSE_TIMEOUT ) ) {
if( getConnectionState().equals( ConnectionState.AWAITING_AUTHENTICATION ) ) {
String errMsg = "Your message timed out because you\'re not authenticated. Have you called login()?";
onError(Topic.ERROR, Event.NOT_AUTHENTICATED, errMsg);
return;
}
}
}
if( deepstreamRuntimeErrorHandler != null ) {
deepstreamRuntimeErrorHandler.onException( topic, event, msg );
} else {
throw new DeepstreamException( topic, event, msg );
}
}
}