Search in sources :

Example 1 with XpipeObjectPoolFromKeyed

use of com.ctrip.xpipe.pool.XpipeObjectPoolFromKeyed in project x-pipe by ctripcorp.

the class AbstractRedisesSlaveofJob method createSlaveofCommand.

private Command<?> createSlaveofCommand(RedisMeta redisMeta, String masterHost, int masterPort) {
    SimpleObjectPool<NettyClient> pool = new XpipeObjectPoolFromKeyed<InetSocketAddress, NettyClient>(clientPool, new InetSocketAddress(redisMeta.getIp(), redisMeta.getPort()));
    Command<?> command = createSlaveOfCommand(pool, masterHost, masterPort);
    return CommandRetryWrapper.buildCountRetry(retryTimes, new RetryDelay(delayBaseMilli) {

        @Override
        public boolean retry(Throwable th) {
            Throwable rootCause = ExceptionUtils.getRootCause(th);
            if (rootCause instanceof RedisError) {
                logger.info("[retry][do not retry, because redis error]{}", rootCause.getMessage());
                return false;
            }
            return super.retry(th);
        }
    }, command, scheduled);
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) XpipeObjectPoolFromKeyed(com.ctrip.xpipe.pool.XpipeObjectPoolFromKeyed) RedisError(com.ctrip.xpipe.redis.core.protocal.error.RedisError) InetSocketAddress(java.net.InetSocketAddress) RetryDelay(com.ctrip.xpipe.retry.RetryDelay)

Example 2 with XpipeObjectPoolFromKeyed

use of com.ctrip.xpipe.pool.XpipeObjectPoolFromKeyed in project x-pipe by ctripcorp.

the class KeeperStateChangeJob method createKeeperSetStateCommand.

private Command<?> createKeeperSetStateCommand(KeeperMeta keeper, Pair<String, Integer> masterAddress) {
    SimpleObjectPool<NettyClient> pool = new XpipeObjectPoolFromKeyed<InetSocketAddress, NettyClient>(clientPool, new InetSocketAddress(keeper.getIp(), keeper.getPort()));
    KeeperSetStateCommand command = new KeeperSetStateCommand(pool, keeper.isActive() ? KeeperState.ACTIVE : KeeperState.BACKUP, masterAddress, scheduled);
    return CommandRetryWrapper.buildCountRetry(retryTimes, new RetryDelay(delayBaseMilli), command, scheduled);
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) XpipeObjectPoolFromKeyed(com.ctrip.xpipe.pool.XpipeObjectPoolFromKeyed) InetSocketAddress(java.net.InetSocketAddress) RetryDelay(com.ctrip.xpipe.retry.RetryDelay) KeeperSetStateCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractKeeperCommand.KeeperSetStateCommand)

Aggregations

NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)2 XpipeObjectPoolFromKeyed (com.ctrip.xpipe.pool.XpipeObjectPoolFromKeyed)2 RetryDelay (com.ctrip.xpipe.retry.RetryDelay)2 InetSocketAddress (java.net.InetSocketAddress)2 KeeperSetStateCommand (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractKeeperCommand.KeeperSetStateCommand)1 RedisError (com.ctrip.xpipe.redis.core.protocal.error.RedisError)1