Search in sources :

Example 1 with CommandFutureListener

use of com.ctrip.xpipe.api.command.CommandFutureListener 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();
            }
        }
    });
}
Also used : CommandFuture(com.ctrip.xpipe.api.command.CommandFuture) CommandFutureListener(com.ctrip.xpipe.api.command.CommandFutureListener)

Example 2 with CommandFutureListener

use of com.ctrip.xpipe.api.command.CommandFutureListener 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);
            }
        }
    });
}
Also used : CommandFuture(com.ctrip.xpipe.api.command.CommandFuture) CommandFutureListener(com.ctrip.xpipe.api.command.CommandFutureListener)

Example 3 with CommandFutureListener

use of com.ctrip.xpipe.api.command.CommandFutureListener 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);
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) DefaultNettyClient(com.ctrip.xpipe.netty.commands.DefaultNettyClient) CommandFuture(com.ctrip.xpipe.api.command.CommandFuture) Replconf(com.ctrip.xpipe.redis.core.protocal.cmd.Replconf) CommandFutureListener(com.ctrip.xpipe.api.command.CommandFutureListener) DefaultNettyClient(com.ctrip.xpipe.netty.commands.DefaultNettyClient) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) IOException(java.io.IOException) XpipeException(com.ctrip.xpipe.exception.XpipeException) SequenceCommandChain(com.ctrip.xpipe.command.SequenceCommandChain)

Example 4 with CommandFutureListener

use of com.ctrip.xpipe.api.command.CommandFutureListener in project x-pipe by ctripcorp.

the class ScheduleCommandWrapper method doExecute.

@Override
protected void doExecute() throws Exception {
    final ScheduledFuture<?> scheduleFuture = scheduled.schedule(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            try {
                command.execute().addListener(new CommandFutureListener<V>() {

                    @Override
                    public void operationComplete(CommandFuture<V> commandFuture) throws Exception {
                        if (commandFuture.isSuccess()) {
                            future().setSuccess(commandFuture.get());
                        } else {
                            future().setFailure(ExceptionUtils.getRootCause(commandFuture.cause()));
                        }
                    }
                });
            } catch (Exception e) {
                future().setFailure(ExceptionUtils.getRootCause(e));
            }
        }
    }, time, timeUnit);
    future().addListener(new CommandFutureListener<V>() {

        @Override
        public void operationComplete(CommandFuture<V> commandFuture) throws Exception {
            if (commandFuture.isCancelled()) {
                logger.info("[command canceled][cancel execution]{}", time);
                command.future().cancel(true);
                scheduleFuture.cancel(false);
            }
        }
    });
}
Also used : CommandFuture(com.ctrip.xpipe.api.command.CommandFuture) CommandFutureListener(com.ctrip.xpipe.api.command.CommandFutureListener) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)

Example 5 with CommandFutureListener

use of com.ctrip.xpipe.api.command.CommandFutureListener in project x-pipe by ctripcorp.

the class TransactionalCommand method doWork.

@SuppressWarnings("unchecked")
protected void doWork(final SimpleObjectPool<NettyClient> clientPool) {
    SequenceCommandChain chain = new SequenceCommandChain(false);
    for (RedisCommand currentCommand : commands) {
        OneTranscationCommand oneTranscationCommand = new OneTranscationCommand(clientPool, currentCommand, scheduled);
        chain.add(oneTranscationCommand);
    }
    chain.execute().addListener(new CommandFutureListener() {

        @Override
        public void operationComplete(CommandFuture commandFuture) throws Exception {
            if (!commandFuture.isSuccess()) {
                logger.error("[doWork][fail]", commandFuture.cause());
            }
            endTranscation(clientPool);
        }
    });
}
Also used : CommandFuture(com.ctrip.xpipe.api.command.CommandFuture) CommandFutureListener(com.ctrip.xpipe.api.command.CommandFutureListener) AbstractRedisCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractRedisCommand) RedisCommand(com.ctrip.xpipe.redis.core.protocal.RedisCommand) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) ReturnObjectException(com.ctrip.xpipe.pool.ReturnObjectException) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException) SequenceCommandChain(com.ctrip.xpipe.command.SequenceCommandChain)

Aggregations

CommandFuture (com.ctrip.xpipe.api.command.CommandFuture)5 CommandFutureListener (com.ctrip.xpipe.api.command.CommandFutureListener)5 CommandExecutionException (com.ctrip.xpipe.command.CommandExecutionException)2 SequenceCommandChain (com.ctrip.xpipe.command.SequenceCommandChain)2 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)1 XpipeException (com.ctrip.xpipe.exception.XpipeException)1 DefaultNettyClient (com.ctrip.xpipe.netty.commands.DefaultNettyClient)1 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 BorrowObjectException (com.ctrip.xpipe.pool.BorrowObjectException)1 ReturnObjectException (com.ctrip.xpipe.pool.ReturnObjectException)1 RedisCommand (com.ctrip.xpipe.redis.core.protocal.RedisCommand)1 AbstractRedisCommand (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractRedisCommand)1 Replconf (com.ctrip.xpipe.redis.core.protocal.cmd.Replconf)1 IOException (java.io.IOException)1