use of com.ctrip.xpipe.command.ParallelCommandChain in project x-pipe by ctripcorp.
the class DcMetaBuilder method doExecute.
@Override
protected void doExecute() throws Exception {
SequenceCommandChain sequenceCommandChain = new SequenceCommandChain(false);
ParallelCommandChain parallelCommandChain = new ParallelCommandChain(executors);
parallelCommandChain.add(retry3TimesUntilSuccess(new GetAllDcClusterShardDetailCommand(dcId)));
parallelCommandChain.add(retry3TimesUntilSuccess(new Cluster2DcClusterMapCommand()));
parallelCommandChain.add(retry3TimesUntilSuccess(new GetDcIdNameMapCommand()));
sequenceCommandChain.add(parallelCommandChain);
sequenceCommandChain.add(retry3TimesUntilSuccess(new BuildDcMetaCommand()));
logger.info("[doExecute] commands: {}", sequenceCommandChain);
sequenceCommandChain.future().addListener(commandFuture -> {
if (commandFuture.isSuccess()) {
future().setSuccess(dcMeta);
} else {
future().setFailure(commandFuture.cause());
}
});
sequenceCommandChain.execute(executors);
}
use of com.ctrip.xpipe.command.ParallelCommandChain in project x-pipe by ctripcorp.
the class AbstractRedisesSlaveofJob method doExecute.
@Override
protected void doExecute() throws CommandExecutionException {
ParallelCommandChain commandChain = new ParallelCommandChain(executors);
for (RedisMeta redisMeta : redises) {
Command<?> backupCommand = createSlaveofCommand(redisMeta, masterHost, masterPort);
commandChain.add(backupCommand);
}
commandChain.execute().addListener(new CommandFutureListener<Object>() {
@Override
public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
if (commandFuture.isSuccess()) {
future().setSuccess(null);
} else {
future().setFailure(commandFuture.cause());
}
}
});
}
use of com.ctrip.xpipe.command.ParallelCommandChain in project x-pipe by ctripcorp.
the class KeyedOneThreadTaskExecutorTest method testHang.
@Test
public void testHang() throws TimeoutException, IOException {
int threadCount = 10;
int taskCount = threadCount;
ExecutorService executorService = null;
try {
executorService = Executors.newFixedThreadPool(threadCount, XpipeThreadFactory.create("test-hang"));
keyed = new KeyedOneThreadTaskExecutor<>(executorService);
AtomicInteger completeCount = new AtomicInteger();
for (int i = 0; i < taskCount; i++) {
int finalI = i;
ParallelCommandChain parallelCommandChain = new ParallelCommandChain(executorService);
parallelCommandChain.add(new TestCommand("success:" + i, sleepInterval));
parallelCommandChain.future().addListener(new CommandFutureListener<Object>() {
@Override
public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
logger.info("[operationComplete]{}", finalI);
completeCount.incrementAndGet();
}
});
keyed.execute(String.valueOf(i), parallelCommandChain);
}
waitConditionUntilTimeOut(() -> completeCount.get() == taskCount);
} finally {
executorService.shutdownNow();
}
}
use of com.ctrip.xpipe.command.ParallelCommandChain in project x-pipe by ctripcorp.
the class AdvancedDcMetaService method getDcMeta.
@Override
public DcMeta getDcMeta(String dcName) {
DcTbl dcTbl = dcService.find(dcName);
DcMeta dcMeta = new DcMeta().setId(dcName).setLastModifiedTime(dcTbl.getDcLastModifiedTime());
ParallelCommandChain chain = new ParallelCommandChain(executors);
chain.add(retry3TimesUntilSuccess(new GetAllSentinelCommand(dcMeta)));
chain.add(retry3TimesUntilSuccess(new GetAllKeeperContainerCommand(dcMeta)));
DcMetaBuilder builder = new DcMetaBuilder(dcMeta, dcTbl.getId(), executors, redisMetaService, dcClusterService, clusterMetaService, dcClusterShardService, dcService, factory);
chain.add(retry3TimesUntilSuccess(builder));
try {
chain.execute().get();
} catch (Exception e) {
logger.error("[queryDcMeta] ", e);
}
return dcMeta;
}
Aggregations