All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alachisoft.ncache.client.internal.communication.ReconnectTask Maven / Gradle / Ivy

There is a newer version: 5.3.0
Show newest version
package com.alachisoft.ncache.client.internal.communication;

import Alachisoft.NCache.Common.Threading.AsyncProcessor;

class ReconnectTask implements AsyncProcessor.IAsyncTask {
    private short _retries = 3;
    private Connection _connection;
    private Broker _parent;

    public ReconnectTask(Broker parent, Connection connection) {
        connection.setIsReconnecting(true);
        _parent = parent;
        _connection = connection;

    }

    public final void Process() {
        try {
            if (_connection == null) {
                return;
            }
            if (_connection.getIsConnected()) {
                return;
            }
            while (_retries-- > 0) {
                try {
                    Exception exception = null;

                    tangible.RefObject tempRef_exception = new tangible.RefObject<>(exception);
                    boolean tempVar = _parent.TryConnecting(_connection, tempRef_exception, 2000, true, _retries == 0);
                    exception = tempRef_exception.argvalue;
                    if (tempVar) {
                        break;
                    }

                    if (exception != null) {
                        if (exception.getMessage().startsWith("System.Exception: Cache is not registered")) {
                            Connection connection = _parent.TryPool();
                            if (connection != null && connection.getIsConnected()) {
                                _parent.GetHashmap(connection);
                                if (_parent.getLogger().getIsErrorLogsEnabled()) {
                                    _parent.getLogger().getNCacheLog().Error("ReconnectTask.Process", "Connection [" + _connection.getIpAddress() + "] Exception->" + exception.toString());
                                }
                            }
                            break;
                        }
                        //Cache might be restarted
                        if (exception.getMessage().startsWith("System.Exception: Cache is not running") && _retries == 0) // then wait till the retries
                        {
                            Connection connection = this._parent.TryPool();
                            if (connection != null && connection.getIsConnected()) {
                                this._parent.GetHashmap(connection);
                                if (_parent.getLogger().getIsErrorLogsEnabled()) {
                                    this._parent.getLogger().getNCacheLog().Error("ReconnectTask.Process", "Connection [" + this._connection.getIpAddress() + "] Exception->" + exception.toString());
                                }
                            }
                            break;
                        }

                        if (_parent.getLogger().getIsErrorLogsEnabled()) {
                            this._parent.getLogger().getNCacheLog().Error("ReconnectTask.Process", "Connection [" + this._connection.getIpAddress() + "] Exception " + exception.toString());
                        }
                    }
                } catch (Throwable e) {
                    if (_parent.getLogger().getIsErrorLogsEnabled()) {
                        _parent.getLogger().getNCacheLog().Error("ReconnectTask.Process", e.toString());
                    }
                    break;
                }
            }
        } finally {
            _parent.UnregisterReconnectTask(_connection.getServerAddress());
            if (this._connection != null) {
                this._connection.setIsReconnecting(false);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy