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);
}
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);
}
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);
}
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));
}
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);
}
Aggregations