Search in sources :

Example 1 with EzyReconnectConfig

use of com.tvd12.ezyfoxserver.client.config.EzyReconnectConfig in project ezyfox-server-android-client by youngmonkeys.

the class EzyConnectionFailureHandler method handle.

@Override
public final void handle(EzyConnectionFailureEvent event) {
    EzyLogger.info("connection failure, reason = " + event.getReason());
    EzyClientConfig config = client.getConfig();
    EzyReconnectConfig reconnectConfig = config.getReconnect();
    boolean shouldReconnect = shouldReconnect(event);
    boolean mustReconnect = reconnectConfig.isEnable() && shouldReconnect;
    boolean reconnecting = false;
    client.setStatus(EzyConnectionStatus.FAILURE);
    if (mustReconnect)
        reconnecting = client.reconnect();
    if (reconnecting) {
        onReconnecting(event);
    } else {
        onConnectionFailed(event);
    }
    postHandle(event);
}
Also used : EzyClientConfig(com.tvd12.ezyfoxserver.client.config.EzyClientConfig) EzyReconnectConfig(com.tvd12.ezyfoxserver.client.config.EzyReconnectConfig)

Example 2 with EzyReconnectConfig

use of com.tvd12.ezyfoxserver.client.config.EzyReconnectConfig in project ezyfox-server-android-client by youngmonkeys.

the class EzyDisconnectionHandler method handle.

@Override
public final void handle(EzyDisconnectionEvent event) {
    String reasonName = EzyDisconnectReasons.getDisconnectReasonName(event.getReason());
    EzyLogger.info("handle disconnection, reason: " + reasonName);
    preHandle(event);
    EzyClientConfig config = client.getConfig();
    EzyReconnectConfig reconnectConfig = config.getReconnect();
    boolean shouldReconnect = shouldReconnect(event);
    boolean mustReconnect = reconnectConfig.isEnable() && event.getReason() != EzyDisconnectReason.UNAUTHORIZED.getId() && event.getReason() != EzyDisconnectReason.CLOSE.getId() && shouldReconnect;
    boolean reconnecting = false;
    client.setStatus(EzyConnectionStatus.DISCONNECTED);
    if (mustReconnect)
        reconnecting = client.reconnect();
    if (reconnecting) {
        onReconnecting(event);
    } else {
        onDisconnected(event);
    }
    postHandle(event);
}
Also used : EzyClientConfig(com.tvd12.ezyfoxserver.client.config.EzyClientConfig) EzyReconnectConfig(com.tvd12.ezyfoxserver.client.config.EzyReconnectConfig)

Aggregations

EzyClientConfig (com.tvd12.ezyfoxserver.client.config.EzyClientConfig)2 EzyReconnectConfig (com.tvd12.ezyfoxserver.client.config.EzyReconnectConfig)2