Search in sources :

Example 1 with RetryDelay

use of com.ctrip.xpipe.retry.RetryDelay 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 RetryDelay

use of com.ctrip.xpipe.retry.RetryDelay 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)

Example 3 with RetryDelay

use of com.ctrip.xpipe.retry.RetryDelay in project x-pipe by ctripcorp.

the class AdvancedDcMetaService method initService.

@PostConstruct
public void initService() {
    executors = DefaultExecutorFactory.createAllowCoreTimeout("OptimizedDcMetaService", OsUtils.defaultMaxCoreThreadCount()).createExecutorService();
    int retryTimes = 3, retryDelayMilli = 5;
    factory = new DefaultRetryCommandFactory(retryTimes, new RetryDelay(retryDelayMilli), scheduled);
}
Also used : DefaultRetryCommandFactory(com.ctrip.xpipe.command.DefaultRetryCommandFactory) RetryDelay(com.ctrip.xpipe.retry.RetryDelay) PostConstruct(javax.annotation.PostConstruct)

Example 4 with RetryDelay

use of com.ctrip.xpipe.retry.RetryDelay in project x-pipe by ctripcorp.

the class CommandRetryWrapperTest method testRetryCancel.

@Test
public void testRetryCancel() {
    TestCommand command = new TestCommand(new Exception("just throw"));
    CommandRetryWrapper<String> wrapper = (CommandRetryWrapper<String>) CommandRetryWrapper.buildCountRetry(retryCount, new RetryDelay(sleepBase), command, scheduled);
    final CommandFuture<String> future = wrapper.execute();
    new Thread(new Runnable() {

        @Override
        public void run() {
            sleep(sleepBase);
            future.cancel(true);
        }
    }).start();
    try {
        future.get();
        Assert.fail();
    } catch (Exception e) {
    }
    Assert.assertTrue(wrapper.getExecuteCount() < (retryCount + 1));
}
Also used : RetryDelay(com.ctrip.xpipe.retry.RetryDelay) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 5 with RetryDelay

use of com.ctrip.xpipe.retry.RetryDelay in project x-pipe by ctripcorp.

the class CommandRetryWrapperTest method testRetry.

@Test
public void testRetry() throws CommandExecutionException {
    TestCommand command = new TestCommand(new Exception("just throw"));
    CommandRetryWrapper<String> wrapper = (CommandRetryWrapper<String>) CommandRetryWrapper.buildCountRetry(retryCount, new RetryDelay(sleepBase), command, scheduled);
    try {
        wrapper.execute().get();
        Assert.fail();
    } catch (InterruptedException | ExecutionException e) {
    }
    Assert.assertEquals(wrapper.getExecuteCount(), retryCount + 1);
}
Also used : RetryDelay(com.ctrip.xpipe.retry.RetryDelay) ExecutionException(java.util.concurrent.ExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Aggregations

RetryDelay (com.ctrip.xpipe.retry.RetryDelay)7 Test (org.junit.Test)4 AbstractTest (com.ctrip.xpipe.AbstractTest)3 ExecutionException (java.util.concurrent.ExecutionException)3 DefaultRetryCommandFactory (com.ctrip.xpipe.command.DefaultRetryCommandFactory)2 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)2 XpipeObjectPoolFromKeyed (com.ctrip.xpipe.pool.XpipeObjectPoolFromKeyed)2 InetSocketAddress (java.net.InetSocketAddress)2 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)1 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)1 KeeperSetStateCommand (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractKeeperCommand.KeeperSetStateCommand)1 RedisError (com.ctrip.xpipe.redis.core.protocal.error.RedisError)1 IOException (java.io.IOException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 PostConstruct (javax.annotation.PostConstruct)1