Example usage for io.netty.util.concurrent Future syncUninterruptibly

List of usage examples for io.netty.util.concurrent Future syncUninterruptibly

Introduction

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

Prototype

Future<V> syncUninterruptibly();

Source Link

Document

Waits for this future until it is done, and rethrows the cause of the failure if this future failed.

Usage

From source file:com.gemstone.gemfire.redis.GemFireRedisServer.java

License:Apache License

/**
 * Shutdown method for {@link GemFireRedisServer}. This closes the {@link Cache},
 * interrupts all execution and forcefully closes all connections.
 *//*from  w w w .  j a  v a 2 s .com*/
public synchronized void shutdown() {
    if (!shutdown) {
        if (logger.infoEnabled())
            logger.info("GemFireRedisServer shutting down");
        ChannelFuture closeFuture = this.serverChannel.closeFuture();
        Future<?> c = workerGroup.shutdownGracefully();
        Future<?> c2 = bossGroup.shutdownGracefully();
        this.serverChannel.close();
        c.syncUninterruptibly();
        c2.syncUninterruptibly();
        this.regionCache.close();
        if (mainThread != null)
            mainThread.interrupt();
        for (ScheduledFuture<?> f : this.expirationFutures.values())
            f.cancel(true);
        this.expirationFutures.clear();
        this.expirationExecutor.shutdownNow();
        closeFuture.syncUninterruptibly();
        shutdown = true;
    }
}

From source file:org.apache.geode.redis.GeodeRedisServer.java

License:Apache License

/**
 * Shutdown method for {@link GeodeRedisServer}. This closes the {@link Cache}, interrupts all
 * execution and forcefully closes all connections.
 */// ww w . jav  a 2s  . c o m
public synchronized void shutdown() {
    if (!shutdown) {
        if (logger.infoEnabled())
            logger.info("GeodeRedisServer shutting down");
        ChannelFuture closeFuture = this.serverChannel.closeFuture();
        Future<?> c = workerGroup.shutdownGracefully();
        Future<?> c2 = bossGroup.shutdownGracefully();
        this.serverChannel.close();
        c.syncUninterruptibly();
        c2.syncUninterruptibly();
        this.regionCache.close();
        if (mainThread != null)
            mainThread.interrupt();
        for (ScheduledFuture<?> f : this.expirationFutures.values())
            f.cancel(true);
        this.expirationFutures.clear();
        this.expirationExecutor.shutdownNow();
        closeFuture.syncUninterruptibly();
        shutdown = true;
    }
}

From source file:org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutputHelper.java

License:Apache License

private static FanOutOneBlockAsyncDFSOutput createOutput(DistributedFileSystem dfs, String src,
        boolean overwrite, boolean createParent, short replication, long blockSize, EventLoop eventLoop)
        throws IOException {
    Configuration conf = dfs.getConf();
    FSUtils fsUtils = FSUtils.getInstance(dfs, conf);
    DFSClient client = dfs.getClient();//from   w  w  w .j a  v a  2 s  .com
    String clientName = client.getClientName();
    ClientProtocol namenode = client.getNamenode();
    HdfsFileStatus stat;
    try {
        stat = FILE_CREATER.create(namenode, src,
                FsPermission.getFileDefault().applyUMask(FsPermission.getUMask(conf)), clientName,
                new EnumSetWritable<CreateFlag>(overwrite ? EnumSet.of(CREATE, OVERWRITE) : EnumSet.of(CREATE)),
                createParent, replication, blockSize);
    } catch (Exception e) {
        if (e instanceof RemoteException) {
            throw (RemoteException) e;
        } else {
            throw new NameNodeException(e);
        }
    }
    beginFileLease(client, src, stat.getFileId());
    boolean succ = false;
    LocatedBlock locatedBlock = null;
    List<Future<Channel>> futureList = null;
    try {
        DataChecksum summer = createChecksum(client);
        locatedBlock = BLOCK_ADDER.addBlock(namenode, src, client.getClientName(), null, null, stat.getFileId(),
                null);
        List<Channel> datanodeList = new ArrayList<>();
        futureList = connectToDataNodes(conf, client, clientName, locatedBlock, 0L, 0L, PIPELINE_SETUP_CREATE,
                summer, eventLoop);
        for (Future<Channel> future : futureList) {
            // fail the creation if there are connection failures since we are fail-fast. The upper
            // layer should retry itself if needed.
            datanodeList.add(future.syncUninterruptibly().getNow());
        }
        CryptoCodec cryptocodec = createCryptoCodec(conf, stat, client);
        FanOutOneBlockAsyncDFSOutput output = new FanOutOneBlockAsyncDFSOutput(conf, fsUtils, dfs, client,
                namenode, clientName, src, stat.getFileId(), locatedBlock, cryptocodec, eventLoop, datanodeList,
                summer, ALLOC);
        succ = true;
        return output;
    } finally {
        if (!succ) {
            if (futureList != null) {
                for (Future<Channel> f : futureList) {
                    f.addListener(new FutureListener<Channel>() {

                        @Override
                        public void operationComplete(Future<Channel> future) throws Exception {
                            if (future.isSuccess()) {
                                future.getNow().close();
                            }
                        }
                    });
                }
            }
            endFileLease(client, src, stat.getFileId());
            fsUtils.recoverFileLease(dfs, new Path(src), conf, new CancelOnClose(client));
        }
    }
}

From source file:org.apache.hadoop.hbase.util.FanOutOneBlockAsyncDFSOutputHelper.java

License:Apache License

private static FanOutOneBlockAsyncDFSOutput createOutput(DistributedFileSystem dfs, String src,
        boolean overwrite, boolean createParent, short replication, long blockSize, EventLoop eventLoop)
        throws IOException {
    Configuration conf = dfs.getConf();
    FSUtils fsUtils = FSUtils.getInstance(dfs, conf);
    DFSClient client = dfs.getClient();/*from w  w w.  j ava2 s .c  o  m*/
    String clientName = client.getClientName();
    ClientProtocol namenode = client.getNamenode();
    HdfsFileStatus stat;
    try {
        stat = FILE_CREATER.create(namenode, src,
                FsPermission.getFileDefault().applyUMask(FsPermission.getUMask(conf)), clientName,
                new EnumSetWritable<CreateFlag>(overwrite ? EnumSet.of(CREATE, OVERWRITE) : EnumSet.of(CREATE)),
                createParent, replication, blockSize);
    } catch (Exception e) {
        if (e instanceof RemoteException) {
            throw (RemoteException) e;
        } else {
            throw new NameNodeException(e);
        }
    }
    beginFileLease(client, src, stat.getFileId());
    boolean succ = false;
    LocatedBlock locatedBlock = null;
    List<Future<Channel>> futureList = null;
    try {
        DataChecksum summer = createChecksum(client);
        locatedBlock = namenode.addBlock(src, client.getClientName(), null, null, stat.getFileId(), null);
        List<Channel> datanodeList = new ArrayList<>();
        futureList = connectToDataNodes(conf, clientName, locatedBlock, 0L, 0L, PIPELINE_SETUP_CREATE, summer,
                eventLoop);
        for (Future<Channel> future : futureList) {
            // fail the creation if there are connection failures since we are fail-fast. The upper
            // layer should retry itself if needed.
            datanodeList.add(future.syncUninterruptibly().getNow());
        }
        succ = true;
        return new FanOutOneBlockAsyncDFSOutput(conf, fsUtils, dfs, client, namenode, clientName, src,
                stat.getFileId(), locatedBlock, eventLoop, datanodeList, summer, ALLOC);
    } finally {
        if (!succ) {
            if (futureList != null) {
                for (Future<Channel> f : futureList) {
                    f.addListener(new FutureListener<Channel>() {

                        @Override
                        public void operationComplete(Future<Channel> future) throws Exception {
                            if (future.isSuccess()) {
                                future.getNow().close();
                            }
                        }
                    });
                }
            }
            endFileLease(client, src, stat.getFileId());
            fsUtils.recoverFileLease(dfs, new Path(src), conf, new CancelOnClose(client));
        }
    }
}

From source file:org.redisson.command.CommandSyncService.java

License:Apache License

<R> R sync(boolean readOnlyMode, Codec codec, NodeSource source, SyncOperation<R> operation, int attempt) {
    if (!connectionManager.getShutdownLatch().acquire()) {
        throw new IllegalStateException("Redisson is shutdown");
    }/*from  w  w w.java  2  s.  co  m*/

    try {
        Future<RedisConnection> connectionFuture;
        if (readOnlyMode) {
            connectionFuture = connectionManager.connectionReadOp(source, null);
        } else {
            connectionFuture = connectionManager.connectionWriteOp(source, null);
        }
        connectionFuture.syncUninterruptibly();

        RedisConnection connection = connectionFuture.getNow();

        try {
            return operation.execute(codec, connection);
        } catch (RedisMovedException e) {
            return sync(readOnlyMode, codec, new NodeSource(e.getSlot(), e.getAddr(), Redirect.MOVED),
                    operation, attempt);
        } catch (RedisAskException e) {
            return sync(readOnlyMode, codec, new NodeSource(e.getSlot(), e.getAddr(), Redirect.ASK), operation,
                    attempt);
        } catch (RedisLoadingException e) {
            return sync(readOnlyMode, codec, source, operation, attempt);
        } catch (RedisTimeoutException e) {
            if (attempt == connectionManager.getConfig().getRetryAttempts()) {
                throw e;
            }
            attempt++;
            return sync(readOnlyMode, codec, source, operation, attempt);
        } finally {
            connectionManager.getShutdownLatch().release();
            if (readOnlyMode) {
                connectionManager.releaseRead(source, connection);
            } else {
                connectionManager.releaseWrite(source, connection);
            }
        }
    } catch (RedisException e) {
        if (attempt == connectionManager.getConfig().getRetryAttempts()) {
            throw e;
        }
        try {
            Thread.sleep(connectionManager.getConfig().getRetryInterval());
        } catch (InterruptedException e1) {
            Thread.currentThread().interrupt();
        }
        attempt++;
        return sync(readOnlyMode, codec, source, operation, attempt);
    }
}

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

License:Apache License

public DNSMonitor(ConnectionManager connectionManager, RedisClient masterHost, Collection<RedisURI> slaveHosts,
        long dnsMonitoringInterval, AddressResolverGroup<InetSocketAddress> resolverGroup) {
    this.resolver = resolverGroup.getResolver(connectionManager.getGroup().next());

    masterHost.resolveAddr().syncUninterruptibly();
    masters.put(masterHost.getConfig().getAddress(), masterHost.getAddr());

    for (RedisURI host : slaveHosts) {
        Future<InetSocketAddress> resolveFuture = resolver
                .resolve(InetSocketAddress.createUnresolved(host.getHost(), host.getPort()));
        resolveFuture.syncUninterruptibly();
        slaves.put(host, resolveFuture.getNow());
    }//from w  w  w  . j  a  v  a2  s  .co m
    this.connectionManager = connectionManager;
    this.dnsMonitoringInterval = dnsMonitoringInterval;
}

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

License:Apache License

@Override
public boolean tryLock() {
    List<Future<Boolean>> tryLockFutures = new ArrayList<Future<Boolean>>(locks.size());
    for (RLock lock : locks) {
        tryLockFutures.add(lock.tryLockAsync());
    }/* ww  w  .  java  2 s. c  o  m*/

    for (Future<Boolean> future : tryLockFutures) {
        try {
            if (!future.syncUninterruptibly().getNow()) {
                unlockInner();
                return false;
            }
        } catch (RuntimeException e) {
            unlockInner();
            throw e;
        }
    }

    return true;
}

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

License:Apache License

public boolean tryLock(long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException {
    List<Future<Boolean>> tryLockFutures = new ArrayList<Future<Boolean>>(locks.size());
    for (RLock lock : locks) {
        tryLockFutures.add(lock.tryLockAsync(waitTime, leaseTime, unit));
    }/*from ww w  .j  av a  2  s.  com*/

    for (Future<Boolean> future : tryLockFutures) {
        try {
            if (!future.syncUninterruptibly().getNow()) {
                unlockInner();
                return false;
            }
        } catch (RuntimeException e) {
            unlockInner();
            throw e;
        }
    }

    return true;
}

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

License:Apache License

@Override
public void unlock() {
    List<Future<Void>> futures = new ArrayList<Future<Void>>(locks.size());

    for (RLock lock : locks) {
        futures.add(lock.unlockAsync());
    }/*from www .  ja  v a2 s. com*/

    for (Future<Void> future : futures) {
        future.syncUninterruptibly();
    }
}

From source file:org.redisson.RedissonPatternTopic.java

License:Apache License

private int addListener(RedisPubSubListener<M> pubSubListener) {
    Future<PubSubConnectionEntry> future = commandExecutor.getConnectionManager().psubscribe(name, codec);
    future.syncUninterruptibly();
    PubSubConnectionEntry entry = future.getNow();
    synchronized (entry) {
        if (entry.isActive()) {
            entry.addListener(name, pubSubListener);
            return System.identityHashCode(pubSubListener);
        }//from   w  w w.j  av a  2s.  c o  m
    }
    // entry is inactive trying add again
    return addListener(pubSubListener);
}