Search in sources :

Example 1 with CommandExecutionException

use of com.ctrip.xpipe.command.CommandExecutionException 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());
            }
        }
    });
}
Also used : ParallelCommandChain(com.ctrip.xpipe.command.ParallelCommandChain) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException)

Example 2 with CommandExecutionException

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

the class RequestResponseCommandTest method testException.

@Test
public void testException() throws CommandExecutionException {
    Exception exception = new Exception();
    TestCommand testCommand = new TestCommand("something\r\n", 0, clientPool, scheduled, exception);
    CommandFuture<String> future = testCommand.execute();
    try {
        future.get();
        Assert.fail();
    } catch (InterruptedException e) {
        Assert.fail();
    } catch (ExecutionException e) {
        Assert.assertEquals(exception, e.getCause());
    }
}
Also used : CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) ExecutionException(java.util.concurrent.ExecutionException) IOException(java.io.IOException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) ExecutionException(java.util.concurrent.ExecutionException) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException) CommandTimeoutException(com.ctrip.xpipe.command.CommandTimeoutException) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 3 with CommandExecutionException

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

the class TransactionalSlaveOfCommand method doExecute.

@Override
protected void doExecute() throws CommandExecutionException {
    logger.info("[doExecute][try xslaveof]{}", this);
    TransactionalCommand slaveofTransaction = new TransactionalCommand(getClientPool(), scheduled, new XSlaveofCommand(null, ip, port, scheduled), new ConfigRewrite(null, scheduled));
    try {
        slaveofTransaction.execute().addListener(new CommandFutureListener<Object[]>() {

            @Override
            public void operationComplete(CommandFuture<Object[]> commandFuture) throws Exception {
                if (!commandFuture.isSuccess()) {
                    failXslaveof(commandFuture.cause());
                } else {
                    logger.info("[doExecute][xslaveof success]{}", this);
                    future().setSuccess(commandFuture.get());
                }
            }
        });
    } catch (Exception e) {
        failXslaveof(e);
    }
}
Also used : XSlaveofCommand(com.ctrip.xpipe.redis.core.protocal.cmd.XSlaveofCommand) ConfigRewrite(com.ctrip.xpipe.redis.core.protocal.cmd.ConfigRewrite) IOException(java.io.IOException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException)

Example 4 with CommandExecutionException

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

the class DefaultSlaveOfCommand method doExecute.

@Override
protected void doExecute() throws CommandExecutionException {
    SimpleObjectPool<NettyClient> clientPool = getClientPool();
    UntilSuccess slaveOf = new UntilSuccess();
    slaveOf.add(new XSlaveofCommand(clientPool, ip, port, scheduled));
    slaveOf.add(new SlaveOfCommand(clientPool, ip, port, scheduled));
    SequenceCommandChain chain = new SequenceCommandChain(false);
    chain.add(slaveOf);
    chain.add(new ConfigRewrite(clientPool, scheduled));
    chain.execute().addListener(new CommandFutureListener<Object>() {

        @Override
        public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
            if (commandFuture.isSuccess()) {
                future().setSuccess(RedisClientProtocol.OK);
            } else {
                future().setFailure(commandFuture.cause());
            }
        }
    });
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) UntilSuccess(com.ctrip.xpipe.command.UntilSuccess) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) SequenceCommandChain(com.ctrip.xpipe.command.SequenceCommandChain)

Example 5 with CommandExecutionException

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

the class TransactionalCommand method doExecute.

@Override
protected void doExecute() throws CommandExecutionException {
    try {
        final NettyClient nettyClient = parentClientPool.borrowObject();
        SimpleObjectPool<NettyClient> clientPool = new FixedObjectPool<NettyClient>(nettyClient);
        startTransaction(clientPool);
        future().addListener(new CommandFutureListener<Object[]>() {

            @Override
            public void operationComplete(CommandFuture<Object[]> commandFuture) throws Exception {
                if (nettyClient != null) {
                    try {
                        parentClientPool.returnObject(nettyClient);
                    } catch (ReturnObjectException e) {
                        logger.error("[doExecute]" + this, e);
                    }
                }
            }
        });
    } catch (BorrowObjectException e) {
        throw new CommandExecutionException("execute " + this, e);
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) ReturnObjectException(com.ctrip.xpipe.pool.ReturnObjectException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) FixedObjectPool(com.ctrip.xpipe.pool.FixedObjectPool) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) ReturnObjectException(com.ctrip.xpipe.pool.ReturnObjectException) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException)

Aggregations

CommandExecutionException (com.ctrip.xpipe.command.CommandExecutionException)7 BorrowObjectException (com.ctrip.xpipe.pool.BorrowObjectException)4 IOException (java.io.IOException)3 AbstractTest (com.ctrip.xpipe.AbstractTest)2 CommandTimeoutException (com.ctrip.xpipe.command.CommandTimeoutException)2 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)2 ReturnObjectException (com.ctrip.xpipe.pool.ReturnObjectException)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 CommandFuture (com.ctrip.xpipe.api.command.CommandFuture)1 ParallelCommandChain (com.ctrip.xpipe.command.ParallelCommandChain)1 SequenceCommandChain (com.ctrip.xpipe.command.SequenceCommandChain)1 UntilSuccess (com.ctrip.xpipe.command.UntilSuccess)1 FixedObjectPool (com.ctrip.xpipe.pool.FixedObjectPool)1 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)1 ConfigRewrite (com.ctrip.xpipe.redis.core.protocal.cmd.ConfigRewrite)1 XSlaveofCommand (com.ctrip.xpipe.redis.core.protocal.cmd.XSlaveofCommand)1 ByteBuf (io.netty.buffer.ByteBuf)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1