use of com.ctrip.xpipe.api.command.CommandFuture in project x-pipe by ctripcorp.
the class UntilSuccess method doExecute.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void doExecute() throws Exception {
if (future().isCancelled()) {
return;
}
CommandFuture<?> future = executeNext();
if (future == null) {
future().setFailure(new CommandChainException("until success fail", getResult()));
return;
}
future.addListener(new CommandFutureListener() {
@Override
public void operationComplete(CommandFuture commandFuture) throws Exception {
if (commandFuture.isSuccess()) {
future().setSuccess(commandFuture.get());
} else {
logger.error("[doExecute]" + currentCommand(), commandFuture.cause());
doExecute();
}
}
});
}
use of com.ctrip.xpipe.api.command.CommandFuture in project x-pipe by ctripcorp.
the class SequenceCommandChain method executeChain.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void executeChain() {
if (future().isCancelled()) {
return;
}
CommandFuture<?> currentFuture = executeNext();
if (currentFuture == null) {
future().setSuccess(getResult());
return;
}
currentFuture.addListener(new CommandFutureListener() {
@Override
public void operationComplete(CommandFuture commandFuture) throws Exception {
if (commandFuture.isSuccess()) {
executeChain();
} else {
failExecuteNext(commandFuture);
}
}
});
}
use of com.ctrip.xpipe.api.command.CommandFuture in project x-pipe by ctripcorp.
the class AbstractRedisMasterReplication method masterConnected.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void masterConnected(Channel channel) {
connectedTime = System.currentTimeMillis();
this.masterChannel = channel;
clientPool = new FixedObjectPool<NettyClient>(new DefaultNettyClient(channel));
checkTimeout(channel);
checkKeeper();
SequenceCommandChain chain = new SequenceCommandChain(false);
chain.add(listeningPortCommand());
chain.add(new FailSafeCommandWrapper<>(new Replconf(clientPool, ReplConfType.CAPA, scheduled, CAPA.EOF.toString(), CAPA.PSYNC2.toString())));
try {
executeCommand(chain).addListener(new CommandFutureListener() {
@Override
public void operationComplete(CommandFuture commandFuture) throws Exception {
if (commandFuture.isSuccess()) {
sendReplicationCommand();
} else {
logger.error("[operationComplete][listeningPortCommand]", commandFuture.cause());
}
}
});
} catch (Exception e) {
logger.error("[masterConnected]" + channel, e);
}
}
use of com.ctrip.xpipe.api.command.CommandFuture in project x-pipe by ctripcorp.
the class AsyncSendEmailCommandTest method testAsyncSendEmailCommand4.
@Test
public void testAsyncSendEmailCommand4() throws Exception {
SendEmailResponse response = new SendEmailResponse();
response.setResultCode(0);
response.setResultMsg("no recipient from email");
when(client.sendEmail(any())).thenReturn(response);
CtripPlatformEmailService.AsyncSendEmailCommand command = new CtripPlatformEmailService.AsyncSendEmailCommand(generateEmail());
command.setClient(client);
CommandFuture future = command.execute();
Assert.assertFalse(future.isSuccess());
Assert.assertEquals("no recipient from email", future.cause().getMessage());
}
use of com.ctrip.xpipe.api.command.CommandFuture in project x-pipe by ctripcorp.
the class AsyncSendEmailCommandTest method testAsyncSendEmailCommand3.
@Test
public void testAsyncSendEmailCommand3() throws Exception {
SendEmailResponse response = new SendEmailResponse();
response.setResultCode(1);
when(client.sendEmail(any())).thenReturn(response);
GetEmailStatusResponse getResponse = new GetEmailStatusResponse();
getResponse.setResultCode(0);
getResponse.setResultMsg("test exception result could be caught");
when(client.getEmailStatus(any())).thenReturn(getResponse);
CtripPlatformEmailService.AsyncSendEmailCommand command = new CtripPlatformEmailService.AsyncSendEmailCommand(generateEmail());
command.setClient(client);
CommandFuture future = command.execute();
future.addListener(commandFuture -> {
Assert.assertFalse(future.isSuccess());
Assert.assertEquals("test exception result could be caught", future.cause().getMessage());
});
waitConditionUntilTimeOut(() -> future.isDone(), 10 * 1000);
}
Aggregations