Search in sources :

Example 1 with TransportAuthenticationException

use of io.transport.sdk.exception.TransportAuthenticationException in project transporter by wang4ever.

the class TransportClient method getChannel.

/**
 * 获取channel
 *
 * @param activated
 *            是否获取连接活跃的,否则等待
 * @param loggedin
 *            获取是否已认证的连接(TRUE:若未登录则会等待)
 * @return
 * @throws InterruptedException
 */
public synchronized TransportConnector getChannel(final boolean loggedin) {
    if (this.connector == null)
        throw new TransportInitializeException("Uninitialized client.");
    if (loggedin) {
        // 60*100=6000
        int max = this.config.getLoginTimeout() * 100;
        int c = 0;
        while (c <= max) {
            ++c;
            try {
                this.wait(10L);
            } catch (InterruptedException e) {
                throw new TransportException(e);
            }
            if (!this.isAuthState()) {
                // Unauthenticated
                if (c == max) {
                    // 1.1 外抛未认证异常.
                    throw new TransportAuthenticationException("Authentication timeout.");
                // 这种处理流程,会导致运行一段时间后线程会堵死???
                // 
                // // 1.2 自动发起重认证流程
                // this.client.channel().close(); // 关闭channel
                // this.join(); // 重连、认证
                }
            } else
                break;
        }
    }
    return this.connector;
}
Also used : TransportInitializeException(io.transport.sdk.exception.TransportInitializeException) TransportException(io.transport.sdk.exception.TransportException) TransportAuthenticationException(io.transport.sdk.exception.TransportAuthenticationException)

Example 2 with TransportAuthenticationException

use of io.transport.sdk.exception.TransportAuthenticationException in project transporter by wang4ever.

the class TransportClients method getChannel.

/**
 * 获取channel
 *
 * @param activated
 *            是否获取连接活跃的,否则等待
 * @param loggedin
 *            获取是否已认证的连接(TRUE:若未登录则会等待)
 * @return
 */
public TransportChannel getChannel(final boolean loggedin) {
    if (this.client == null)
        throw new TransportInitializeException("Uninitialized client.");
    if (loggedin) {
        // 60*100=6000
        int max = this.config.getLoginTimeout() * 100;
        int c = 0;
        while (c <= max) {
            ++c;
            Threads.sleep(10L);
            if (!this.isAuthState()) {
                // Unauthenticated
                if (c == max) {
                    // 1.1 外抛未认证异常.
                    throw new TransportAuthenticationException("Authentication timeout.");
                // 
                // 这种处理流程,会导致运行一段时间后线程会堵死???
                // // 1.2 自动发起重认证流程
                // this.client.channel().close(); // 关闭channel
                // this.join(); // 重连、认证
                }
            } else
                break;
        }
    }
    return this.client;
}
Also used : TransportInitializeException(io.transport.sdk.exception.TransportInitializeException) TransportAuthenticationException(io.transport.sdk.exception.TransportAuthenticationException)

Aggregations

TransportAuthenticationException (io.transport.sdk.exception.TransportAuthenticationException)2 TransportInitializeException (io.transport.sdk.exception.TransportInitializeException)2 TransportException (io.transport.sdk.exception.TransportException)1