protected override void process(EzyDisconnectionEvent evt)
        {
            String reasonName = EzyDisconnectReasons.getDisconnectReasonName(evt.getReason());

            logger.info("handle disconnection, reason = " + reasonName);
            preHandle(evt);
            EzyClientConfig    config          = client.getConfig();
            EzyReconnectConfig reconnectConfig = config.getReconnect();
            bool should        = shouldReconnect(evt);
            bool mustReconnect = reconnectConfig.isEnable() &&
                                 evt.getReason() != (int)EzyDisconnectReason.UNAUTHORIZED &&
                                 evt.getReason() != (int)EzyDisconnectReason.CLOSE &&
                                 should;
            bool reconnecting = false;

            client.setStatus(EzyConnectionStatus.DISCONNECTED);
            client.setUdpStatus(EzyConnectionStatus.DISCONNECTED);
            if (mustReconnect)
            {
                reconnecting = client.reconnect();
            }
            if (reconnecting)
            {
                onReconnecting(evt);
            }
            else
            {
                onDisconnected(evt);
            }
            postHandle(evt);
        }
Esempio n. 2
0
        protected EzySocketClient newSocketClient()
        {
            EzyTcpSocketClient client = newTcpSocketClient();

            client.setPingSchedule(pingSchedule);
            client.setPingManager(pingManager);
            client.setNetworkStatistics(networkStatistics);
            client.setHandlerManager(handlerManager);
            client.setReconnectConfig(config.getReconnect());
            client.setUnloggableCommands(unloggableCommands);
            return(client);
        }
        protected override sealed void process(EzyConnectionFailureEvent evt)
        {
            logger.info("connection failure, reason = " + evt.getReason());
            EzyClientConfig    config          = client.getConfig();
            EzyReconnectConfig reconnectConfig = config.getReconnect();
            bool should        = shouldReconnect(evt);
            bool mustReconnect = reconnectConfig.isEnable() && should;
            bool reconnecting  = false;

            client.setStatus(EzyConnectionStatus.FAILURE);
            if (mustReconnect)
            {
                reconnecting = client.reconnect();
            }
            if (reconnecting)
            {
                onReconnecting(evt);
            }
            else
            {
                onConnectionFailed(evt);
            }
            postHandle(evt);
        }