Example usage for io.netty.util.concurrent DefaultPromise DefaultPromise

List of usage examples for io.netty.util.concurrent DefaultPromise DefaultPromise

Introduction

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

Prototype

protected DefaultPromise() 

Source Link

Document

See #executor() for expectations of the executor.

Usage

From source file:io.vertx.core.net.impl.VertxSniHandler.java

License:Open Source License

public VertxSniHandler(SSLHelper helper, VertxInternal vertx) {
    super(input -> {
        return helper.getContext(vertx, input);
    });//from w ww.  j a  va2s  .  c  om
    this.helper = helper;
    this.handshakeFuture = new DefaultPromise<Channel>() {
        @Override
        protected EventExecutor executor() {
            ChannelHandlerContext ctx = context;
            if (ctx == null) {
                throw new IllegalStateException();
            }
            return ctx.executor();
        }
    };
}

From source file:org.redisson.CommandExecutorService.java

License:Apache License

public <T, R> Future<Collection<R>> readAllAsync(RedisCommand<T> command, Object... params) {
    final Promise<Collection<R>> mainPromise = connectionManager.newPromise();
    Promise<R> promise = new DefaultPromise<R>() {
        Queue<R> results = new ConcurrentLinkedQueue<R>();
        AtomicInteger counter = new AtomicInteger(connectionManager.getEntries().keySet().size());

        @Override//  w w  w . j a va2s  . c  o m
        public Promise<R> setSuccess(R result) {
            if (result instanceof Collection) {
                results.addAll((Collection) result);
            } else {
                results.add(result);
            }

            if (counter.decrementAndGet() == 0 && !mainPromise.isDone()) {
                mainPromise.setSuccess(results);
            }
            return this;
        }

        @Override
        public Promise<R> setFailure(Throwable cause) {
            mainPromise.setFailure(cause);
            return this;
        }

    };

    for (Integer slot : connectionManager.getEntries().keySet()) {
        async(true, slot, null, connectionManager.getCodec(), command, params, promise, 0);
    }
    return mainPromise;
}

From source file:org.redisson.CommandExecutorService.java

License:Apache License

public <T, R> Future<R> allAsync(boolean readOnlyMode, RedisCommand<T> command,
        final SlotCallback<T, R> callback, Object... params) {
    final Promise<R> mainPromise = connectionManager.newPromise();
    Promise<T> promise = new DefaultPromise<T>() {
        AtomicInteger counter = new AtomicInteger(connectionManager.getEntries().keySet().size());

        @Override/* w  ww  . j  a  va 2  s . co m*/
        public Promise<T> setSuccess(T result) {
            if (callback != null) {
                callback.onSlotResult(result);
            }
            if (counter.decrementAndGet() == 0) {
                if (callback != null) {
                    mainPromise.setSuccess(callback.onFinish());
                } else {
                    mainPromise.setSuccess(null);
                }
            }
            return this;
        }

        @Override
        public Promise<T> setFailure(Throwable cause) {
            mainPromise.setFailure(cause);
            return this;
        }
    };
    for (Integer slot : connectionManager.getEntries().keySet()) {
        async(readOnlyMode, slot, null, connectionManager.getCodec(), command, params, promise, 0);
    }
    return mainPromise;
}

From source file:org.redisson.CommandExecutorService.java

License:Apache License

public <T, R> Future<R> evalAllAsync(boolean readOnlyMode, RedisCommand<T> command,
        final SlotCallback<T, R> callback, String script, List<Object> keys, Object... params) {
    final Promise<R> mainPromise = connectionManager.newPromise();
    Promise<T> promise = new DefaultPromise<T>() {
        AtomicInteger counter = new AtomicInteger(connectionManager.getEntries().keySet().size());

        @Override/*  w w  w .  ja  v  a 2  s .  c om*/
        public Promise<T> setSuccess(T result) {
            callback.onSlotResult(result);
            if (counter.decrementAndGet() == 0 && !mainPromise.isDone()) {
                mainPromise.setSuccess(callback.onFinish());
            }
            return this;
        }

        @Override
        public Promise<T> setFailure(Throwable cause) {
            mainPromise.setFailure(cause);
            return this;
        }
    };

    List<Object> args = new ArrayList<Object>(2 + keys.size() + params.length);
    args.add(script);
    args.add(keys.size());
    args.addAll(keys);
    args.addAll(Arrays.asList(params));
    for (Integer slot : connectionManager.getEntries().keySet()) {
        async(readOnlyMode, slot, null, connectionManager.getCodec(), command, args.toArray(), promise, 0);
    }
    return mainPromise;
}

From source file:org.redisson.core.RedissonMultiLock.java

License:Apache License

public void lockInterruptibly(long leaseTime, TimeUnit unit) throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Object> result = new AtomicReference<Object>();
    Promise<Void> promise = new DefaultPromise<Void>() {
        public Promise<Void> setSuccess(Void result) {
            latch.countDown();//from www  .  j a  v a 2 s  .co  m
            return this;
        };

        public Promise<Void> setFailure(Throwable cause) {
            result.set(cause);
            latch.countDown();
            return this;
        };
    };

    lock(promise, 0, leaseTime, unit);

    latch.await();
    if (result.get() instanceof Throwable) {
        PlatformDependent.throwException((Throwable) result.get());
    }
}

From source file:org.redisson.core.RedissonMultiLock.java

License:Apache License

@Override
public void lockInterruptibly() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Object> result = new AtomicReference<Object>();
    Promise<Void> promise = new DefaultPromise<Void>() {
        public Promise<Void> setSuccess(Void result) {
            latch.countDown();/* ww  w .  j a  va2  s .co  m*/
            return this;
        };

        public Promise<Void> setFailure(Throwable cause) {
            result.set(cause);
            latch.countDown();
            return this;
        };
    };

    lock(promise, 0, -1, null);

    latch.await();
    if (result.get() instanceof Throwable) {
        PlatformDependent.throwException((Throwable) result.get());
    }
}