Example usage for io.netty.util.concurrent Promise tryFailure

List of usage examples for io.netty.util.concurrent Promise tryFailure

Introduction

In this page you can find the example usage for io.netty.util.concurrent Promise tryFailure.

Prototype

boolean tryFailure(Throwable cause);

Source Link

Document

Marks this future as a failure and notifies all listeners.

Usage

From source file:org.redisson.connection.ConnectionEntry.java

License:Apache License

public Future<RedisPubSubConnection> connectPubSub(final MasterSlaveServersConfig config) {
    final Promise<RedisPubSubConnection> connectionFuture = client.getBootstrap().group().next().newPromise();
    Future<RedisPubSubConnection> future = client.connectPubSubAsync();
    future.addListener(new FutureListener<RedisPubSubConnection>() {
        @Override/*w w  w .  ja  v  a  2 s  .com*/
        public void operationComplete(Future<RedisPubSubConnection> future) throws Exception {
            if (!future.isSuccess()) {
                connectionFuture.tryFailure(future.cause());
                return;
            }
            RedisPubSubConnection conn = future.getNow();
            log.debug("new pubsub connection created: {}", conn);

            FutureConnectionListener<RedisPubSubConnection> listener = new FutureConnectionListener<RedisPubSubConnection>(
                    connectionFuture, conn);
            connectListener.onConnect(config, nodeType, listener);
            listener.executeCommands();

            addReconnectListener(config, conn);
        }
    });
    return connectionFuture;
}

From source file:org.redisson.misc.ConnectionPool.java

License:Apache License

private void initConnections(final ClientConnectionsEntry entry, final Promise<Void> initPromise,
        boolean checkFreezed) {
    int minimumIdleSize = getMinimumIdleSize(entry);

    if (minimumIdleSize == 0 || (checkFreezed && entry.isFreezed())) {
        initPromise.setSuccess(null);//from w w w .  j a v a2  s. c o  m
        return;
    }

    final AtomicInteger initializedConnections = new AtomicInteger(minimumIdleSize);
    for (int i = 0; i < minimumIdleSize; i++) {
        if ((checkFreezed && entry.isFreezed()) || !tryAcquireConnection(entry)) {
            Throwable cause = new RedisConnectionException(
                    "Can't init enough connections amount! " + initializedConnections.get() + " from "
                            + minimumIdleSize + " was initialized. Server: " + entry.getClient().getAddr());
            initPromise.tryFailure(cause);
            return;
        }

        Future<T> promise = connectTo(entry);
        promise.addListener(new FutureListener<T>() {
            @Override
            public void operationComplete(Future<T> future) throws Exception {
                if (future.isSuccess()) {
                    T conn = future.getNow();
                    releaseConnection(entry, conn);
                }
                releaseConnection(entry);
                if (!future.isSuccess()) {
                    Throwable cause = new RedisConnectionException(
                            "Can't init enough connections amount! from " + entry.getClient().getAddr());
                    initPromise.tryFailure(cause);
                    return;
                }

                if (initializedConnections.decrementAndGet() == 0) {
                    initPromise.setSuccess(null);
                }
            }
        });
    }
}

From source file:org.redisson.misc.ConnectionPool.java

License:Apache License

private void promiseFailure(ClientConnectionsEntry entry, Promise<T> promise, Throwable cause) {
    if (entry.incFailedAttempts() == config.getFailedAttempts()) {
        checkForReconnect(entry);//from w  w w . jav  a2 s  .  c o  m
    }

    promise.tryFailure(cause);
}

From source file:org.redisson.misc.ConnectionPool.java

License:Apache License

private void promiseFailure(ClientConnectionsEntry entry, Promise<T> promise, T conn) {
    int attempts = entry.incFailedAttempts();
    if (attempts == config.getFailedAttempts()) {
        checkForReconnect(entry);//from  w  w  w.j  a  va 2s .c o  m
    } else if (attempts < config.getFailedAttempts()) {
        releaseConnection(entry, conn);
    }

    releaseConnection(entry);

    RedisConnectionException cause = new RedisConnectionException(conn + " is not active!");
    promise.tryFailure(cause);
}